@eka-care/ekascribe-ts-sdk 2.0.11 → 2.0.13

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 ADDED
@@ -0,0 +1,1135 @@
1
+ # Eka Care Ekascribe Typescript SDK Integration
2
+
3
+ This guide explains how to integrate the Eka Care Ekascribe Typescript SDK into your application.
4
+
5
+ ## Overview
6
+
7
+ The Eka Care Ekascribe SDK allows you to capture and process audio, generating structured medical documentation using Eka Care's voice transcription API.
8
+
9
+ ## Documentation
10
+
11
+ [Visit the documentation site](https://developer.eka.care/api-reference/health-ai/ekascribe/SDKs/TS-sdk)
12
+
13
+ ## Prerequisites
14
+
15
+ Before getting started, ensure you have:
16
+
17
+ - Node 14 or higher
18
+ - `npm` or `yarn` for dependency management
19
+ - Access and refresh tokens from Eka Care (optional for some methods)
20
+ - Microphone access via browser permissions
21
+ - Stable network connectivity
22
+
23
+ ## Installation
24
+
25
+ Install the SDK using `npm` or `yarn`:
26
+
27
+ ```bash
28
+ npm install @eka-care/ekascribe-ts-sdk
29
+ # or
30
+ yarn add @eka-care/ekascribe-ts-sdk
31
+ ```
32
+
33
+ ## Bundler Setup
34
+
35
+ The SDK uses a SharedWorker for background audio uploads. Modern bundlers (Webpack 5, Vite) automatically handle the worker bundling.
36
+
37
+ ### Vite
38
+
39
+ Works out of the box - no configuration needed.
40
+
41
+ ```ts
42
+ // Just import and use
43
+ import { getEkaScribeInstance } from '@eka-care/ekascribe-ts-sdk';
44
+ ```
45
+
46
+ ### Webpack 5
47
+
48
+ Works out of the box with default configuration. The `new URL(..., import.meta.url)` pattern is natively supported.
49
+
50
+ ```ts
51
+ import { getEkaScribeInstance } from '@eka-care/ekascribe-ts-sdk';
52
+ ```
53
+
54
+ ### Next.js
55
+
56
+ For Next.js projects, ensure the SDK is only used on the client side:
57
+
58
+ ```tsx
59
+ 'use client';
60
+
61
+ import { getEkaScribeInstance } from '@eka-care/ekascribe-ts-sdk';
62
+
63
+ // Use inside a client component
64
+ const ekascribe = getEkaScribeInstance({ access_token: 'your_token' });
65
+ ```
66
+
67
+ ### Browser (Script Tag)
68
+
69
+ For direct browser usage without a bundler:
70
+
71
+ ```html
72
+ <script type="module">
73
+ import { getEkaScribeInstance } from 'https://cdn.jsdelivr.net/npm/@eka-care/ekascribe-ts-sdk/dist/index.mjs';
74
+
75
+ const ekascribe = getEkaScribeInstance({ access_token: 'your_token' });
76
+ </script>
77
+ ```
78
+
79
+ ## Usage
80
+
81
+ ### 1. Get Ekascribe Instance
82
+
83
+ Get the SDK instance once and use it everywhere in your application to call all methods.
84
+
85
+ ```ts
86
+ // Create a config variable to manage tokens
87
+ const sdkConfig = {
88
+ access_token: '<your_access_token>',
89
+ };
90
+
91
+ // Get instance and use it throughout your application
92
+ const ekascribe = getEkaScribeInstance(sdkConfig);
93
+ ```
94
+
95
+ **Important:** Use this same `ekascribe` instance for all SDK method calls.
96
+
97
+ ### 2. Fetch configurations list
98
+
99
+ Get supported input languages, output formats, and consultation modes.
100
+
101
+ ```ts
102
+ const config = await ekascribe.getEkascribeConfig();
103
+ ```
104
+
105
+ - #### Sample Response:
106
+
107
+ ```ts
108
+ {
109
+ "data": {
110
+ "supported_languages": [
111
+ { "id": "en", "name": "English" },
112
+ { "id": "hi", "name": "Hindi" }
113
+ ],
114
+ "supported_output_formats": [{ "id": "clinical-notes-template", "name": "Clinical Notes" }],
115
+ "consultation_modes": [
116
+ {
117
+ "id": "consultation",
118
+ "name": "Consultation",
119
+ "desc": "Eka Scribe will listen to your conversation and create clinical notes"
120
+ }
121
+ ],
122
+ "max_selection": {
123
+ "supported_languages": 2,
124
+ "supported_output_formats": 2,
125
+ "consultation_modes": 1
126
+ },
127
+ "user_details": {
128
+ "fn": "Dr. John",
129
+ "mn": "",
130
+ "ln": "Doe",
131
+ "dob": "1985-06-15",
132
+ "gen": "M",
133
+ "s": "active",
134
+ "is_paid_doc": true,
135
+ "uuid": "user-uuid-123"
136
+ },
137
+ "wid": "workspace-id-456"
138
+ },
139
+ "message": "Configuration fetched successfully",
140
+ "code": 200
141
+ }
142
+ ```
143
+
144
+ ### 3. Init transaction
145
+
146
+ Initialize a transaction before starting recording. This sets up the session with your configuration.
147
+
148
+ ```ts
149
+ const response = await ekascribe.initTransaction({
150
+ mode: 'consultation',
151
+ input_language: ['en-IN'],
152
+ output_format_template: [{ template_id: 'your_template_id' }],
153
+ txn_id: 'unique-transaction-id',
154
+ transfer: 'vaded' | 'non-vaded',
155
+ model_type: 'pro' | 'lite',
156
+ system_info: {
157
+ platform: 'web',
158
+ language: 'en',
159
+ time_zone: 'Asia/Kolkata',
160
+ },
161
+ patient_details: {
162
+ username: 'John Doe',
163
+ age: 35,
164
+ biologicalSex: 'M',
165
+ },
166
+ version: '1.0.0',
167
+ additional_data: {},
168
+ });
169
+ ```
170
+
171
+ **Key Parameters:**
172
+
173
+ - `input_language`: Language code array (e.g., `['en-IN']`)
174
+ - `output_format_template`: Array with `template_id` - depends on your end user's template selection
175
+ - `system_info`: Optional - Pass your system configuration to backend
176
+ - `patient_details`: Optional - Patient information
177
+ - `version`: SDK version
178
+ - `additional_data`: Optional - Pass any data you want to receive unchanged in the response
179
+ - `transfer`: Audio mode. Use `vaded` for audio already processed with Voice Activity Detection (SDK does this by default); use `non-vaded` only if you are sending raw audio without VAD.
180
+ - `model_type`: Transcription model choice. `pro` = most accurate; `lite` = lower latency, more performant.
181
+
182
+ - #### Sample Response:
183
+
184
+ ```ts
185
+ {
186
+ error_code?: ERROR_CODE,
187
+ status_code: 200,
188
+ message: "Transaction initialized successfully",
189
+ business_id: "biz_abc123def456",
190
+ txn_id: "abc-123",
191
+ oid: "org_789xyz",
192
+ uuid: "user_uuid_456"
193
+ }
194
+ ```
195
+
196
+ **Error handling:**
197
+
198
+ Possible Error Codes in `error_code`:
199
+
200
+ - `txn_limit_exceeded`: Maximum number of transactions exceeded
201
+ - `txn_init_failed`: Something went wrong. Retry with the same method call
202
+
203
+ **Handling 401 Status Code:**
204
+
205
+ If you receive a `status_code: 401`, update the tokens in your config and reinitialize the instance:
206
+
207
+ ```ts
208
+ // Update tokens in your config variable
209
+ sdkConfig.access_token = '<new_access_token>';
210
+
211
+ // Update tokens in the instance
212
+ ekascribe.updateAuthTokens({ access_token: sdkConfig.access_token });
213
+
214
+ // Now you can retry the method call
215
+ const response = await ekascribe.initTransaction({ ... });
216
+ ```
217
+
218
+ ### 4. Start recording
219
+
220
+ Start recording audio after initializing the transaction.
221
+
222
+ ```ts
223
+ const response = await ekascribe.startRecording();
224
+ ```
225
+
226
+ - #### Sample Response:
227
+
228
+ ```ts
229
+ {
230
+ "status_code": 200,
231
+ "message": "Recording started successfully",
232
+ "txn_id": "abc-123",
233
+ // Possible error codes:
234
+ // - "microphone" -> microphone permission not granted
235
+ // - "vad_not_initialized" -> VAD failed to initialize; reinitialize and retry the same function call
236
+ error_code?: ERROR_CODE
237
+ }
238
+ ```
239
+
240
+ ### 5. Pause recording
241
+
242
+ Pause the ongoing voice recording.
243
+
244
+ ```ts
245
+ const response = await ekascribe.pauseRecording();
246
+ ```
247
+
248
+ - #### Sample Response:
249
+
250
+ ```ts
251
+ {
252
+ "status_code": 200,
253
+ "message": "Recording paused successfully",
254
+ "is_paused": true,
255
+ error_code?: ERROR_CODE,
256
+ }
257
+ ```
258
+
259
+ ### 6. Resume recording
260
+
261
+ Resume a paused recording.
262
+
263
+ ```ts
264
+ const response = await ekascribe.resumeRecording();
265
+ ```
266
+
267
+ - #### Sample Response:
268
+
269
+ ```ts
270
+ {
271
+ "status_code": 200,
272
+ "message": "Recording resumed successfully",
273
+ "is_paused": false,
274
+ error_code?: ERROR_CODE,
275
+ }
276
+ ```
277
+
278
+ ### 7. End recording
279
+
280
+ End the recording session. This method:
281
+
282
+ - Stops the recording
283
+ - Uploads all audio chunks to the server
284
+ - Automatically retries failed uploads once
285
+ - Calls the commit API to finalize the transaction
286
+
287
+ ```ts
288
+ const response = await ekascribe.endRecording();
289
+ ```
290
+
291
+ - #### Sample Response:
292
+
293
+ ```ts
294
+ {
295
+ "status_code": 200,
296
+ "message": "Recording ended and files uploaded successfully",
297
+ failed_files?: ['1.mp3', '2.mp3'], // Only present if some files failed to upload
298
+ total_audio_files?: ['1.mp3', '2.mp3', '3.mp3', '4.mp3'], // List of all audio files generated
299
+ error_code?: ERROR_CODE;
300
+ }
301
+ ```
302
+
303
+ **Error handling:**
304
+
305
+ - Possible Error Codes, `error_code`
306
+ - `txn_stop_failed`: Call `endRecording` again.
307
+ - `audio_upload_failed`: Use `retryUploadRecording` (step 9).
308
+ - `txn_commit_failed`: Call `commitTransactionCall` (step 11).
309
+
310
+ **Handling 401 Status Code:**
311
+
312
+ If you receive a `status_code: 401`, update the tokens in your config and retry:
313
+
314
+ ```ts
315
+ // Update tokens in your config variable
316
+ sdkConfig.access_token = '<new_access_token>';
317
+
318
+ // Update tokens in the instance
319
+ ekascribe.updateAuthTokens({ access_token: sdkConfig.access_token });
320
+
321
+ // Now retry the method call
322
+ const response = await ekascribe.endRecording();
323
+ ```
324
+
325
+ ### 8. Get output recorded prescription
326
+
327
+ You can fetch output in two ways:
328
+
329
+ - `getTemplateOutput({ txn_id })`: polling is your responsibility; call repeatedly until processing finishes.
330
+ - `pollSessionOutput({ txn_id, max_polling_time })`: SDK polls for you and resolves when processing finishes (default max wait: 2 minutes; override via `max_polling_time`, pass time in milliseconds).
331
+
332
+ Example (manual polling):
333
+
334
+ ```ts
335
+ const res = await ekascribe.getTemplateOutput({ txn_id: 'transaction-id' });
336
+ ```
337
+
338
+ Example (SDK-managed polling):
339
+
340
+ ```ts
341
+ // Waits up to 2 minutes by default; override as needed
342
+ const res = await ekascribe.pollSessionOutput({
343
+ txn_id: 'transaction-id',
344
+ max_polling_time: 2 * 60 * 1000, // optional
345
+ });
346
+ ```
347
+
348
+ Status codes to handle:
349
+
350
+ - `202`: Templates are still processing; poll again (or let `pollSessionOutput` continue).
351
+ - `500`: All template processing failed, or internal server error; stop and surface error.
352
+ - `206`: Partial success; some templates not processed fully.
353
+ - `200`: Success; all templates processed.
354
+
355
+ - #### Response type:
356
+
357
+ ```ts
358
+ {
359
+ response?: {
360
+ data: {
361
+ output: TOutputSummary[];
362
+ template_results: {
363
+ integration: TOutputSummary[];
364
+ custom: TOutputSummary[];
365
+ transcript: TOutputSummary[];
366
+ };
367
+ audio_matrix?: {
368
+ quality: string;
369
+ };
370
+ additional_data?: {};
371
+ created_at?: string;
372
+ };
373
+ error?: {
374
+ code: string;
375
+ msg: string;
376
+ };
377
+ } | null;
378
+ status_code: number;
379
+ message?: string;
380
+ }
381
+
382
+ type TOutputSummary = {
383
+ template_id: string;
384
+ value?: JSON | Array | string;
385
+ type: string;
386
+ name: string;
387
+ status: 'success' | 'partial_success' | 'failure';
388
+ errors?: Array<{
389
+ type: 'warning' | 'error';
390
+ code?: string;
391
+ msg: string;
392
+ }>;
393
+ warnings?: Array<{
394
+ type: 'warning' | 'error';
395
+ code?: string;
396
+ msg: string;
397
+ }>;
398
+ };
399
+ ```
400
+
401
+ - #### Example Response:
402
+
403
+ ```ts
404
+ {
405
+ status_code: 200,
406
+ response: {
407
+ data: {
408
+ output: [
409
+ {
410
+ template_id: "template_id_passed_in_initTransaction",
411
+ value: "Output Data for this template",
412
+ type: "custom",
413
+ name: "General Prescription",
414
+ status: "success"
415
+ }
416
+ ],
417
+ template_results: {
418
+ custom: [
419
+ {
420
+ template_id: "custom_template",
421
+ value: "Output prescription",
422
+ type: "custom",
423
+ name: "Custom Medication Template",
424
+ status: "partial_success",
425
+ warnings: [
426
+ {
427
+ type: "warning",
428
+ code: "FIELD_MISSING",
429
+ msg: "Dosage information not found"
430
+ }
431
+ ]
432
+ }
433
+ ]
434
+ },
435
+ audio_matrix: {
436
+ quality: "4.5"
437
+ },
438
+ created_at: "2024-11-19T10:30:00Z"
439
+ }
440
+ }
441
+ }
442
+ ```
443
+
444
+ ### 9. Retry upload recording
445
+
446
+ Retry uploading failed audio files after `endRecording`.
447
+
448
+ ```ts
449
+ const response = await ekascribe.retryUploadRecording({ force_commit: true });
450
+ ```
451
+
452
+ - #### Sample Response:
453
+
454
+ ```ts
455
+ {
456
+ "status_code": 200,
457
+ "message": "All files uploaded successfully after retry",
458
+ error_code?: ERROR_CODE;
459
+ failed_files?: ['1.mp3', '2.mp3'];
460
+ total_audio_files?: ['1.mp3', '2.mp3', '3.mp3', '4.mp3'];
461
+ }
462
+ ```
463
+
464
+ **`force_commit` behavior:**
465
+
466
+ - `force_commit: true` - Model will initiate the processing if some files still fail after retry
467
+ - `force_commit: false` - It will waits until all files are uploaded successfully before processing.
468
+
469
+ **Handling 401 Status Code:**
470
+
471
+ If you receive a `status_code: 401`, update the tokens in your config and retry:
472
+
473
+ ```ts
474
+ // Update tokens in your config variable
475
+ sdkConfig.access_token = '<new_access_token>';
476
+
477
+ // Update tokens in the instance
478
+ ekascribe.updateAuthTokens({ access_token: sdkConfig.access_token });
479
+
480
+ // Now retry the method call
481
+ const response = await ekascribe.retryUploadRecording({ force_commit: true });
482
+ ```
483
+
484
+ ### 10. Patch recording session status
485
+
486
+ Cancel or update the status of a recording session.
487
+
488
+ ```ts
489
+ const response = await ekascribe.patchSessionStatus({
490
+ sessionId: 'abc-123', // txn_id of the session you want to cancel
491
+ processing_status: 'cancelled', // pass exactly this value
492
+ processing_error: {
493
+ error: {
494
+ // Pass these exact values without changing them
495
+ type: 'user_action',
496
+ code: 'cancelled_by_user',
497
+ msg: 'Session cancelled by user',
498
+ },
499
+ },
500
+ });
501
+ ```
502
+
503
+ - #### Sample Response:
504
+
505
+ ```ts
506
+ {
507
+ "status": "success",
508
+ "message": "Session status updated successfully",
509
+ "code": 200,
510
+ error?: {
511
+ code: string;
512
+ message: string;
513
+ display_message: string;
514
+ };
515
+ }
516
+ ```
517
+
518
+ **Handling 401 Status Code:**
519
+
520
+ If you receive a `code: 401`, update the tokens in your config and retry:
521
+
522
+ ```ts
523
+ // Update tokens in your config variable
524
+ sdkConfig.access_token = '<new_access_token>';
525
+
526
+ // Update tokens in the instance
527
+ ekascribe.updateAuthTokens({ access_token: sdkConfig.access_token });
528
+
529
+ // Now retry the method call
530
+ const response = await ekascribe.patchSessionStatus({ ... });
531
+ ```
532
+
533
+ ### 11. Commit transaction
534
+
535
+ Call this if `endRecording` returns `error_code: 'txn_commit_failed'` or the transaction is not yet committed.
536
+
537
+ ```ts
538
+ const response = await ekascribe.commitTransactionCall();
539
+ ```
540
+
541
+ - #### Response type:
542
+
543
+ ```ts
544
+ {
545
+ error_code?: ERROR_CODE;
546
+ status_code: number;
547
+ message: string;
548
+ };
549
+ ```
550
+
551
+ **Handling 401 Status Code:**
552
+
553
+ If you receive a `status_code: 401`, update the tokens in your config and retry:
554
+
555
+ ```ts
556
+ // Update tokens in your config variable
557
+ sdkConfig.access_token = '<new_access_token>';
558
+
559
+ // Update tokens in the instance
560
+ ekascribe.updateAuthTokens({ access_token: sdkConfig.access_token });
561
+
562
+ // Now retry the method call
563
+ const response = await ekascribe.commitTransactionCall();
564
+ ```
565
+
566
+ ### 12. Stop transaction
567
+
568
+ Use this method to stop a transaction that has not yet been stopped or returned a `txn_stop_failed` error in a previous step.
569
+
570
+ ```ts
571
+ const response = await ekascribe.stopTransactionCall();
572
+ ```
573
+
574
+ - #### Response type:
575
+
576
+ ```ts
577
+ {
578
+ error_code?: ERROR_CODE;
579
+ status_code: number;
580
+ message: string;
581
+ };
582
+ ```
583
+
584
+ **Handling 401 Status Code:**
585
+
586
+ If you receive a `status_code: 401`, update the tokens in your config and retry:
587
+
588
+ ```ts
589
+ // Update tokens in your config variable
590
+ sdkConfig.access_token = '<new_access_token>';
591
+
592
+ // Update tokens in the instance
593
+ ekascribe.updateAuthTokens({ access_token: sdkConfig.access_token });
594
+
595
+ // Now retry the method call
596
+ const response = await ekascribe.stopTransactionCall();
597
+ ```
598
+
599
+ ### 13. Get previous sessions
600
+
601
+ Fetch previous sessions. `txn_count` controls how many sessions the API returns.
602
+
603
+ ```ts
604
+ const sessions = await ekascribe.getSessionHistory({ txn_count: 10 }); // txn_count = number of sessions to fetch
605
+ ```
606
+
607
+ - #### Response type:
608
+
609
+ ```ts
610
+ {
611
+ data: [
612
+ {
613
+ b_id: "7174661713699045", // business ID
614
+ created_at: "2025-12-10T10:28:00Z",
615
+ mode: "consultation",
616
+ oid: "174661713843153", // logged-in doctor's org ID
617
+ patient_details: { // present only if sent in initTransaction
618
+ "age": 18,
619
+ "biologicalSex": "M",
620
+ "username": ""
621
+ },
622
+ // processing_status can be: success | system_failure | request_failure | cancelled | in-progress
623
+ processing_status: "in-progress",
624
+ txn_id: "sc-c2e9be8b-46e5-489a-9473-236ddb5b24fb",
625
+ // user_status can be: init | commit
626
+ user_status: "init",
627
+ uuid: "c44fd76d-8de1-4011-aa54-5ddcca140f0f" // logged-in doctor's user ID
628
+ }
629
+ ],
630
+ status: "success",
631
+ code: 200,
632
+ message: "Sessions fetched",
633
+ retrieved_count: 1
634
+ }
635
+ ```
636
+
637
+ ## Templates SDK Methods
638
+
639
+ ### 1. Get All Templates
640
+
641
+ Use this method to retrieve all available templates for the current user.
642
+
643
+ ```ts
644
+ const templates = await ekascribe.getAllTemplates();
645
+ ```
646
+
647
+ - #### Response type:
648
+
649
+ ```ts
650
+ {
651
+ items: [
652
+ {
653
+ id: "123;
654
+ title: "Template Name";
655
+ desc: "Template Description";
656
+ section_ids: ["section-1", "section-2"];
657
+ is_editable: true | false;
658
+ }
659
+ ];
660
+ code: number;
661
+ error?: { code: string; message: string };
662
+ }
663
+ ```
664
+
665
+ ### 2. Create Template
666
+
667
+ Use this method to create a new custom template.
668
+
669
+ ```ts
670
+ const newTemplate = await ekascribe.createTemplate({
671
+ title: 'My Custom Template',
672
+ desc: 'Description of the template',
673
+ section_ids: ['section1', 'section2', 'section3'],
674
+ });
675
+ ```
676
+
677
+ - #### Response type:
678
+
679
+ ```ts
680
+ {
681
+ code: number;
682
+ msg: string;
683
+ template_id?: string;
684
+ message?: string;
685
+ error?: { code: string; message: string };
686
+ }
687
+ ```
688
+
689
+ ### 3. Edit Template
690
+
691
+ Use this method to update an existing template.
692
+
693
+ ```ts
694
+ const updatedTemplate = await ekascribe.updateTemplate({
695
+ template_id: 'template-123',
696
+ title: 'Updated Template Title',
697
+ desc: 'Updated description',
698
+ section_ids: ['section1', 'section2', 'section4'],
699
+ });
700
+ ```
701
+
702
+ - #### Response type:
703
+
704
+ ```ts
705
+ {
706
+ code: number;
707
+ msg: string;
708
+ template_id?: string;
709
+ message?: string;
710
+ error?: { code: string; message: string };
711
+ }
712
+ ```
713
+
714
+ ### 4. Delete Template
715
+
716
+ Use this method to delete an existing template.
717
+
718
+ ```ts
719
+ const deleteResult = await ekascribe.deleteTemplate('template-123');
720
+ ```
721
+
722
+ - #### Response type:
723
+
724
+ ```ts
725
+ {
726
+ code: number;
727
+ msg: string;
728
+ template_id?: string;
729
+ message?: string;
730
+ error?: { code: string; message: string };
731
+ }
732
+ ```
733
+
734
+ ### 5. Generate Template with AI by giving a prompt
735
+
736
+ Use this method to generate a template using AI with a text prompt.
737
+
738
+ ```ts
739
+ const formData = new FormData();
740
+ formData.append('content', 'Create a cardiology consultation template');
741
+ formData.append('file', file);
742
+ formData.append('contentType', 'text/file');
743
+
744
+ const aiTemplate = await ekascribe.aiGenerateTemplate(formData);
745
+ ```
746
+
747
+ - #### Response type:
748
+
749
+ ```ts
750
+ {
751
+ title: string;
752
+ desc: string;
753
+ sections: [
754
+ {
755
+ id: string;
756
+ title: string;
757
+ desc: string;
758
+ format: 'P' | 'B';
759
+ example: string;
760
+ default?: boolean;
761
+ parent_section_id?: string;
762
+ }
763
+ ];
764
+ code: number;
765
+ message: string;
766
+ }
767
+ ```
768
+
769
+ ### 6. Add templates to list
770
+
771
+ Use this method to mark templates as favourite templates.
772
+
773
+ ```ts
774
+ const configUpdate = await ekascribe.updateConfig({
775
+ my_templates: ['template1', 'template2'],
776
+ });
777
+ ```
778
+
779
+ - #### Response type:
780
+
781
+ ```ts
782
+ {
783
+ auto_download?: boolean;
784
+ default_languages?: string[];
785
+ my_templates?: string[];
786
+ scribe_enabled?: boolean;
787
+ msg: string;
788
+ code: number;
789
+ error?: { code: string; message: string };
790
+ }
791
+ ```
792
+
793
+ ### 7. Get All Sections
794
+
795
+ Use this method to retrieve all available template sections.
796
+
797
+ ```ts
798
+ const sections = await ekascribe.getAllTemplateSections();
799
+ ```
800
+
801
+ - #### Response type:
802
+
803
+ ```ts
804
+ {
805
+ items: [
806
+ {
807
+ id: string;
808
+ title: string;
809
+ desc: string;
810
+ format: 'P' | 'B';
811
+ example: string;
812
+ default?: boolean;
813
+ parent_section_id?: string;
814
+ }
815
+ ];
816
+ code: number;
817
+ error?: { code: string; message: string };
818
+ }
819
+ ```
820
+
821
+ ### 8. Create Section in a template
822
+
823
+ Use this method to create a new section that can be used in templates.
824
+
825
+ ```ts
826
+ const newSection = await ekascribe.createTemplateSection({
827
+ title: 'Chief Complaint',
828
+ desc: "Patient's primary concern",
829
+ format: 'P', // 'P' for paragraph, 'B' for bullet points
830
+ example: 'Patient presents with chest pain for 2 days',
831
+ });
832
+ ```
833
+
834
+ - #### Response type:
835
+
836
+ ```ts
837
+ {
838
+ msg: string;
839
+ section_id: string;
840
+ code: number;
841
+ action: 'updated' | 'created_custom';
842
+ error?: { code: string; message: string };
843
+ }
844
+ ```
845
+
846
+ ### 9. Edit Section in a template
847
+
848
+ Use this method to update an existing template section.
849
+
850
+ ```ts
851
+ const updatedSection = await ekascribe.updateTemplateSection({
852
+ section_id: 'section-123',
853
+ title: 'Updated Chief Complaint',
854
+ desc: 'Updated description',
855
+ format: 'B',
856
+ example: 'Updated example text',
857
+ });
858
+ ```
859
+
860
+ - #### Response type:
861
+
862
+ ```ts
863
+ {
864
+ msg: string;
865
+ section_id: string;
866
+ code: number;
867
+ action: 'updated' | 'created_custom';
868
+ error?: { code: string; message: string };
869
+ }
870
+ ```
871
+
872
+ ### 10. Delete Section from a template
873
+
874
+ Use this method to delete a template section.
875
+
876
+ ```ts
877
+ const deleteResult = await ekascribe.deleteTemplateSection('section-123');
878
+ ```
879
+
880
+ - #### Response type:
881
+
882
+ ```ts
883
+ {
884
+ msg: string;
885
+ section_id: string;
886
+ code: number;
887
+ action: 'updated' | 'created_custom';
888
+ error?: { code: string; message: string };
889
+ }
890
+ ```
891
+
892
+ ## Non-vaded flow: Upload raw audio to get output summary
893
+
894
+ Use this method to upload pre-recorded audio files directly and get transcription output without real-time recording. This is useful when you have existing audio files and want to process them.
895
+
896
+ **What this method does:**
897
+
898
+ - Gets a presigned URL from the server
899
+ - Uploads audio files to S3 via presigned URL
900
+ - Initializes a transaction with the uploaded files
901
+ - Returns the transaction details
902
+
903
+ ```ts
904
+ const audioFiles = [file1, file2]; // File or Blob objects
905
+ const audioFileNames = ['audio1.mp3', 'audio2.mp3'];
906
+
907
+ const response = await ekascribe.uploadAudioWithPresignedUrl({
908
+ action: 'ekascribe-v2', // Pass this exact value without changing
909
+ audioFiles,
910
+ audioFileNames,
911
+ mode: 'consultation',
912
+ txn_id: 'unique-transaction-id',
913
+ input_language: ['en-IN'],
914
+ output_format_template: [{ template_id: 'your_template_id' }],
915
+ transfer: 'non-vaded', // Use 'non-vaded' for raw audio files
916
+ model_type: 'pro' | 'lite',
917
+ system_info: {
918
+ platform: 'web',
919
+ language: 'en',
920
+ time_zone: 'Asia/Kolkata',
921
+ },
922
+ patient_details: {
923
+ username: 'John Doe',
924
+ age: 35,
925
+ biologicalSex: 'M',
926
+ },
927
+ version: '1.0.0',
928
+ additional_data: {},
929
+ });
930
+ ```
931
+
932
+ **Key Parameters:**
933
+
934
+ - `action`: Pass `ekascribe-v2` exactly as shown
935
+ - `audioFiles`: Array of File or Blob objects
936
+ - `audioFileNames`: Array of file names corresponding to audio files
937
+ - `transfer`: Use `non-vaded` for raw audio files (not processed with VAD)
938
+ - Other parameters: Same as `initTransaction` (see step 3)
939
+
940
+ - #### Sample Response:
941
+
942
+ ```ts
943
+ {
944
+ error_code?: ERROR_CODE,
945
+ status_code: 200,
946
+ message: 'Recording uploaded successfully.',
947
+ }
948
+ ```
949
+
950
+ **Error handling:**
951
+
952
+ Possible Error Codes in `error_code`:
953
+
954
+ - `get_presigned_url_failed`: Failed to get presigned URL from server, retry with the same method
955
+ - `audio_upload_failed`: Failed to upload audio files to S3, retry with the same method
956
+ - `txn_limit_exceeded`: Maximum number of transactions exceeded
957
+ - `txn_init_failed`: Failed to initialize transaction after upload, retry with the same method
958
+
959
+ **Handling 401 Status Code:**
960
+
961
+ If you receive a `status_code: 401`, update the tokens in your config and retry:
962
+
963
+ ```ts
964
+ // Update tokens in your config variable
965
+ sdkConfig.access_token = '<new_access_token>';
966
+
967
+ // Update tokens in the instance
968
+ ekascribe.updateAuthTokens({ access_token: sdkConfig.access_token });
969
+
970
+ // Now retry the method call
971
+ const response = await ekascribe.uploadAudioWithPresignedUrl({ ... });
972
+ ```
973
+
974
+ ## Utility Methods
975
+
976
+ ### 1. Get total uploaded files
977
+
978
+ Use this method to retrieve all the audio files generated for a specific session.
979
+
980
+ ```ts
981
+ const files = ekascribe.getTotalAudioFiles();
982
+ ```
983
+
984
+ - #### Response type:
985
+
986
+ ```ts
987
+ ['1.mp3', '2.mp3', '3.mp3', '4.mp3'];
988
+ ```
989
+
990
+ ### 2. Get successfully uploaded files
991
+
992
+ Use this method to retrieve all the audio files that were uploaded successfully.
993
+
994
+ ```ts
995
+ const successFiles = ekascribe.getSuccessFiles();
996
+ ```
997
+
998
+ - #### Response type:
999
+
1000
+ ```ts
1001
+ ['3.mp3', '4.mp3'];
1002
+ ```
1003
+
1004
+ ### 3. Get failed audio files
1005
+
1006
+ Use this method to retrieve all the audio files that failed to upload.
1007
+
1008
+ ```ts
1009
+ const failedFiles = ekascribe.getFailedFiles();
1010
+ ```
1011
+
1012
+ - #### Response type:
1013
+
1014
+ ```ts
1015
+ ['1.mp3', '2.mp3'];
1016
+ ```
1017
+
1018
+ ### 4. Reset Class Instance
1019
+
1020
+ Use this method to reset the EkaScribe instance and clear all stored data.
1021
+
1022
+ ```ts
1023
+ ekaScribe.resetEkaScribe();
1024
+ ```
1025
+
1026
+ ### 5. Reinitialise VAD Instance
1027
+
1028
+ Use this method to reinitialize the Voice Activity Detection (VAD) instance.
1029
+
1030
+ ```ts
1031
+ ekaScribe.reinitializeVad();
1032
+ ```
1033
+
1034
+ ### 6. Pause VAD Instance
1035
+
1036
+ Use this method to pause the Voice Activity Detection without stopping the recording session.
1037
+
1038
+ ```ts
1039
+ ekaScribe.pauseVad();
1040
+ ```
1041
+
1042
+ ### 7. Destroy VAD Instance
1043
+
1044
+ Use this method to completely destroy the VAD instance and free up resources.
1045
+
1046
+ ```ts
1047
+ ekaScribe.destroyVad();
1048
+ ```
1049
+
1050
+ ## Generic Callbacks
1051
+
1052
+ ### 1. Event callback
1053
+
1054
+ This is a comprehensive callback that provides information about SDK operations, including success events, errors, progress updates, and system status. Use this callback to monitor all SDK activities and handle events globally in your application.
1055
+
1056
+ ```ts
1057
+ ekaScribe.onEventCallback((eventData) => {
1058
+ console.log('Event callback triggered:', eventData);
1059
+ });
1060
+ ```
1061
+
1062
+ - #### Sample Callback Data:
1063
+
1064
+ ```ts
1065
+ {
1066
+ callback_type: 'AUDIO_UPLOAD' | 'TRANSACTION_STATUS' | 'VAD_STATUS' | 'RECORDING_STATUS',
1067
+ status: 'success' | 'error' | 'progress' | 'info',
1068
+ message: 'Audio file uploaded successfully',
1069
+ error?: {
1070
+ code: 500,
1071
+ msg: 'Upload failed',
1072
+ details: { fileName: 'audio_chunk_1.mp3' }
1073
+ },
1074
+ data?: {
1075
+ success: 3,
1076
+ total: 4,
1077
+ is_uploaded: true,
1078
+ fileName: 'audio_chunk_1.mp3',
1079
+ request: { txn_id: 'abc-123' },
1080
+ response: { status: 'uploaded' }
1081
+ },
1082
+ timestamp: '2024-01-15T10:30:45.123Z',
1083
+ metadata?: {
1084
+ txn_id: 'abc-123',
1085
+ chunk_index: 1
1086
+ }
1087
+ }
1088
+ ```
1089
+
1090
+ ### 2. User speech callback
1091
+
1092
+ This callback will return a boolean indicating whether the user is speaking or not.
1093
+
1094
+ ```ts
1095
+ ekaScribe.onUserSpeechCallback((isSpeech) => {
1096
+ console.log(isSpeech ? 'User is speaking' : 'User is not speaking');
1097
+ });
1098
+ ```
1099
+
1100
+ ### Error codes
1101
+
1102
+ | Error Code | Description |
1103
+ | --------------------- | ----------------------------------------------------------- |
1104
+ | `microphone` | Microphone access error (permission denied or unavailable) |
1105
+ | `txn_init_failed` | Failed to initialize transaction |
1106
+ | `txn_limit_exceeded` | Maximum number of concurrent transactions exceeded |
1107
+ | `unknown_error` | An unknown or unclassified error occurred |
1108
+ | `txn_stop_failed` | Error occurred while stopping the transaction |
1109
+ | `audio_upload_failed` | Audio file upload to server failed |
1110
+ | `txn_commit_failed` | Commit call failed for the current transaction |
1111
+ | `invalid_request` | Request to SDK was malformed or missing required parameters |
1112
+ | `vad_not_initialized` | Voice activity detection engine was not initialized |
1113
+ | `no_audio_capture` | No audio was captured during the recording session |
1114
+ | `txn_status_mismatch` | Invalid operation due to mismatched transaction status |
1115
+
1116
+ ## Contribution Guidelines
1117
+
1118
+ This is a continually updated, open source project.
1119
+ Contributions are welcome!
1120
+
1121
+ ## Tips
1122
+
1123
+ - The SDK internally handles shared worker logic to reduce load on the main thread. Try to execute these functions in the main thread to avoid unnecessary issues.
1124
+
1125
+ ## Advanced Usage (for later use)
1126
+
1127
+ - Maximum retries for file upload in case of failure.
1128
+ - Update VAD configurations
1129
+
1130
+ ## Under Development
1131
+
1132
+ - Opus compression of audio files
1133
+ - Test cases
1134
+
1135
+ Refer [Ekascribe](https://github.com/eka-care/v2rx-extension) for SDK implementations.