@ctchealth/plato-sdk 0.0.7 → 0.0.9

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,265 @@
1
+ import axios, { AxiosInstance } from 'axios';
2
+ import {
3
+ CallCreateDto,
4
+ CallDTO,
5
+ CreateSimulationDto,
6
+ CreationPhase,
7
+ SimulationRecordingsDto,
8
+ SimulationRecordingsQueryDto,
9
+ } from './plato-intefaces';
10
+ import Vapi from '@vapi-ai/web';
11
+ import { Call } from '@vapi-ai/web/dist/api';
12
+
13
+ export interface ApiClientConfig {
14
+ baseUrl: string;
15
+ token?: string;
16
+ user?: string;
17
+ }
18
+
19
+ /**
20
+ * Event map for call events, providing strict typing for each event's payload.
21
+ */
22
+ export interface CallEventMap {
23
+ 'call-start': void;
24
+ 'call-end': void;
25
+ 'speech-start': void;
26
+ 'speech-end': void;
27
+ error: Error;
28
+ message: {
29
+ type: string;
30
+ role: string;
31
+ transcript?: string;
32
+ transcriptType: 'final' | 'partial';
33
+ toolCallList?: any[];
34
+ toolCalls?: any[];
35
+ [key: string]: any;
36
+ };
37
+ 'volume-level': number;
38
+ }
39
+
40
+ export type CallEventNames = keyof CallEventMap;
41
+
42
+ export type CallEventListener<K extends CallEventNames> = (payload: CallEventMap[K]) => void;
43
+
44
+ export class PlatoApiClient {
45
+ private http: AxiosInstance;
46
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-function-type
47
+ private eventListeners: Partial<Record<CallEventNames, Function[]>> = {};
48
+ private callControllerInstance?: Vapi;
49
+ private eventsAttached = false;
50
+ eventNames: CallEventNames[] = [
51
+ 'call-start',
52
+ 'call-end',
53
+ 'speech-start',
54
+ 'speech-end',
55
+ 'error',
56
+ 'message',
57
+ 'volume-level',
58
+ ];
59
+
60
+ constructor(private config: ApiClientConfig) {
61
+ if (!config.baseUrl) {
62
+ throw new Error('baseUrl is required');
63
+ }
64
+ if (!config.token) {
65
+ throw new Error('token is required');
66
+ }
67
+ if (!config.user) {
68
+ throw new Error('user is required');
69
+ }
70
+
71
+ if (config.baseUrl.endsWith('/')) {
72
+ config.baseUrl = config.baseUrl.slice(0, -1);
73
+ }
74
+
75
+ this.http = axios.create({
76
+ baseURL: config.baseUrl,
77
+ headers: {
78
+ 'x-api-key': config.token,
79
+ 'x-api-key-user': config.user,
80
+ },
81
+ });
82
+ }
83
+
84
+ /**
85
+ * Register a listener for a call event with strict typing.
86
+ * @param event Event name
87
+ * @param listener Listener function
88
+ */
89
+ private on<K extends CallEventNames>(event: K, listener: CallEventListener<K>): void {
90
+ if (!this.eventListeners[event]) {
91
+ this.eventListeners[event] = [];
92
+ }
93
+ this.eventListeners[event]!.push(listener);
94
+ if (this.callControllerInstance && !this.eventsAttached) {
95
+ this.attachEvents();
96
+ }
97
+ }
98
+
99
+ /**
100
+ * Remove a listener for a call event with strict typing.
101
+ * @param event Event name
102
+ * @param listener Listener function
103
+ */
104
+ private off<K extends CallEventNames>(event: K, listener: CallEventListener<K>): void {
105
+ if (!this.eventListeners[event]) return;
106
+ this.eventListeners[event] = this.eventListeners[event]!.filter(l => l !== listener);
107
+ }
108
+
109
+ /**
110
+ * Internal: Attach event listeners and propagate to registered listeners.
111
+ */
112
+ private attachEvents(): void {
113
+ if (this.eventsAttached || !this.callControllerInstance) return;
114
+ this.eventsAttached = true;
115
+ const vapi = this.callControllerInstance;
116
+
117
+ this.eventNames.forEach(event => {
118
+ vapi.on(event, (payload: any) => {
119
+ (this.eventListeners[event] || []).forEach(listener => listener(payload));
120
+ });
121
+ });
122
+ }
123
+
124
+ async createSimulation(createSimulationParams: CreateSimulationDto): Promise<{
125
+ simulationId: string;
126
+ phase: CreationPhase;
127
+ }> {
128
+ try {
129
+ const res = await this.http.post('/api/v1/simulation', {
130
+ ...createSimulationParams,
131
+ });
132
+ return {
133
+ simulationId: res.data.simulationId,
134
+ phase: res.data.phase,
135
+ };
136
+ } catch (e) {
137
+ if (axios.isAxiosError(e)) {
138
+ console.error('Error creating simulation:', e.response?.data.message);
139
+ }
140
+ throw e;
141
+ }
142
+ }
143
+
144
+ async checkSimulationStatus(simulationId: string): Promise<{
145
+ phase: CreationPhase;
146
+ }> {
147
+ const res = await this.http.get(`/api/v1/simulation/status/${simulationId}`);
148
+
149
+ return res.data;
150
+ }
151
+
152
+ async getCallDetails(callId: string): Promise<CallDTO> {
153
+ try {
154
+ const res = await this.http.get(`/api/v1/simulation/call/${callId}`);
155
+ return res.data as CallDTO;
156
+ } catch (e) {
157
+ if (axios.isAxiosError(e)) {
158
+ console.error('Error getting call details:', e.response?.data.message);
159
+ }
160
+ throw e;
161
+ }
162
+ }
163
+
164
+ async getCallRecordings(
165
+ queryParams: SimulationRecordingsQueryDto
166
+ ): Promise<SimulationRecordingsDto[]> {
167
+ try {
168
+ const res = await this.http.get(`/api/v1/simulation/call/recordings`, {
169
+ params: queryParams,
170
+ });
171
+ return res.data as SimulationRecordingsDto[];
172
+ } catch (e) {
173
+ if (axios.isAxiosError(e)) {
174
+ console.error('Error getting call recordings:', e.response?.data.message);
175
+ }
176
+ throw e;
177
+ }
178
+ }
179
+
180
+ async getCallRecording(callId: string): Promise<string> {
181
+ try {
182
+ const res = await this.http.get(`/api/v1/simulation/call/recordings/${callId}`);
183
+ return res.data as string;
184
+ } catch (e) {
185
+ if (axios.isAxiosError(e)) {
186
+ console.error('Error getting call recording:', e.response?.data.message);
187
+ }
188
+ throw e;
189
+ }
190
+ }
191
+
192
+ /**
193
+ * Remove all listeners for all call events.
194
+ */
195
+ private removeAllEventListeners(): void {
196
+ if (!this.callControllerInstance) return;
197
+ this.eventNames.forEach(event => {
198
+ (this.eventListeners[event] || []).forEach(listener => {
199
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
200
+ // @ts-expect-error
201
+ this.callControllerInstance?.off(event, listener);
202
+ });
203
+ this.eventListeners[event] = [];
204
+ });
205
+ this.eventsAttached = false;
206
+ }
207
+
208
+ async startCall(simulationId: string) {
209
+ this.callControllerInstance = new Vapi(
210
+ 'f07d17ec-d4e6-487d-a0b9-0539c01aecbb',
211
+ 'https://db41aykk1gw9e.cloudfront.net' // base url
212
+ );
213
+ if (!this.eventsAttached) {
214
+ this.attachEvents();
215
+ }
216
+ const { data } = await this.http.get(`/api/v1/simulation/${simulationId}`);
217
+ const assistantId = data as string;
218
+ const call: Call | null = await this.callControllerInstance.start(assistantId);
219
+
220
+ if (!call || !call.assistantId) {
221
+ throw new Error('Cannot start a call, please try again later');
222
+ }
223
+ try {
224
+ const apiCall = await this.createCall({
225
+ callId: call.id,
226
+ assistantId: call.assistantId,
227
+ });
228
+
229
+ // Return stopCall, callId, and event subscription methods with strict typing
230
+ return {
231
+ stopCall: () => {
232
+ this.callControllerInstance?.stop();
233
+ this.removeAllEventListeners();
234
+ },
235
+ callId: apiCall._id,
236
+ /**
237
+ * Subscribe to call events for this call with strict typing.
238
+ * @param event Event name
239
+ * @param listener Listener function
240
+ */
241
+ on: <K extends CallEventNames>(event: K, listener: CallEventListener<K>) =>
242
+ this.on(event, listener),
243
+ /**
244
+ * Unsubscribe from call events for this call with strict typing.
245
+ * @param event Event name
246
+ * @param listener Listener function
247
+ */
248
+ off: <K extends CallEventNames>(event: K, listener: CallEventListener<K>) =>
249
+ this.off(event, listener),
250
+ };
251
+ } catch (e) {
252
+ this.callControllerInstance?.stop();
253
+ this.removeAllEventListeners();
254
+ throw e;
255
+ }
256
+ }
257
+
258
+ private async createCall(payload: CallCreateDto) {
259
+ const response = await this.http.post('/api/v1/simulation/call', {
260
+ ...payload,
261
+ });
262
+
263
+ return response.data as CallDTO;
264
+ }
265
+ }
package/tsconfig.json ADDED
@@ -0,0 +1,22 @@
1
+ {
2
+ "extends": "../../tsconfig.base.json",
3
+ "compilerOptions": {
4
+ "module": "commonjs",
5
+ "forceConsistentCasingInFileNames": true,
6
+ "strict": true,
7
+ "noImplicitOverride": true,
8
+ "noImplicitReturns": true,
9
+ "noFallthroughCasesInSwitch": true,
10
+ "noPropertyAccessFromIndexSignature": true
11
+ },
12
+ "files": [],
13
+ "include": [],
14
+ "references": [
15
+ {
16
+ "path": "./tsconfig.lib.json"
17
+ },
18
+ {
19
+ "path": "./tsconfig.spec.json"
20
+ }
21
+ ]
22
+ }
@@ -0,0 +1,11 @@
1
+ {
2
+ "extends": "./tsconfig.json",
3
+ "compilerOptions": {
4
+ "outDir": "../../dist/out-tsc",
5
+ "declaration": true,
6
+ "types": ["node"],
7
+ "esModuleInterop": true
8
+ },
9
+ "include": ["src/**/*.ts"],
10
+ "exclude": ["jest.config.ts", "src/**/*.spec.ts", "src/**/*.test.ts"]
11
+ }
@@ -0,0 +1,10 @@
1
+ {
2
+ "extends": "./tsconfig.json",
3
+ "compilerOptions": {
4
+ "outDir": "../../dist/out-tsc",
5
+ "module": "commonjs",
6
+ "moduleResolution": "node10",
7
+ "types": ["jest", "node"]
8
+ },
9
+ "include": ["jest.config.ts", "src/**/*.test.ts", "src/**/*.spec.ts", "src/**/*.d.ts"]
10
+ }
package/src/index.js DELETED
@@ -1,5 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const tslib_1 = require("tslib");
4
- tslib_1.__exportStar(require("./lib/plato-sdk"), exports);
5
- //# sourceMappingURL=index.js.map
package/src/index.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../libs/plato-sdk/src/index.ts"],"names":[],"mappings":";;;AAAA,0DAAgC"}
@@ -1,186 +0,0 @@
1
- export declare enum YearOfExperience {
2
- '1-5' = "1-5 years",
3
- '6-10' = "6-10 years",
4
- '11-20' = "16-20 years",
5
- '20+' = "20+ years"
6
- }
7
- export declare enum PracticeType {
8
- Private = "Private Practice",
9
- Hospital = "Hospital",
10
- AcademicMedicalCenter = "Academic Medical Center",
11
- Clinic = "Clinic"
12
- }
13
- export declare enum SegmentType {
14
- Traditionalist = "The Traditionalist",
15
- Innovator = "The Innovator",
16
- PatientOrientedPhysician = "The Patient-Oriented Physician",
17
- FinanciallyDrivenPrescriber = "The Financially-Driven Prescriber",
18
- EvidencePurist = "The Evidence-Purist",
19
- CostConsciousPrescriber = "The Cost-Conscious Prescriber"
20
- }
21
- export declare enum AssistantVoiceGender {
22
- Male = "Male",
23
- Female = "Female"
24
- }
25
- export declare class PersonalityAndBehaviourDto {
26
- riskTolerance: number;
27
- researchOrientation: number;
28
- recognitionNeed: number;
29
- brandLoyalty: number;
30
- patientEmpathy: number;
31
- trainingDifficulty: number;
32
- friendliness: number;
33
- }
34
- export declare class ProfessionalProfileDto {
35
- practiceSettings: string;
36
- yearOfExperience: number;
37
- specialityAndDepartment: string;
38
- location: string;
39
- }
40
- export declare class ContextDto {
41
- subSpecialityOrTherapyFocus: string;
42
- typicalPatientMix: string;
43
- keyClinicalDrivers: string;
44
- }
45
- export declare class CharacterCreateDto {
46
- name: string;
47
- professionalProfile: ProfessionalProfileDto;
48
- segment: SegmentType;
49
- personalityAndBehaviour: PersonalityAndBehaviourDto;
50
- context: ContextDto;
51
- assistantGender: AssistantVoiceGender;
52
- }
53
- export declare class ProductConfig {
54
- name: string;
55
- description: string;
56
- }
57
- export declare class TrainingConfigurationDto {
58
- readonly trainingDifficulty: number;
59
- readonly communicationFormality: number;
60
- readonly friendlinessLevel: number;
61
- readonly subjectMatterExpertise: number;
62
- }
63
- export declare class CreateSimulationDto {
64
- persona: CharacterCreateDto;
65
- product: ProductConfig;
66
- presentation?: string;
67
- scenario: string;
68
- objectives?: string[];
69
- anticipatedObjections?: string[];
70
- trainingConfiguration: TrainingConfigurationDto;
71
- }
72
- export interface CallCreateDto {
73
- /**
74
- * Call ID obtained
75
- */
76
- callId: string;
77
- /**
78
- * Call Assistant ID
79
- */
80
- assistantId: string;
81
- }
82
- export interface CallDTO {
83
- /**
84
- * call ID
85
- */
86
- _id: string;
87
- /**
88
- * call ID obtained
89
- */
90
- callId: string;
91
- /**
92
- * call User ID
93
- */
94
- platoUserId: string;
95
- /**
96
- * call Assistant ID
97
- */
98
- assistantId: string;
99
- /**
100
- * call summary of the conversation
101
- */
102
- summary: string;
103
- /**
104
- * call transcript of the conversation
105
- */
106
- transcript: string;
107
- /**
108
- * call feedback provided by the user
109
- */
110
- feedback: string;
111
- /**
112
- * Success Evaluation returned by model
113
- */
114
- successEvaluation: boolean;
115
- /**
116
- * call Recording URL
117
- */
118
- recordingUrl: string;
119
- /**
120
- * Date and Time of the creation of the message
121
- */
122
- createdAt: Date;
123
- /**
124
- * Date and Time of the creation of the message
125
- */
126
- endedAt: Date;
127
- /**
128
- * Rating of the call given by the user
129
- */
130
- rating: number;
131
- /**
132
- * Main strenghts of the user conversation based on the analysis of the AI
133
- */
134
- strengths: Array<string>;
135
- /**
136
- * Main weak points of the user conversation based on the analysis of the AI
137
- */
138
- weaknesses: Array<string>;
139
- /**
140
- * Name of Metric for the AI feedback report
141
- */
142
- metric1: string;
143
- /**
144
- * Name of Metric for the AI feedback report
145
- */
146
- metric2: string;
147
- /**
148
- * Name of Metric for the AI feedback report
149
- */
150
- metric3: string;
151
- /**
152
- * AI feedback value for Metric 1
153
- */
154
- metric1Value: number;
155
- /**
156
- * AI feedback value for Metric 2
157
- */
158
- metric2Value: number;
159
- /**
160
- * AI feedback value for Metric 3
161
- */
162
- metric3Value: number;
163
- /**
164
- * AI feedback value for the call score
165
- */
166
- score?: number;
167
- /**
168
- * Defines if the calls will be consider for the memory feature
169
- */
170
- inMemory: boolean;
171
- }
172
- export declare enum CreationStatus {
173
- CREATING = "CREATING",
174
- READY = "READY",
175
- ERROR = "ERROR"
176
- }
177
- export declare enum CreationPhase {
178
- STARTING = "STARTING",
179
- CORE = "CORE",
180
- BOUNDARIES = "BOUNDARIES",
181
- SPEECH_AND_THOUGHT = "SPEECH_AND_THOUGHT",
182
- CONVERSATION_EVOLUTION = "CONVERSATION_EVOLUTION",
183
- MEMORY = "MEMORY",
184
- FINISHED = "FINISHED",
185
- ERROR = "ERROR"
186
- }
@@ -1,103 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.CreationPhase = exports.CreationStatus = exports.CreateSimulationDto = exports.TrainingConfigurationDto = exports.ProductConfig = exports.CharacterCreateDto = exports.ContextDto = exports.ProfessionalProfileDto = exports.PersonalityAndBehaviourDto = exports.AssistantVoiceGender = exports.SegmentType = exports.PracticeType = exports.YearOfExperience = void 0;
4
- var YearOfExperience;
5
- (function (YearOfExperience) {
6
- YearOfExperience["1-5"] = "1-5 years";
7
- YearOfExperience["6-10"] = "6-10 years";
8
- YearOfExperience["11-20"] = "16-20 years";
9
- YearOfExperience["20+"] = "20+ years";
10
- })(YearOfExperience || (exports.YearOfExperience = YearOfExperience = {}));
11
- var PracticeType;
12
- (function (PracticeType) {
13
- PracticeType["Private"] = "Private Practice";
14
- PracticeType["Hospital"] = "Hospital";
15
- PracticeType["AcademicMedicalCenter"] = "Academic Medical Center";
16
- PracticeType["Clinic"] = "Clinic";
17
- })(PracticeType || (exports.PracticeType = PracticeType = {}));
18
- var SegmentType;
19
- (function (SegmentType) {
20
- SegmentType["Traditionalist"] = "The Traditionalist";
21
- SegmentType["Innovator"] = "The Innovator";
22
- SegmentType["PatientOrientedPhysician"] = "The Patient-Oriented Physician";
23
- SegmentType["FinanciallyDrivenPrescriber"] = "The Financially-Driven Prescriber";
24
- SegmentType["EvidencePurist"] = "The Evidence-Purist";
25
- SegmentType["CostConsciousPrescriber"] = "The Cost-Conscious Prescriber";
26
- })(SegmentType || (exports.SegmentType = SegmentType = {}));
27
- var AssistantVoiceGender;
28
- (function (AssistantVoiceGender) {
29
- AssistantVoiceGender["Male"] = "Male";
30
- AssistantVoiceGender["Female"] = "Female";
31
- })(AssistantVoiceGender || (exports.AssistantVoiceGender = AssistantVoiceGender = {}));
32
- class PersonalityAndBehaviourDto {
33
- riskTolerance;
34
- researchOrientation;
35
- recognitionNeed;
36
- brandLoyalty;
37
- patientEmpathy;
38
- trainingDifficulty;
39
- friendliness;
40
- }
41
- exports.PersonalityAndBehaviourDto = PersonalityAndBehaviourDto;
42
- class ProfessionalProfileDto {
43
- practiceSettings;
44
- yearOfExperience;
45
- specialityAndDepartment;
46
- location;
47
- }
48
- exports.ProfessionalProfileDto = ProfessionalProfileDto;
49
- class ContextDto {
50
- subSpecialityOrTherapyFocus;
51
- typicalPatientMix;
52
- keyClinicalDrivers;
53
- }
54
- exports.ContextDto = ContextDto;
55
- class CharacterCreateDto {
56
- name;
57
- professionalProfile;
58
- segment;
59
- personalityAndBehaviour;
60
- context;
61
- assistantGender;
62
- }
63
- exports.CharacterCreateDto = CharacterCreateDto;
64
- class ProductConfig {
65
- name;
66
- description;
67
- }
68
- exports.ProductConfig = ProductConfig;
69
- class TrainingConfigurationDto {
70
- trainingDifficulty;
71
- communicationFormality;
72
- friendlinessLevel;
73
- subjectMatterExpertise;
74
- }
75
- exports.TrainingConfigurationDto = TrainingConfigurationDto;
76
- class CreateSimulationDto {
77
- persona;
78
- product;
79
- presentation;
80
- scenario;
81
- objectives;
82
- anticipatedObjections;
83
- trainingConfiguration;
84
- }
85
- exports.CreateSimulationDto = CreateSimulationDto;
86
- var CreationStatus;
87
- (function (CreationStatus) {
88
- CreationStatus["CREATING"] = "CREATING";
89
- CreationStatus["READY"] = "READY";
90
- CreationStatus["ERROR"] = "ERROR";
91
- })(CreationStatus || (exports.CreationStatus = CreationStatus = {}));
92
- var CreationPhase;
93
- (function (CreationPhase) {
94
- CreationPhase["STARTING"] = "STARTING";
95
- CreationPhase["CORE"] = "CORE";
96
- CreationPhase["BOUNDARIES"] = "BOUNDARIES";
97
- CreationPhase["SPEECH_AND_THOUGHT"] = "SPEECH_AND_THOUGHT";
98
- CreationPhase["CONVERSATION_EVOLUTION"] = "CONVERSATION_EVOLUTION";
99
- CreationPhase["MEMORY"] = "MEMORY";
100
- CreationPhase["FINISHED"] = "FINISHED";
101
- CreationPhase["ERROR"] = "ERROR";
102
- })(CreationPhase || (exports.CreationPhase = CreationPhase = {}));
103
- //# sourceMappingURL=plato-intefaces.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"plato-intefaces.js","sourceRoot":"","sources":["../../../../../libs/plato-sdk/src/lib/plato-intefaces.ts"],"names":[],"mappings":";;;AAAA,IAAY,gBAKX;AALD,WAAY,gBAAgB;IAC1B,qCAAmB,CAAA;IACnB,uCAAqB,CAAA;IACrB,yCAAuB,CAAA;IACvB,qCAAmB,CAAA;AACrB,CAAC,EALW,gBAAgB,gCAAhB,gBAAgB,QAK3B;AAGD,IAAY,YAKX;AALD,WAAY,YAAY;IACtB,4CAA4B,CAAA;IAC5B,qCAAqB,CAAA;IACrB,iEAAiD,CAAA;IACjD,iCAAiB,CAAA;AACnB,CAAC,EALW,YAAY,4BAAZ,YAAY,QAKvB;AACD,IAAY,WAOX;AAPD,WAAY,WAAW;IACrB,oDAAqC,CAAA;IACrC,0CAA2B,CAAA;IAC3B,0EAA2D,CAAA;IAC3D,gFAAiE,CAAA;IACjE,qDAAsC,CAAA;IACtC,wEAAyD,CAAA;AAC3D,CAAC,EAPW,WAAW,2BAAX,WAAW,QAOtB;AAED,IAAY,oBAGX;AAHD,WAAY,oBAAoB;IAC9B,qCAAa,CAAA;IACb,yCAAiB,CAAA;AACnB,CAAC,EAHW,oBAAoB,oCAApB,oBAAoB,QAG/B;AAED,MAAa,0BAA0B;IACrC,aAAa,CAAU;IACvB,mBAAmB,CAAU;IAC7B,eAAe,CAAU;IACzB,YAAY,CAAU;IACtB,cAAc,CAAU;IACxB,kBAAkB,CAAU;IAC5B,YAAY,CAAU;CACvB;AARD,gEAQC;AAED,MAAa,sBAAsB;IACjC,gBAAgB,CAAU;IAC1B,gBAAgB,CAAU;IAC1B,uBAAuB,CAAU;IACjC,QAAQ,CAAU;CACnB;AALD,wDAKC;AAED,MAAa,UAAU;IACrB,2BAA2B,CAAU;IACrC,iBAAiB,CAAU;IAC3B,kBAAkB,CAAU;CAC7B;AAJD,gCAIC;AAED,MAAa,kBAAkB;IAC7B,IAAI,CAAU;IACd,mBAAmB,CAA0B;IAC7C,OAAO,CAAgB;IACvB,uBAAuB,CAA8B;IACrD,OAAO,CAAc;IACrB,eAAe,CAAyB;CACzC;AAPD,gDAOC;AAED,MAAa,aAAa;IACxB,IAAI,CAAU;IACd,WAAW,CAAU;CACtB;AAHD,sCAGC;AAED,MAAa,wBAAwB;IAC1B,kBAAkB,CAAU;IAC5B,sBAAsB,CAAU;IAChC,iBAAiB,CAAU;IAC3B,sBAAsB,CAAU;CAC1C;AALD,4DAKC;AAED,MAAa,mBAAmB;IAC9B,OAAO,CAAsB;IAC7B,OAAO,CAAiB;IACxB,YAAY,CAAU;IACtB,QAAQ,CAAU;IAClB,UAAU,CAAY;IACtB,qBAAqB,CAAY;IACjC,qBAAqB,CAA4B;CAClD;AARD,kDAQC;AA2GD,IAAY,cAIX;AAJD,WAAY,cAAc;IACxB,uCAAqB,CAAA;IACrB,iCAAe,CAAA;IACf,iCAAe,CAAA;AACjB,CAAC,EAJW,cAAc,8BAAd,cAAc,QAIzB;AACD,IAAY,aASX;AATD,WAAY,aAAa;IACvB,sCAAqB,CAAA;IACrB,8BAAa,CAAA;IACb,0CAAyB,CAAA;IACzB,0DAAyC,CAAA;IACzC,kEAAiD,CAAA;IACjD,kCAAiB,CAAA;IACjB,sCAAqB,CAAA;IACrB,gCAAe,CAAA;AACjB,CAAC,EATW,aAAa,6BAAb,aAAa,QASxB"}
@@ -1,82 +0,0 @@
1
- import { CallDTO, CreateSimulationDto, CreationPhase } from './plato-intefaces';
2
- export interface ApiClientConfig {
3
- baseUrl: string;
4
- token?: string;
5
- user?: string;
6
- }
7
- /**
8
- * Event map for call events, providing strict typing for each event's payload.
9
- */
10
- export interface CallEventMap {
11
- 'call-start': void;
12
- 'call-end': void;
13
- 'speech-start': void;
14
- 'speech-end': void;
15
- 'error': Error;
16
- 'message': {
17
- type: string;
18
- role: string;
19
- transcript?: string;
20
- transcriptType: 'final' | 'partial';
21
- toolCallList?: any[];
22
- toolCalls?: any[];
23
- [key: string]: any;
24
- };
25
- 'volume-level': number;
26
- }
27
- export type CallEventNames = keyof CallEventMap;
28
- export type CallEventListener<K extends CallEventNames> = (payload: CallEventMap[K]) => void;
29
- export declare class PlatoApiClient {
30
- private config;
31
- private http;
32
- private eventListeners;
33
- private callControllerInstance?;
34
- private eventsAttached;
35
- eventNames: CallEventNames[];
36
- constructor(config: ApiClientConfig);
37
- /**
38
- * Register a listener for a call event with strict typing.
39
- * @param event Event name
40
- * @param listener Listener function
41
- */
42
- private on;
43
- /**
44
- * Remove a listener for a call event with strict typing.
45
- * @param event Event name
46
- * @param listener Listener function
47
- */
48
- private off;
49
- /**
50
- * Internal: Attach event listeners and propagate to registered listeners.
51
- */
52
- private attachEvents;
53
- createSimulation(createSimulationParams: CreateSimulationDto): Promise<{
54
- simulationId: string;
55
- phase: CreationPhase;
56
- }>;
57
- checkSimulationStatus(simulationId: string): Promise<{
58
- phase: CreationPhase;
59
- }>;
60
- getCallDetails(callId: string): Promise<CallDTO>;
61
- /**
62
- * Remove all listeners for all call events.
63
- */
64
- private removeAllEventListeners;
65
- startCall(simulationId: string): Promise<{
66
- stopCall: () => void;
67
- callId: string;
68
- /**
69
- * Subscribe to call events for this call with strict typing.
70
- * @param event Event name
71
- * @param listener Listener function
72
- */
73
- on: <K extends CallEventNames>(event: K, listener: CallEventListener<K>) => void;
74
- /**
75
- * Unsubscribe from call events for this call with strict typing.
76
- * @param event Event name
77
- * @param listener Listener function
78
- */
79
- off: <K extends CallEventNames>(event: K, listener: CallEventListener<K>) => void;
80
- }>;
81
- private createCall;
82
- }