@ctchealth/plato-sdk 0.0.18 → 0.0.19

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.
@@ -0,0 +1,776 @@
1
+ /**
2
+ * Copyright (c) 2025 ctcHealth. All rights reserved.
3
+ *
4
+ * This file is part of the ctcHealth Plato Platform, a proprietary software system developed by ctcHealth.
5
+ *
6
+ * This source code and all related materials are confidential and proprietary to ctcHealth.
7
+ * Unauthorized access, use, copying, modification, distribution, or disclosure is strictly prohibited
8
+ * and may result in disciplinary action and civil and/or criminal penalties.
9
+ *
10
+ * This software is intended solely for authorized use within ctcHealth and its designated partners.
11
+ *
12
+ * For internal use only.
13
+ */
14
+ import axios, { AxiosInstance } from 'axios';
15
+ import {
16
+ CallCreateDto,
17
+ CallDTO,
18
+ CreateSimulationDto,
19
+ CreationPhase,
20
+ SimulationRecordingsDto,
21
+ SimulationRecordingsQueryDto,
22
+ SimulationDetailsDto,
23
+ RecommendationsResponseDto,
24
+ RequestPdfUploadResponse,
25
+ PdfSlidesDto,
26
+ PdfSlideDto,
27
+ PdfSlidesAnalysisQueryDto,
28
+ CheckPdfStatusResponse,
29
+ AssistantImageDto,
30
+ ActiveCallState,
31
+ } from './plato-intefaces';
32
+ import Vapi from '@vapi-ai/web';
33
+ import { Call } from '@vapi-ai/web/dist/api';
34
+ import { checkFile, calculateHash, getPdfPageCount } from './utils';
35
+ import { MAX_PDF_FILE_SIZE, ALLOWED_PDF_MIME_TYPES, MAX_PDF_PAGES } from './constants';
36
+
37
+ export interface ApiClientConfig {
38
+ baseUrl: string;
39
+ jwtToken: string;
40
+ publicKey: string;
41
+ }
42
+
43
+ export interface ToolCall {
44
+ function: {
45
+ name: string;
46
+ arguments: {
47
+ slideNumber?: number;
48
+ progressObjectiveNumber?: number;
49
+ [key: string]: unknown;
50
+ };
51
+ };
52
+ id: string;
53
+ }
54
+
55
+ /**
56
+ * Event map for call events, providing strict typing for each event's payload.
57
+ * There are no inputs for the events and all of them return void.
58
+ */
59
+ export interface CallEventMap {
60
+ 'call-start': undefined;
61
+ 'call-end': undefined;
62
+ 'speech-start': undefined;
63
+ 'speech-end': undefined;
64
+ error: Error;
65
+ message: {
66
+ type: string;
67
+ role: string;
68
+ transcript?: string;
69
+ transcriptType: 'final' | 'partial';
70
+ toolCallList?: ToolCall[]; // used in real-time messages to the client
71
+ toolCalls?: ToolCall[]; // used in conversation history
72
+ [key: string]: unknown;
73
+ };
74
+ 'volume-level': number;
75
+ 'call-details-ready': CallDTO;
76
+ }
77
+
78
+ export type CallEventNames = keyof CallEventMap;
79
+
80
+ export type CallEventListener<K extends CallEventNames> = (payload: CallEventMap[K]) => void;
81
+
82
+ export class PlatoApiClient {
83
+ private static readonly ACTIVE_CALL_STORAGE_KEY = 'plato_active_call';
84
+
85
+ private http: AxiosInstance;
86
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-function-type
87
+ private eventListeners: Partial<Record<CallEventNames, Function[]>> = {};
88
+ private callControllerInstance?: Vapi;
89
+ private eventsAttached = false;
90
+ private currentCallId?: string;
91
+ // Vapi-native events (events that Vapi SDK supports)
92
+ // Exclude our custom SDK events from this list
93
+ private vapiEventNames: Exclude<CallEventNames, 'call-details-ready'>[] = [
94
+ 'call-start',
95
+ 'call-end',
96
+ 'speech-start',
97
+ 'speech-end',
98
+ 'error',
99
+ 'message',
100
+ 'volume-level',
101
+ ];
102
+ // All event names including SDK-specific events
103
+ eventNames: CallEventNames[] = [
104
+ 'call-start',
105
+ 'call-end',
106
+ 'speech-start',
107
+ 'speech-end',
108
+ 'error',
109
+ 'message',
110
+ 'volume-level',
111
+ 'call-details-ready',
112
+ ];
113
+
114
+ constructor(private config: ApiClientConfig) {
115
+ if (!config.baseUrl) {
116
+ throw new Error('baseUrl is required');
117
+ }
118
+
119
+ if (config.baseUrl.endsWith('/')) {
120
+ config.baseUrl = config.baseUrl.slice(0, -1);
121
+ }
122
+
123
+ this.http = axios.create({
124
+ baseURL: config.baseUrl,
125
+ headers: {
126
+ 'x-client-token': config.jwtToken,
127
+ },
128
+ });
129
+ }
130
+
131
+ /**
132
+ * Update the JWT token for all subsequent requests.
133
+ * Useful when the token is refreshed or when switching user context.
134
+ */
135
+ setJwtToken(jwtToken: string): void {
136
+ this.http.defaults.headers.common['x-client-token'] = jwtToken;
137
+ }
138
+
139
+ /**
140
+ * Remove the JWT token from subsequent requests.
141
+ */
142
+ clearJwtToken(): void {
143
+ delete this.http.defaults.headers.common['x-client-token'];
144
+ }
145
+
146
+ /**
147
+ * Register a listener for a call event with strict typing.
148
+ * @param event Event name
149
+ * @param listener Listener function
150
+ */
151
+ private on<K extends CallEventNames>(event: K, listener: CallEventListener<K>): void {
152
+ if (!this.eventListeners[event]) {
153
+ this.eventListeners[event] = [];
154
+ }
155
+ const listeners = this.eventListeners[event];
156
+
157
+ if (listeners) {
158
+ listeners.push(listener);
159
+ }
160
+ if (this.callControllerInstance && !this.eventsAttached) {
161
+ this.attachEvents();
162
+ }
163
+ }
164
+
165
+ /**
166
+ * Remove a listener for a call event with strict typing.
167
+ * @param event Event name
168
+ * @param listener Listener function
169
+ */
170
+ private off<K extends CallEventNames>(event: K, listener: CallEventListener<K>): void {
171
+ const listeners = this.eventListeners[event];
172
+
173
+ if (!listeners) return;
174
+ this.eventListeners[event] = listeners.filter(l => l !== listener);
175
+ }
176
+
177
+ /**
178
+ * Internal: Attach event listeners and propagate to registered listeners.
179
+ */
180
+ private attachEvents(): void {
181
+ if (this.eventsAttached || !this.callControllerInstance) return;
182
+ this.eventsAttached = true;
183
+ const vapi = this.callControllerInstance;
184
+
185
+ // Only attach Vapi-native events to the Vapi instance
186
+ this.vapiEventNames.forEach(event => {
187
+ vapi.on(event, (payload: CallEventMap[CallEventNames]) => {
188
+ (this.eventListeners[event] || []).forEach(listener => listener(payload));
189
+ });
190
+ });
191
+ }
192
+
193
+ /**
194
+ * Internal: Emit SDK-specific events that are not part of Vapi.
195
+ */
196
+ private emit<K extends CallEventNames>(event: K, payload: CallEventMap[K]): void {
197
+ const listeners = this.eventListeners[event];
198
+ if (listeners) {
199
+ listeners.forEach(listener => listener(payload));
200
+ }
201
+ }
202
+
203
+ /**
204
+ * Store active call state in localStorage for recovery purposes.
205
+ * @private
206
+ */
207
+ private storeCallState(state: ActiveCallState): void {
208
+ try {
209
+ localStorage.setItem(PlatoApiClient.ACTIVE_CALL_STORAGE_KEY, JSON.stringify(state));
210
+ } catch (error) {
211
+ console.warn('Failed to store call state:', error);
212
+ }
213
+ }
214
+
215
+ /**
216
+ * Retrieve active call state from localStorage.
217
+ * Validates the stored data and clears it if invalid.
218
+ * @private
219
+ * @returns The stored call state or null if not found or invalid
220
+ */
221
+ private getStoredCallState(): ActiveCallState | null {
222
+ try {
223
+ const stored = localStorage.getItem(PlatoApiClient.ACTIVE_CALL_STORAGE_KEY);
224
+ if (!stored) {
225
+ return null;
226
+ }
227
+
228
+ const parsed = JSON.parse(stored) as ActiveCallState;
229
+
230
+ // Validate required fields
231
+ if (!parsed.callId || !parsed.externalCallId || !parsed.simulationId || !parsed.startedAt) {
232
+ console.warn('Invalid stored call state, clearing');
233
+ this.clearCallState();
234
+ return null;
235
+ }
236
+
237
+ return parsed;
238
+ } catch (error) {
239
+ console.warn('Failed to retrieve call state:', error);
240
+ return null;
241
+ }
242
+ }
243
+
244
+ /**
245
+ * Clear active call state from localStorage.
246
+ * @private
247
+ */
248
+ private clearCallState(): void {
249
+ try {
250
+ localStorage.removeItem(PlatoApiClient.ACTIVE_CALL_STORAGE_KEY);
251
+ } catch (error) {
252
+ console.warn('Failed to clear call state:', error);
253
+ }
254
+ }
255
+
256
+ /**
257
+ * Check if a stored call is considered abandoned based on age.
258
+ * Calls older than 5 minutes are considered abandoned.
259
+ * @private
260
+ * @param state The call state to check
261
+ * @returns true if the call is abandoned, false otherwise
262
+ */
263
+ private isCallAbandoned(state: ActiveCallState): boolean {
264
+ const ABANDONMENT_THRESHOLD_MS = 5 * 60 * 1000; // 5 minutes
265
+ const startedAt = new Date(state.startedAt).getTime();
266
+ const now = Date.now();
267
+ const age = now - startedAt;
268
+
269
+ return age > ABANDONMENT_THRESHOLD_MS;
270
+ }
271
+
272
+ /**
273
+ * Recover and clean up any abandoned calls from previous sessions.
274
+ *
275
+ * This method should be called during application initialization,
276
+ * typically in ngOnInit() or useEffect(). It detects calls that were
277
+ * active when the page was last refreshed and notifies the backend
278
+ * to process them if they're older than 5 minutes.
279
+ *
280
+ * The backend endpoint is idempotent, so calling this method multiple
281
+ * times for the same call is safe.
282
+ *
283
+ * @returns Promise<boolean> - true if an abandoned call was recovered and processed
284
+ *
285
+ * @example
286
+ * // In Angular component
287
+ * async ngOnInit(): Promise<void> {
288
+ * const recovered = await this.platoClient.recoverAbandonedCall();
289
+ * if (recovered) {
290
+ * console.log('Recovered abandoned call from previous session');
291
+ * }
292
+ * }
293
+ *
294
+ * @example
295
+ * // In React component
296
+ * useEffect(() => {
297
+ * platoClient.recoverAbandonedCall()
298
+ * .then(recovered => {
299
+ * if (recovered) {
300
+ * console.log('Recovered abandoned call');
301
+ * }
302
+ * })
303
+ * .catch(console.error);
304
+ * }, []);
305
+ */
306
+ async recoverAbandonedCall(): Promise<boolean> {
307
+ try {
308
+ const storedState = this.getStoredCallState();
309
+
310
+ if (!storedState) {
311
+ return false;
312
+ }
313
+
314
+ if (!this.isCallAbandoned(storedState)) {
315
+ return false;
316
+ }
317
+
318
+ console.log('Detected abandoned call, notifying backend:', storedState.callId);
319
+
320
+ try {
321
+ const response = await this.http.post('/api/v1/postcall/call-ended', {
322
+ callId: storedState.callId,
323
+ });
324
+
325
+ console.log('Backend notified of abandoned call:', response.data);
326
+ } catch (error) {
327
+ console.error('Failed to notify backend of abandoned call:', error);
328
+ }
329
+
330
+ this.clearCallState();
331
+
332
+ return true;
333
+ } catch (error) {
334
+ console.error('Error during call recovery:', error);
335
+ this.clearCallState();
336
+ return false;
337
+ }
338
+ }
339
+
340
+ async createSimulation(createSimulationParams: CreateSimulationDto): Promise<{
341
+ simulationId: string;
342
+ phase: CreationPhase;
343
+ }> {
344
+ try {
345
+ const res = await this.http.post('/api/v1/simulation', {
346
+ ...createSimulationParams,
347
+ });
348
+ return {
349
+ simulationId: res.data.simulationId,
350
+ phase: res.data.phase,
351
+ };
352
+ } catch (e) {
353
+ if (axios.isAxiosError(e)) {
354
+ console.error('Error creating simulation:', e.response?.data.message);
355
+ }
356
+ throw e;
357
+ }
358
+ }
359
+
360
+ async checkSimulationStatus(simulationId: string): Promise<{
361
+ phase: CreationPhase;
362
+ }> {
363
+ const res = await this.http.get(`/api/v1/simulation/status/${simulationId}`);
364
+
365
+ return res.data;
366
+ }
367
+
368
+ async getUserSimulations(): Promise<Array<{ simulationId: string; phase: CreationPhase }>> {
369
+ try {
370
+ const res = await this.http.get('/api/v1/simulation/user/simulations');
371
+ return res.data;
372
+ } catch (e) {
373
+ if (axios.isAxiosError(e)) {
374
+ console.error('Error getting user simulations:', e.response?.data.message);
375
+ }
376
+ throw e;
377
+ }
378
+ }
379
+
380
+ async getSimulationDetails(simulationId: string): Promise<SimulationDetailsDto> {
381
+ try {
382
+ const res = await this.http.get(`/api/v1/simulation/details/${simulationId}`);
383
+ return res.data as SimulationDetailsDto;
384
+ } catch (e) {
385
+ if (axios.isAxiosError(e)) {
386
+ console.error('Error getting simulation details:', e.response?.data.message);
387
+ }
388
+ throw e;
389
+ }
390
+ }
391
+
392
+ /**
393
+ * Deletes a simulation (assistant) from the server and Vapi.
394
+ * @param simulationId - MongoDB ObjectId of the simulation
395
+ * @throws 404 if simulation not found
396
+ */
397
+ async deleteSimulation(simulationId: string): Promise<void> {
398
+ try {
399
+ await this.http.delete(`/api/v1/simulation/${simulationId}`);
400
+ } catch (e) {
401
+ if (axios.isAxiosError(e)) {
402
+ console.error('Error deleting simulation:', e.response?.data.message);
403
+ }
404
+ throw e;
405
+ }
406
+ }
407
+
408
+ async getCallDetails(callId: string): Promise<CallDTO> {
409
+ try {
410
+ const res = await this.http.get(`/api/v1/simulation/call/${callId}`);
411
+ return res.data as CallDTO;
412
+ } catch (e) {
413
+ if (axios.isAxiosError(e)) {
414
+ console.error('Error getting call details:', e.response?.data.message);
415
+ }
416
+ throw e;
417
+ }
418
+ }
419
+
420
+ async getCallRecordings(
421
+ queryParams: SimulationRecordingsQueryDto
422
+ ): Promise<SimulationRecordingsDto[]> {
423
+ try {
424
+ const res = await this.http.get(`/api/v1/simulation/call/recordings`, {
425
+ params: queryParams,
426
+ });
427
+ return res.data as SimulationRecordingsDto[];
428
+ } catch (e) {
429
+ if (axios.isAxiosError(e)) {
430
+ console.error('Error getting call recordings:', e.response?.data.message);
431
+ }
432
+ throw e;
433
+ }
434
+ }
435
+
436
+ async getCallRecording(callId: string): Promise<string> {
437
+ try {
438
+ const res = await this.http.get(`/api/v1/simulation/call/recordings/${callId}`);
439
+ return res.data as string;
440
+ } catch (e) {
441
+ if (axios.isAxiosError(e)) {
442
+ console.error('Error getting call recording:', e.response?.data.message);
443
+ }
444
+ throw e;
445
+ }
446
+ }
447
+
448
+ /**
449
+ * Remove all listeners for all call events.
450
+ */
451
+ private removeAllEventListeners(): void {
452
+ if (!this.callControllerInstance) return;
453
+ this.eventNames.forEach(event => {
454
+ (this.eventListeners[event] || []).forEach(listener => {
455
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
456
+ // @ts-expect-error
457
+ this.callControllerInstance?.off(event, listener);
458
+ });
459
+ this.eventListeners[event] = [];
460
+ });
461
+ this.eventsAttached = false;
462
+ }
463
+
464
+ async startCall(simulationId: string) {
465
+ // Check for any previous call state before starting new call
466
+ // If found, notify backend to ensure it gets processed
467
+ const storedState = this.getStoredCallState();
468
+ if (storedState) {
469
+ console.log(
470
+ 'Found previous call state, notifying backend before starting new call:',
471
+ storedState.callId
472
+ );
473
+ try {
474
+ await this.http.post('/api/v1/postcall/call-ended', {
475
+ callId: storedState.callId,
476
+ });
477
+ console.log('Backend notified of previous call');
478
+ } catch (error) {
479
+ console.error('Failed to notify backend of previous call:', error);
480
+ }
481
+ }
482
+
483
+ // Now clear the state before starting new call
484
+ this.clearCallState();
485
+
486
+ this.callControllerInstance = new Vapi(
487
+ this.config.publicKey,
488
+ 'https://db41aykk1gw9e.cloudfront.net' // base url
489
+ );
490
+ if (!this.eventsAttached) {
491
+ this.attachEvents();
492
+ }
493
+
494
+ // Internal call-end listener
495
+ this.callControllerInstance.on('call-end', () => {
496
+ this.onCallEnded().catch(error => {
497
+ console.error('Error in onCallEnded: ', error);
498
+ });
499
+ });
500
+
501
+ const { data } = await this.http.get(`/api/v1/simulation/${simulationId}`);
502
+ const assistantId = data as string;
503
+ const call: Call | null = await this.callControllerInstance.start(assistantId);
504
+
505
+ if (!call || !call.assistantId) {
506
+ throw new Error('Cannot start a call, please try again later');
507
+ }
508
+ try {
509
+ const apiCall = await this.createCall({
510
+ callId: call.id,
511
+ assistantId: call.assistantId,
512
+ });
513
+
514
+ // Store the callId for use in onCallEnded
515
+ this.currentCallId = apiCall._id;
516
+
517
+ // Store call state in localStorage for recovery
518
+ this.storeCallState({
519
+ callId: apiCall._id,
520
+ externalCallId: call.id,
521
+ simulationId: simulationId,
522
+ startedAt: new Date().toISOString(),
523
+ version: 1,
524
+ });
525
+
526
+ // Return stopCall, callId, and event subscription methods with strict typing
527
+ return {
528
+ stopCall: () => {
529
+ this.callControllerInstance?.stop();
530
+ this.removeAllEventListeners();
531
+ this.clearCallState();
532
+ },
533
+ callId: apiCall._id,
534
+ /**
535
+ * Subscribe to call events for this call with strict typing.
536
+ * @param event Event name
537
+ * @param listener Listener function
538
+ */
539
+ on: <K extends CallEventNames>(event: K, listener: CallEventListener<K>) =>
540
+ this.on(event, listener),
541
+ /**
542
+ * Unsubscribe from call events for this call with strict typing.
543
+ * @param event Event name
544
+ * @param listener Listener function
545
+ */
546
+ off: <K extends CallEventNames>(event: K, listener: CallEventListener<K>) =>
547
+ this.off(event, listener),
548
+ };
549
+ } catch (e) {
550
+ this.callControllerInstance?.stop();
551
+ this.removeAllEventListeners();
552
+ this.clearCallState();
553
+ throw e;
554
+ }
555
+ }
556
+
557
+ private async onCallEnded(): Promise<void> {
558
+ let callIdForRetry: string | undefined;
559
+ try {
560
+ if (!this.currentCallId) {
561
+ return;
562
+ }
563
+
564
+ callIdForRetry = this.currentCallId;
565
+
566
+ // First attempt
567
+ let response = await this.http.post('/api/v1/postcall/call-ended', {
568
+ callId: callIdForRetry,
569
+ });
570
+
571
+ // If status is "processing", retry once immediately
572
+ if (response.data?.status === 'processing') {
573
+ response = await this.http.post('/api/v1/postcall/call-ended', {
574
+ callId: callIdForRetry,
575
+ });
576
+ }
577
+
578
+ // After onCallEnded completes successfully, fetch and emit call details
579
+ try {
580
+ const callDetails = await this.getCallDetails(callIdForRetry);
581
+ this.emit('call-details-ready', callDetails);
582
+ } catch (error) {
583
+ console.error('Error fetching call details after call ended:', error);
584
+ // Don't throw - we don't want to break the onCallEnded flow
585
+ }
586
+ } catch {
587
+ // Silently handle errors in post-call processing
588
+ } finally {
589
+ // Clean up the callId after processing (success or failure)
590
+ this.currentCallId = undefined;
591
+ // Clear stored call state after normal call end
592
+ this.clearCallState();
593
+ }
594
+ }
595
+
596
+ private async createCall(payload: CallCreateDto) {
597
+ const response = await this.http.post('/api/v1/simulation/call', {
598
+ ...payload,
599
+ });
600
+
601
+ return response.data as CallDTO;
602
+ }
603
+
604
+ async uploadPdfSlides(file: File | Blob): Promise<string> {
605
+ try {
606
+ const checkResult = checkFile(file, MAX_PDF_FILE_SIZE, ALLOWED_PDF_MIME_TYPES);
607
+
608
+ if (checkResult !== true) {
609
+ throw new Error(checkResult);
610
+ }
611
+
612
+ // Check PDF page count before proceeding
613
+ const pageCount = await getPdfPageCount(file);
614
+ if (pageCount > MAX_PDF_PAGES) {
615
+ throw new Error(
616
+ `PDF has ${pageCount} pages, which exceeds the maximum allowed page count of ${MAX_PDF_PAGES} pages.`
617
+ );
618
+ }
619
+
620
+ const contentHash = await calculateHash(file);
621
+ const filename = file instanceof File ? file.name : (file as { filename?: string }).filename;
622
+
623
+ if (!filename) {
624
+ throw new Error(
625
+ 'Invalid input: could not extract filename from the provided file or blob.'
626
+ );
627
+ }
628
+
629
+ if (/[^a-zA-Z0-9._ -]/.test(filename)) {
630
+ throw new Error(
631
+ 'Filename contains invalid characters. Only English letters, numbers, dots, hyphens, and underscores are allowed.'
632
+ );
633
+ }
634
+
635
+ const { presignedPost, pdfId } = (
636
+ await this.http.post<RequestPdfUploadResponse>('/api/v1/pdfSlides/request-upload', {
637
+ contentHash,
638
+ filename,
639
+ })
640
+ ).data;
641
+
642
+ const formData = new FormData();
643
+ Object.entries(presignedPost.fields).forEach(([key, value]) => {
644
+ formData.append(key, value);
645
+ });
646
+ formData.append('file', file);
647
+
648
+ try {
649
+ await axios.post(presignedPost.url, formData, {
650
+ headers: {
651
+ 'Content-Type': 'multipart/form-data',
652
+ },
653
+ });
654
+ } catch (uploadError) {
655
+ // S3 upload failed - clean up the MongoDB record created during request-upload
656
+ try {
657
+ await this.deleteSlideAnalysis(pdfId);
658
+ } catch (deleteError) {
659
+ console.error('Failed to clean up PDF record after upload failure:', deleteError);
660
+ }
661
+ throw uploadError;
662
+ }
663
+
664
+ /*
665
+ // replace const { presignedPost, pdfId } with const { presignedPost, objectKey, pdfId }
666
+ // Uncomment this block if you are testing locally without AWS EventBridge
667
+ await this.http.post('/api/v1/pdfSlides/test-event-bridge', {
668
+ s3Name: objectKey,
669
+ });
670
+ */
671
+
672
+ return pdfId;
673
+ } catch (e) {
674
+ if (axios.isAxiosError(e)) {
675
+ console.error('Error uploading PDF slides:', e.response?.data?.message || e.message);
676
+ } else {
677
+ console.error(
678
+ 'Error uploading PDF slides:',
679
+ e instanceof Error ? e.message : 'Unknown error'
680
+ );
681
+ }
682
+ throw e;
683
+ }
684
+ }
685
+
686
+ async getRecommendations(): Promise<RecommendationsResponseDto> {
687
+ try {
688
+ const res = await this.http.get<RecommendationsResponseDto>('/api/v1/recommendations');
689
+ return res.data;
690
+ } catch (e) {
691
+ if (axios.isAxiosError(e)) {
692
+ console.error('Error getting recommendations:', e.response?.data.message);
693
+ }
694
+ throw e;
695
+ }
696
+ }
697
+
698
+ async getSlidesAnalysis(queryParams: PdfSlidesAnalysisQueryDto): Promise<PdfSlidesDto[]> {
699
+ try {
700
+ const res = await this.http.get<PdfSlidesDto[]>('/api/v1/pdfSlides', {
701
+ params: queryParams,
702
+ });
703
+ return res.data;
704
+ } catch (e) {
705
+ if (axios.isAxiosError(e)) {
706
+ console.error('Error getting PDF slides analysis:', e.response?.data.message);
707
+ }
708
+ throw e;
709
+ }
710
+ }
711
+
712
+ async getSlideAnalysis(id: string): Promise<PdfSlideDto> {
713
+ try {
714
+ const res = await this.http.get<PdfSlideDto>(`/api/v1/pdfSlides/${id}`);
715
+ return res.data;
716
+ } catch (e) {
717
+ if (axios.isAxiosError(e)) {
718
+ console.error('Error getting PDF slide analysis by ID:', e.response?.data.message);
719
+ }
720
+ throw e;
721
+ }
722
+ }
723
+
724
+ async deleteSlideAnalysis(id: string): Promise<void> {
725
+ try {
726
+ await this.http.delete(`/api/v1/pdfSlides/${id}`);
727
+ } catch (e) {
728
+ if (axios.isAxiosError(e)) {
729
+ console.error('Error deleting PDF slide analysis:', e.response?.data.message);
730
+ }
731
+ throw e;
732
+ }
733
+ }
734
+
735
+ async checkPdfStatus(id: string): Promise<CheckPdfStatusResponse> {
736
+ try {
737
+ const res = await this.http.get<CheckPdfStatusResponse>(`/api/v1/pdfSlides/status/${id}`);
738
+ return res.data;
739
+ } catch (e) {
740
+ if (axios.isAxiosError(e)) {
741
+ console.error('Error checking PDF status:', e.response?.data.message);
742
+ }
743
+ throw e;
744
+ }
745
+ }
746
+
747
+ async getAssistantImages(): Promise<AssistantImageDto[]> {
748
+ try {
749
+ const res = await this.http.get<AssistantImageDto[]>('/api/v1/assistant-images');
750
+ return res.data;
751
+ } catch (e) {
752
+ if (axios.isAxiosError(e)) {
753
+ console.error('Error getting assistant images:', e.response?.data.message);
754
+ }
755
+ throw e;
756
+ }
757
+ }
758
+
759
+ /**
760
+ * Deletes a call and all associated data (messages, recommendations, recording).
761
+ * Only the owner of the call can delete it.
762
+ * @param callId - MongoDB ObjectId of the call
763
+ * @throws 404 if call not found
764
+ * @throws 403 if the caller is not the call owner
765
+ */
766
+ async deleteCall(callId: string): Promise<void> {
767
+ try {
768
+ await this.http.delete(`/api/v1/simulation/call/${callId}`);
769
+ } catch (e) {
770
+ if (axios.isAxiosError(e)) {
771
+ console.error('Error deleting call:', e.response?.data.message);
772
+ }
773
+ throw e;
774
+ }
775
+ }
776
+ }