@ctchealth/plato-sdk 0.0.17 → 0.0.18
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 +3 -3
- package/package.json +4 -3
- package/src/index.js +18 -0
- package/src/index.js.map +1 -0
- package/src/lib/{constants.ts → constants.d.ts} +3 -3
- package/src/lib/constants.js +20 -0
- package/src/lib/constants.js.map +1 -0
- package/src/lib/plato-intefaces.d.ts +393 -0
- package/src/lib/plato-intefaces.js +173 -0
- package/src/lib/plato-intefaces.js.map +1 -0
- package/src/lib/plato-sdk.d.ts +193 -0
- package/src/lib/plato-sdk.js +663 -0
- package/src/lib/plato-sdk.js.map +1 -0
- package/src/lib/utils.d.ts +24 -0
- package/src/lib/utils.js +70 -0
- package/src/lib/utils.js.map +1 -0
- package/eslint.config.cjs +0 -121
- package/jest.config.ts +0 -10
- package/project.json +0 -24
- package/src/lib/plato-intefaces.ts +0 -431
- package/src/lib/plato-sdk.ts +0 -789
- package/src/lib/utils.ts +0 -72
- package/tsconfig.json +0 -22
- package/tsconfig.lib.json +0 -11
- package/tsconfig.spec.json +0 -10
- /package/src/{index.ts → index.d.ts} +0 -0
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
import { CallDTO, CreateSimulationDto, CreationPhase, SimulationRecordingsDto, SimulationRecordingsQueryDto, SimulationDetailsDto, RecommendationsResponseDto, PdfSlidesDto, PdfSlideDto, PdfSlidesAnalysisQueryDto, CheckPdfStatusResponse, AssistantImageDto } from './plato-intefaces';
|
|
2
|
+
export interface ApiClientConfig {
|
|
3
|
+
baseUrl: string;
|
|
4
|
+
token?: string;
|
|
5
|
+
user?: string;
|
|
6
|
+
jwtToken?: string;
|
|
7
|
+
}
|
|
8
|
+
export interface ToolCall {
|
|
9
|
+
function: {
|
|
10
|
+
name: string;
|
|
11
|
+
arguments: {
|
|
12
|
+
slideNumber?: number;
|
|
13
|
+
progressObjectiveNumber?: number;
|
|
14
|
+
[key: string]: unknown;
|
|
15
|
+
};
|
|
16
|
+
};
|
|
17
|
+
id: string;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Event map for call events, providing strict typing for each event's payload.
|
|
21
|
+
* There are no inputs for the events and all of them return void.
|
|
22
|
+
*/
|
|
23
|
+
export interface CallEventMap {
|
|
24
|
+
'call-start': undefined;
|
|
25
|
+
'call-end': undefined;
|
|
26
|
+
'speech-start': undefined;
|
|
27
|
+
'speech-end': undefined;
|
|
28
|
+
error: Error;
|
|
29
|
+
message: {
|
|
30
|
+
type: string;
|
|
31
|
+
role: string;
|
|
32
|
+
transcript?: string;
|
|
33
|
+
transcriptType: 'final' | 'partial';
|
|
34
|
+
toolCallList?: ToolCall[];
|
|
35
|
+
toolCalls?: ToolCall[];
|
|
36
|
+
[key: string]: unknown;
|
|
37
|
+
};
|
|
38
|
+
'volume-level': number;
|
|
39
|
+
'call-details-ready': CallDTO;
|
|
40
|
+
}
|
|
41
|
+
export type CallEventNames = keyof CallEventMap;
|
|
42
|
+
export type CallEventListener<K extends CallEventNames> = (payload: CallEventMap[K]) => void;
|
|
43
|
+
export declare class PlatoApiClient {
|
|
44
|
+
private config;
|
|
45
|
+
private static readonly ACTIVE_CALL_STORAGE_KEY;
|
|
46
|
+
private http;
|
|
47
|
+
private eventListeners;
|
|
48
|
+
private callControllerInstance?;
|
|
49
|
+
private eventsAttached;
|
|
50
|
+
private currentCallId?;
|
|
51
|
+
private vapiEventNames;
|
|
52
|
+
eventNames: CallEventNames[];
|
|
53
|
+
constructor(config: ApiClientConfig);
|
|
54
|
+
/**
|
|
55
|
+
* Update the JWT token for all subsequent requests.
|
|
56
|
+
* Useful when the token is refreshed or when switching user context.
|
|
57
|
+
*/
|
|
58
|
+
setJwtToken(jwtToken: string): void;
|
|
59
|
+
/**
|
|
60
|
+
* Remove the JWT token from subsequent requests.
|
|
61
|
+
*/
|
|
62
|
+
clearJwtToken(): void;
|
|
63
|
+
/**
|
|
64
|
+
* Register a listener for a call event with strict typing.
|
|
65
|
+
* @param event Event name
|
|
66
|
+
* @param listener Listener function
|
|
67
|
+
*/
|
|
68
|
+
private on;
|
|
69
|
+
/**
|
|
70
|
+
* Remove a listener for a call event with strict typing.
|
|
71
|
+
* @param event Event name
|
|
72
|
+
* @param listener Listener function
|
|
73
|
+
*/
|
|
74
|
+
private off;
|
|
75
|
+
/**
|
|
76
|
+
* Internal: Attach event listeners and propagate to registered listeners.
|
|
77
|
+
*/
|
|
78
|
+
private attachEvents;
|
|
79
|
+
/**
|
|
80
|
+
* Internal: Emit SDK-specific events that are not part of Vapi.
|
|
81
|
+
*/
|
|
82
|
+
private emit;
|
|
83
|
+
/**
|
|
84
|
+
* Store active call state in localStorage for recovery purposes.
|
|
85
|
+
* @private
|
|
86
|
+
*/
|
|
87
|
+
private storeCallState;
|
|
88
|
+
/**
|
|
89
|
+
* Retrieve active call state from localStorage.
|
|
90
|
+
* Validates the stored data and clears it if invalid.
|
|
91
|
+
* @private
|
|
92
|
+
* @returns The stored call state or null if not found or invalid
|
|
93
|
+
*/
|
|
94
|
+
private getStoredCallState;
|
|
95
|
+
/**
|
|
96
|
+
* Clear active call state from localStorage.
|
|
97
|
+
* @private
|
|
98
|
+
*/
|
|
99
|
+
private clearCallState;
|
|
100
|
+
/**
|
|
101
|
+
* Check if a stored call is considered abandoned based on age.
|
|
102
|
+
* Calls older than 5 minutes are considered abandoned.
|
|
103
|
+
* @private
|
|
104
|
+
* @param state The call state to check
|
|
105
|
+
* @returns true if the call is abandoned, false otherwise
|
|
106
|
+
*/
|
|
107
|
+
private isCallAbandoned;
|
|
108
|
+
/**
|
|
109
|
+
* Recover and clean up any abandoned calls from previous sessions.
|
|
110
|
+
*
|
|
111
|
+
* This method should be called during application initialization,
|
|
112
|
+
* typically in ngOnInit() or useEffect(). It detects calls that were
|
|
113
|
+
* active when the page was last refreshed and notifies the backend
|
|
114
|
+
* to process them if they're older than 5 minutes.
|
|
115
|
+
*
|
|
116
|
+
* The backend endpoint is idempotent, so calling this method multiple
|
|
117
|
+
* times for the same call is safe.
|
|
118
|
+
*
|
|
119
|
+
* @returns Promise<boolean> - true if an abandoned call was recovered and processed
|
|
120
|
+
*
|
|
121
|
+
* @example
|
|
122
|
+
* // In Angular component
|
|
123
|
+
* async ngOnInit(): Promise<void> {
|
|
124
|
+
* const recovered = await this.platoClient.recoverAbandonedCall();
|
|
125
|
+
* if (recovered) {
|
|
126
|
+
* console.log('Recovered abandoned call from previous session');
|
|
127
|
+
* }
|
|
128
|
+
* }
|
|
129
|
+
*
|
|
130
|
+
* @example
|
|
131
|
+
* // In React component
|
|
132
|
+
* useEffect(() => {
|
|
133
|
+
* platoClient.recoverAbandonedCall()
|
|
134
|
+
* .then(recovered => {
|
|
135
|
+
* if (recovered) {
|
|
136
|
+
* console.log('Recovered abandoned call');
|
|
137
|
+
* }
|
|
138
|
+
* })
|
|
139
|
+
* .catch(console.error);
|
|
140
|
+
* }, []);
|
|
141
|
+
*/
|
|
142
|
+
recoverAbandonedCall(): Promise<boolean>;
|
|
143
|
+
createSimulation(createSimulationParams: CreateSimulationDto): Promise<{
|
|
144
|
+
simulationId: string;
|
|
145
|
+
phase: CreationPhase;
|
|
146
|
+
}>;
|
|
147
|
+
checkSimulationStatus(simulationId: string): Promise<{
|
|
148
|
+
phase: CreationPhase;
|
|
149
|
+
}>;
|
|
150
|
+
getUserSimulations(): Promise<Array<{
|
|
151
|
+
simulationId: string;
|
|
152
|
+
phase: CreationPhase;
|
|
153
|
+
}>>;
|
|
154
|
+
getSimulationDetails(simulationId: string): Promise<SimulationDetailsDto>;
|
|
155
|
+
/**
|
|
156
|
+
* Deletes a simulation (assistant) from the server and Vapi.
|
|
157
|
+
* @param simulationId - MongoDB ObjectId of the simulation
|
|
158
|
+
* @throws 404 if simulation not found
|
|
159
|
+
*/
|
|
160
|
+
deleteSimulation(simulationId: string): Promise<void>;
|
|
161
|
+
getCallDetails(callId: string): Promise<CallDTO>;
|
|
162
|
+
getCallRecordings(queryParams: SimulationRecordingsQueryDto): Promise<SimulationRecordingsDto[]>;
|
|
163
|
+
getCallRecording(callId: string): Promise<string>;
|
|
164
|
+
/**
|
|
165
|
+
* Remove all listeners for all call events.
|
|
166
|
+
*/
|
|
167
|
+
private removeAllEventListeners;
|
|
168
|
+
startCall(simulationId: string): Promise<{
|
|
169
|
+
stopCall: () => void;
|
|
170
|
+
callId: string;
|
|
171
|
+
/**
|
|
172
|
+
* Subscribe to call events for this call with strict typing.
|
|
173
|
+
* @param event Event name
|
|
174
|
+
* @param listener Listener function
|
|
175
|
+
*/
|
|
176
|
+
on: <K extends CallEventNames>(event: K, listener: CallEventListener<K>) => void;
|
|
177
|
+
/**
|
|
178
|
+
* Unsubscribe from call events for this call with strict typing.
|
|
179
|
+
* @param event Event name
|
|
180
|
+
* @param listener Listener function
|
|
181
|
+
*/
|
|
182
|
+
off: <K extends CallEventNames>(event: K, listener: CallEventListener<K>) => void;
|
|
183
|
+
}>;
|
|
184
|
+
private onCallEnded;
|
|
185
|
+
private createCall;
|
|
186
|
+
uploadPdfSlides(file: File | Blob): Promise<string>;
|
|
187
|
+
getRecommendations(): Promise<RecommendationsResponseDto>;
|
|
188
|
+
getSlidesAnalysis(queryParams: PdfSlidesAnalysisQueryDto): Promise<PdfSlidesDto[]>;
|
|
189
|
+
getSlideAnalysis(id: string): Promise<PdfSlideDto>;
|
|
190
|
+
deleteSlideAnalysis(id: string): Promise<void>;
|
|
191
|
+
checkPdfStatus(id: string): Promise<CheckPdfStatusResponse>;
|
|
192
|
+
getAssistantImages(): Promise<AssistantImageDto[]>;
|
|
193
|
+
}
|