retell-sdk 2.2.4 → 2.2.6
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/example.js +15 -4
- package/example.js.map +1 -1
- package/models/components/agent.d.ts +3 -205
- package/models/components/agent.d.ts.map +1 -1
- package/models/components/agent.js +5 -221
- package/models/components/agent.js.map +1 -1
- package/models/components/calldetail.d.ts +33 -22
- package/models/components/calldetail.d.ts.map +1 -1
- package/models/components/calldetail.js +32 -31
- package/models/components/calldetail.js.map +1 -1
- package/models/components/index.d.ts +0 -3
- package/models/components/index.d.ts.map +1 -1
- package/models/components/index.js +0 -3
- package/models/components/index.js.map +1 -1
- package/models/errors/index.d.ts +1 -6
- package/models/errors/index.d.ts.map +1 -1
- package/models/errors/index.js +1 -6
- package/models/errors/index.js.map +1 -1
- package/models/errors/registercall.d.ts +218 -0
- package/models/errors/registercall.d.ts.map +1 -0
- package/models/errors/registercall.js +386 -0
- package/models/errors/registercall.js.map +1 -0
- package/models/operations/createagent.d.ts +3 -16
- package/models/operations/createagent.d.ts.map +1 -1
- package/models/operations/createagent.js +4 -22
- package/models/operations/createagent.js.map +1 -1
- package/models/operations/getcall.d.ts +1 -1
- package/models/operations/index.d.ts +1 -7
- package/models/operations/index.d.ts.map +1 -1
- package/models/operations/index.js +1 -7
- package/models/operations/index.js.map +1 -1
- package/models/operations/listcalls.d.ts +1 -7
- package/models/operations/listcalls.d.ts.map +1 -1
- package/models/operations/listcalls.js +0 -4
- package/models/operations/listcalls.js.map +1 -1
- package/models/operations/registercall.d.ts +74 -0
- package/models/operations/registercall.d.ts.map +1 -0
- package/models/operations/registercall.js +104 -0
- package/models/operations/registercall.js.map +1 -0
- package/models/operations/updateagent.d.ts +3 -16
- package/models/operations/updateagent.d.ts.map +1 -1
- package/models/operations/updateagent.js +7 -25
- package/models/operations/updateagent.js.map +1 -1
- package/package.json +1 -1
- package/sdk/audioWsClient.d.ts +10 -0
- package/sdk/audioWsClient.d.ts.map +1 -0
- package/sdk/audioWsClient.js +60 -0
- package/sdk/audioWsClient.js.map +1 -0
- package/sdk/index.d.ts +1 -1
- package/sdk/index.d.ts.map +1 -1
- package/sdk/index.js +1 -1
- package/sdk/index.js.map +1 -1
- package/sdk/sdk.d.ts +1 -23
- package/sdk/sdk.d.ts.map +1 -1
- package/sdk/sdk.js +11 -437
- package/sdk/sdk.js.map +1 -1
- package/src/example.ts +18 -4
- package/src/models/components/agent.ts +8 -460
- package/src/models/components/calldetail.ts +47 -42
- package/src/models/components/index.ts +0 -3
- package/src/models/errors/index.ts +1 -6
- package/src/models/errors/{createphonecall.ts → registercall.ts} +60 -60
- package/src/models/operations/createagent.ts +8 -50
- package/src/models/operations/getcall.ts +1 -1
- package/src/models/operations/index.ts +1 -7
- package/src/models/operations/listcalls.ts +1 -11
- package/src/models/operations/registercall.ts +167 -0
- package/src/models/operations/updateagent.ts +11 -58
- package/src/sdk/audioWsClient.ts +63 -0
- package/src/sdk/index.ts +1 -1
- package/src/sdk/sdk.ts +13 -526
- package/src/models/components/agentpromptparams.ts +0 -61
- package/src/models/components/callphonenumber.ts +0 -64
- package/src/models/components/phonenumber.ts +0 -84
- package/src/models/errors/createphonenumber.ts +0 -552
- package/src/models/errors/deletephonenumber.ts +0 -442
- package/src/models/errors/getphonenumber.ts +0 -442
- package/src/models/errors/listphonenumbers.ts +0 -332
- package/src/models/errors/updatephoneagent.ts +0 -442
- package/src/models/operations/createphonecall.ts +0 -353
- package/src/models/operations/createphonenumber.ts +0 -144
- package/src/models/operations/createwebcall.ts +0 -16
- package/src/models/operations/deletephonenumber.ts +0 -119
- package/src/models/operations/getphonenumber.ts +0 -134
- package/src/models/operations/listphonenumbers.ts +0 -88
- package/src/models/operations/updatephoneagent.ts +0 -187
- package/src/sdk/liveClient.ts +0 -113
|
@@ -1,134 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Code generated by Speakeasy (https://speakeasyapi.dev). DO NOT EDIT.
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
import * as components from "../../models/components";
|
|
6
|
-
import { z } from "zod";
|
|
7
|
-
|
|
8
|
-
export type GetPhoneNumberRequest = {
|
|
9
|
-
/**
|
|
10
|
-
* Phone number in E.164 format to retreive more information.
|
|
11
|
-
*/
|
|
12
|
-
phoneNumber: string;
|
|
13
|
-
};
|
|
14
|
-
|
|
15
|
-
export type GetPhoneNumberResponse = {
|
|
16
|
-
/**
|
|
17
|
-
* HTTP response content type for this operation
|
|
18
|
-
*/
|
|
19
|
-
contentType: string;
|
|
20
|
-
/**
|
|
21
|
-
* Successfully retrieved a phone number.
|
|
22
|
-
*/
|
|
23
|
-
phoneNumber?: components.PhoneNumber | undefined;
|
|
24
|
-
/**
|
|
25
|
-
* HTTP response status code for this operation
|
|
26
|
-
*/
|
|
27
|
-
statusCode: number;
|
|
28
|
-
/**
|
|
29
|
-
* Raw HTTP response; suitable for custom response parsing
|
|
30
|
-
*/
|
|
31
|
-
rawResponse: Response;
|
|
32
|
-
};
|
|
33
|
-
|
|
34
|
-
/** @internal */
|
|
35
|
-
export namespace GetPhoneNumberRequest$ {
|
|
36
|
-
export type Inbound = {
|
|
37
|
-
phone_number: string;
|
|
38
|
-
};
|
|
39
|
-
|
|
40
|
-
export const inboundSchema: z.ZodType<
|
|
41
|
-
GetPhoneNumberRequest,
|
|
42
|
-
z.ZodTypeDef,
|
|
43
|
-
Inbound
|
|
44
|
-
> = z
|
|
45
|
-
.object({
|
|
46
|
-
phone_number: z.string(),
|
|
47
|
-
})
|
|
48
|
-
.transform((v) => {
|
|
49
|
-
return {
|
|
50
|
-
phoneNumber: v.phone_number,
|
|
51
|
-
};
|
|
52
|
-
});
|
|
53
|
-
|
|
54
|
-
export type Outbound = {
|
|
55
|
-
phone_number: string;
|
|
56
|
-
};
|
|
57
|
-
|
|
58
|
-
export const outboundSchema: z.ZodType<
|
|
59
|
-
Outbound,
|
|
60
|
-
z.ZodTypeDef,
|
|
61
|
-
GetPhoneNumberRequest
|
|
62
|
-
> = z
|
|
63
|
-
.object({
|
|
64
|
-
phoneNumber: z.string(),
|
|
65
|
-
})
|
|
66
|
-
.transform((v) => {
|
|
67
|
-
return {
|
|
68
|
-
phone_number: v.phoneNumber,
|
|
69
|
-
};
|
|
70
|
-
});
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
/** @internal */
|
|
74
|
-
export namespace GetPhoneNumberResponse$ {
|
|
75
|
-
export type Inbound = {
|
|
76
|
-
ContentType: string;
|
|
77
|
-
PhoneNumber?: components.PhoneNumber$.Inbound | undefined;
|
|
78
|
-
StatusCode: number;
|
|
79
|
-
RawResponse: Response;
|
|
80
|
-
};
|
|
81
|
-
|
|
82
|
-
export const inboundSchema: z.ZodType<
|
|
83
|
-
GetPhoneNumberResponse,
|
|
84
|
-
z.ZodTypeDef,
|
|
85
|
-
Inbound
|
|
86
|
-
> = z
|
|
87
|
-
.object({
|
|
88
|
-
ContentType: z.string(),
|
|
89
|
-
PhoneNumber: components.PhoneNumber$.inboundSchema.optional(),
|
|
90
|
-
StatusCode: z.number().int(),
|
|
91
|
-
RawResponse: z.instanceof(Response),
|
|
92
|
-
})
|
|
93
|
-
.transform((v) => {
|
|
94
|
-
return {
|
|
95
|
-
contentType: v.ContentType,
|
|
96
|
-
...(v.PhoneNumber === undefined
|
|
97
|
-
? null
|
|
98
|
-
: { phoneNumber: v.PhoneNumber }),
|
|
99
|
-
statusCode: v.StatusCode,
|
|
100
|
-
rawResponse: v.RawResponse,
|
|
101
|
-
};
|
|
102
|
-
});
|
|
103
|
-
|
|
104
|
-
export type Outbound = {
|
|
105
|
-
ContentType: string;
|
|
106
|
-
PhoneNumber?: components.PhoneNumber$.Outbound | undefined;
|
|
107
|
-
StatusCode: number;
|
|
108
|
-
RawResponse: never;
|
|
109
|
-
};
|
|
110
|
-
|
|
111
|
-
export const outboundSchema: z.ZodType<
|
|
112
|
-
Outbound,
|
|
113
|
-
z.ZodTypeDef,
|
|
114
|
-
GetPhoneNumberResponse
|
|
115
|
-
> = z
|
|
116
|
-
.object({
|
|
117
|
-
contentType: z.string(),
|
|
118
|
-
phoneNumber: components.PhoneNumber$.outboundSchema.optional(),
|
|
119
|
-
statusCode: z.number().int(),
|
|
120
|
-
rawResponse: z.instanceof(Response).transform(() => {
|
|
121
|
-
throw new Error("Response cannot be serialized");
|
|
122
|
-
}),
|
|
123
|
-
})
|
|
124
|
-
.transform((v) => {
|
|
125
|
-
return {
|
|
126
|
-
ContentType: v.contentType,
|
|
127
|
-
...(v.phoneNumber === undefined
|
|
128
|
-
? null
|
|
129
|
-
: { PhoneNumber: v.phoneNumber }),
|
|
130
|
-
StatusCode: v.statusCode,
|
|
131
|
-
RawResponse: v.rawResponse,
|
|
132
|
-
};
|
|
133
|
-
});
|
|
134
|
-
}
|
|
@@ -1,88 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Code generated by Speakeasy (https://speakeasyapi.dev). DO NOT EDIT.
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
import * as components from "../../models/components";
|
|
6
|
-
import { z } from "zod";
|
|
7
|
-
|
|
8
|
-
export type ListPhoneNumbersResponse = {
|
|
9
|
-
/**
|
|
10
|
-
* HTTP response content type for this operation
|
|
11
|
-
*/
|
|
12
|
-
contentType: string;
|
|
13
|
-
/**
|
|
14
|
-
* HTTP response status code for this operation
|
|
15
|
-
*/
|
|
16
|
-
statusCode: number;
|
|
17
|
-
/**
|
|
18
|
-
* Raw HTTP response; suitable for custom response parsing
|
|
19
|
-
*/
|
|
20
|
-
rawResponse: Response;
|
|
21
|
-
/**
|
|
22
|
-
* Successfully retrieved all phone number objects.
|
|
23
|
-
*/
|
|
24
|
-
phoneNumbers?: Array<components.PhoneNumber> | undefined;
|
|
25
|
-
};
|
|
26
|
-
|
|
27
|
-
/** @internal */
|
|
28
|
-
export namespace ListPhoneNumbersResponse$ {
|
|
29
|
-
export type Inbound = {
|
|
30
|
-
ContentType: string;
|
|
31
|
-
StatusCode: number;
|
|
32
|
-
RawResponse: Response;
|
|
33
|
-
phoneNumbers?: Array<components.PhoneNumber$.Inbound> | undefined;
|
|
34
|
-
};
|
|
35
|
-
|
|
36
|
-
export const inboundSchema: z.ZodType<
|
|
37
|
-
ListPhoneNumbersResponse,
|
|
38
|
-
z.ZodTypeDef,
|
|
39
|
-
Inbound
|
|
40
|
-
> = z
|
|
41
|
-
.object({
|
|
42
|
-
ContentType: z.string(),
|
|
43
|
-
StatusCode: z.number().int(),
|
|
44
|
-
RawResponse: z.instanceof(Response),
|
|
45
|
-
phoneNumbers: z.array(components.PhoneNumber$.inboundSchema).optional(),
|
|
46
|
-
})
|
|
47
|
-
.transform((v) => {
|
|
48
|
-
return {
|
|
49
|
-
contentType: v.ContentType,
|
|
50
|
-
statusCode: v.StatusCode,
|
|
51
|
-
rawResponse: v.RawResponse,
|
|
52
|
-
...(v.phoneNumbers === undefined
|
|
53
|
-
? null
|
|
54
|
-
: { phoneNumbers: v.phoneNumbers }),
|
|
55
|
-
};
|
|
56
|
-
});
|
|
57
|
-
|
|
58
|
-
export type Outbound = {
|
|
59
|
-
ContentType: string;
|
|
60
|
-
StatusCode: number;
|
|
61
|
-
RawResponse: never;
|
|
62
|
-
phoneNumbers?: Array<components.PhoneNumber$.Outbound> | undefined;
|
|
63
|
-
};
|
|
64
|
-
|
|
65
|
-
export const outboundSchema: z.ZodType<
|
|
66
|
-
Outbound,
|
|
67
|
-
z.ZodTypeDef,
|
|
68
|
-
ListPhoneNumbersResponse
|
|
69
|
-
> = z
|
|
70
|
-
.object({
|
|
71
|
-
contentType: z.string(),
|
|
72
|
-
statusCode: z.number().int(),
|
|
73
|
-
rawResponse: z.instanceof(Response).transform(() => {
|
|
74
|
-
throw new Error("Response cannot be serialized");
|
|
75
|
-
}),
|
|
76
|
-
phoneNumbers: z.array(components.PhoneNumber$.outboundSchema).optional(),
|
|
77
|
-
})
|
|
78
|
-
.transform((v) => {
|
|
79
|
-
return {
|
|
80
|
-
ContentType: v.contentType,
|
|
81
|
-
StatusCode: v.statusCode,
|
|
82
|
-
RawResponse: v.rawResponse,
|
|
83
|
-
...(v.phoneNumbers === undefined
|
|
84
|
-
? null
|
|
85
|
-
: { phoneNumbers: v.phoneNumbers }),
|
|
86
|
-
};
|
|
87
|
-
});
|
|
88
|
-
}
|
|
@@ -1,187 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Code generated by Speakeasy (https://speakeasyapi.dev). DO NOT EDIT.
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
import * as components from "../../models/components";
|
|
6
|
-
import { z } from "zod";
|
|
7
|
-
|
|
8
|
-
export type UpdatePhoneAgentRequestBody = {
|
|
9
|
-
/**
|
|
10
|
-
* Unique agent id to associate with this phone number.
|
|
11
|
-
*/
|
|
12
|
-
agentId: string;
|
|
13
|
-
};
|
|
14
|
-
|
|
15
|
-
export type UpdatePhoneAgentRequest = {
|
|
16
|
-
requestBody: UpdatePhoneAgentRequestBody;
|
|
17
|
-
/**
|
|
18
|
-
* Phone number in E.164 format that require agent update.
|
|
19
|
-
*/
|
|
20
|
-
phoneNumber: string;
|
|
21
|
-
};
|
|
22
|
-
|
|
23
|
-
export type UpdatePhoneAgentResponse = {
|
|
24
|
-
/**
|
|
25
|
-
* HTTP response content type for this operation
|
|
26
|
-
*/
|
|
27
|
-
contentType: string;
|
|
28
|
-
/**
|
|
29
|
-
* Successfully updated the phone number's agent.
|
|
30
|
-
*/
|
|
31
|
-
phoneNumber?: components.PhoneNumber | undefined;
|
|
32
|
-
/**
|
|
33
|
-
* HTTP response status code for this operation
|
|
34
|
-
*/
|
|
35
|
-
statusCode: number;
|
|
36
|
-
/**
|
|
37
|
-
* Raw HTTP response; suitable for custom response parsing
|
|
38
|
-
*/
|
|
39
|
-
rawResponse: Response;
|
|
40
|
-
};
|
|
41
|
-
|
|
42
|
-
/** @internal */
|
|
43
|
-
export namespace UpdatePhoneAgentRequestBody$ {
|
|
44
|
-
export type Inbound = {
|
|
45
|
-
agent_id: string;
|
|
46
|
-
};
|
|
47
|
-
|
|
48
|
-
export const inboundSchema: z.ZodType<
|
|
49
|
-
UpdatePhoneAgentRequestBody,
|
|
50
|
-
z.ZodTypeDef,
|
|
51
|
-
Inbound
|
|
52
|
-
> = z
|
|
53
|
-
.object({
|
|
54
|
-
agent_id: z.string(),
|
|
55
|
-
})
|
|
56
|
-
.transform((v) => {
|
|
57
|
-
return {
|
|
58
|
-
agentId: v.agent_id,
|
|
59
|
-
};
|
|
60
|
-
});
|
|
61
|
-
|
|
62
|
-
export type Outbound = {
|
|
63
|
-
agent_id: string;
|
|
64
|
-
};
|
|
65
|
-
|
|
66
|
-
export const outboundSchema: z.ZodType<
|
|
67
|
-
Outbound,
|
|
68
|
-
z.ZodTypeDef,
|
|
69
|
-
UpdatePhoneAgentRequestBody
|
|
70
|
-
> = z
|
|
71
|
-
.object({
|
|
72
|
-
agentId: z.string(),
|
|
73
|
-
})
|
|
74
|
-
.transform((v) => {
|
|
75
|
-
return {
|
|
76
|
-
agent_id: v.agentId,
|
|
77
|
-
};
|
|
78
|
-
});
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
/** @internal */
|
|
82
|
-
export namespace UpdatePhoneAgentRequest$ {
|
|
83
|
-
export type Inbound = {
|
|
84
|
-
RequestBody: UpdatePhoneAgentRequestBody$.Inbound;
|
|
85
|
-
phone_number: string;
|
|
86
|
-
};
|
|
87
|
-
|
|
88
|
-
export const inboundSchema: z.ZodType<
|
|
89
|
-
UpdatePhoneAgentRequest,
|
|
90
|
-
z.ZodTypeDef,
|
|
91
|
-
Inbound
|
|
92
|
-
> = z
|
|
93
|
-
.object({
|
|
94
|
-
RequestBody: z.lazy(() => UpdatePhoneAgentRequestBody$.inboundSchema),
|
|
95
|
-
phone_number: z.string(),
|
|
96
|
-
})
|
|
97
|
-
.transform((v) => {
|
|
98
|
-
return {
|
|
99
|
-
requestBody: v.RequestBody,
|
|
100
|
-
phoneNumber: v.phone_number,
|
|
101
|
-
};
|
|
102
|
-
});
|
|
103
|
-
|
|
104
|
-
export type Outbound = {
|
|
105
|
-
RequestBody: UpdatePhoneAgentRequestBody$.Outbound;
|
|
106
|
-
phone_number: string;
|
|
107
|
-
};
|
|
108
|
-
|
|
109
|
-
export const outboundSchema: z.ZodType<
|
|
110
|
-
Outbound,
|
|
111
|
-
z.ZodTypeDef,
|
|
112
|
-
UpdatePhoneAgentRequest
|
|
113
|
-
> = z
|
|
114
|
-
.object({
|
|
115
|
-
requestBody: z.lazy(() => UpdatePhoneAgentRequestBody$.outboundSchema),
|
|
116
|
-
phoneNumber: z.string(),
|
|
117
|
-
})
|
|
118
|
-
.transform((v) => {
|
|
119
|
-
return {
|
|
120
|
-
RequestBody: v.requestBody,
|
|
121
|
-
phone_number: v.phoneNumber,
|
|
122
|
-
};
|
|
123
|
-
});
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
/** @internal */
|
|
127
|
-
export namespace UpdatePhoneAgentResponse$ {
|
|
128
|
-
export type Inbound = {
|
|
129
|
-
ContentType: string;
|
|
130
|
-
PhoneNumber?: components.PhoneNumber$.Inbound | undefined;
|
|
131
|
-
StatusCode: number;
|
|
132
|
-
RawResponse: Response;
|
|
133
|
-
};
|
|
134
|
-
|
|
135
|
-
export const inboundSchema: z.ZodType<
|
|
136
|
-
UpdatePhoneAgentResponse,
|
|
137
|
-
z.ZodTypeDef,
|
|
138
|
-
Inbound
|
|
139
|
-
> = z
|
|
140
|
-
.object({
|
|
141
|
-
ContentType: z.string(),
|
|
142
|
-
PhoneNumber: components.PhoneNumber$.inboundSchema.optional(),
|
|
143
|
-
StatusCode: z.number().int(),
|
|
144
|
-
RawResponse: z.instanceof(Response),
|
|
145
|
-
})
|
|
146
|
-
.transform((v) => {
|
|
147
|
-
return {
|
|
148
|
-
contentType: v.ContentType,
|
|
149
|
-
...(v.PhoneNumber === undefined
|
|
150
|
-
? null
|
|
151
|
-
: { phoneNumber: v.PhoneNumber }),
|
|
152
|
-
statusCode: v.StatusCode,
|
|
153
|
-
rawResponse: v.RawResponse,
|
|
154
|
-
};
|
|
155
|
-
});
|
|
156
|
-
|
|
157
|
-
export type Outbound = {
|
|
158
|
-
ContentType: string;
|
|
159
|
-
PhoneNumber?: components.PhoneNumber$.Outbound | undefined;
|
|
160
|
-
StatusCode: number;
|
|
161
|
-
RawResponse: never;
|
|
162
|
-
};
|
|
163
|
-
|
|
164
|
-
export const outboundSchema: z.ZodType<
|
|
165
|
-
Outbound,
|
|
166
|
-
z.ZodTypeDef,
|
|
167
|
-
UpdatePhoneAgentResponse
|
|
168
|
-
> = z
|
|
169
|
-
.object({
|
|
170
|
-
contentType: z.string(),
|
|
171
|
-
phoneNumber: components.PhoneNumber$.outboundSchema.optional(),
|
|
172
|
-
statusCode: z.number().int(),
|
|
173
|
-
rawResponse: z.instanceof(Response).transform(() => {
|
|
174
|
-
throw new Error("Response cannot be serialized");
|
|
175
|
-
}),
|
|
176
|
-
})
|
|
177
|
-
.transform((v) => {
|
|
178
|
-
return {
|
|
179
|
-
ContentType: v.contentType,
|
|
180
|
-
...(v.phoneNumber === undefined
|
|
181
|
-
? null
|
|
182
|
-
: { PhoneNumber: v.phoneNumber }),
|
|
183
|
-
StatusCode: v.statusCode,
|
|
184
|
-
RawResponse: v.rawResponse,
|
|
185
|
-
};
|
|
186
|
-
});
|
|
187
|
-
}
|
package/src/sdk/liveClient.ts
DELETED
|
@@ -1,113 +0,0 @@
|
|
|
1
|
-
import { EventEmitter } from "eventemitter3";
|
|
2
|
-
import WebSocket, { MessageEvent } from "isomorphic-ws";
|
|
3
|
-
import * as operations from "../models/operations";
|
|
4
|
-
|
|
5
|
-
const baseEndpoint = "wss://api.re-tell.ai";
|
|
6
|
-
|
|
7
|
-
export class LiveClient extends EventEmitter {
|
|
8
|
-
private ws: WebSocket;
|
|
9
|
-
private call: any;
|
|
10
|
-
|
|
11
|
-
constructor(apiKey: string, input: operations.CreateWebCallRequestBody) {
|
|
12
|
-
super();
|
|
13
|
-
|
|
14
|
-
let endpoint =
|
|
15
|
-
baseEndpoint +
|
|
16
|
-
"/create-web-call?api_key=" +
|
|
17
|
-
apiKey +
|
|
18
|
-
"&agent_id=" +
|
|
19
|
-
input.agentId;
|
|
20
|
-
if (input.sampleRate != null) {
|
|
21
|
-
endpoint += "&sample_rate=" + input.sampleRate;
|
|
22
|
-
}
|
|
23
|
-
if (input.agentPromptParams != null) {
|
|
24
|
-
endpoint +=
|
|
25
|
-
"&agent_prompt_params=" +
|
|
26
|
-
encodeURIComponent(JSON.stringify(input.agentPromptParams));
|
|
27
|
-
}
|
|
28
|
-
this.ws = new WebSocket(endpoint);
|
|
29
|
-
this.ws.binaryType = "arraybuffer";
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
waitForReady() {
|
|
33
|
-
return new Promise<void>((resolve, reject) => {
|
|
34
|
-
const onError = (error: any) => {
|
|
35
|
-
reject(error); // Reject on error
|
|
36
|
-
};
|
|
37
|
-
this.ws.onerror = onError;
|
|
38
|
-
|
|
39
|
-
const onClose = (event: WebSocket.CloseEvent) => {
|
|
40
|
-
reject(
|
|
41
|
-
"websocket closed before ready with code: " +
|
|
42
|
-
event.code +
|
|
43
|
-
", reason: " +
|
|
44
|
-
event.reason,
|
|
45
|
-
);
|
|
46
|
-
};
|
|
47
|
-
this.ws.onclose = onClose;
|
|
48
|
-
|
|
49
|
-
const onMessage = (event: MessageEvent) => {
|
|
50
|
-
try {
|
|
51
|
-
const data = JSON.parse(event.data as string);
|
|
52
|
-
if (data.status === "ready") {
|
|
53
|
-
// Remove all registered listeners for cleaner future processing.
|
|
54
|
-
this.ws.removeEventListener("error", onError);
|
|
55
|
-
this.ws.removeEventListener("close", onClose);
|
|
56
|
-
this.ws.removeEventListener("message", onMessage);
|
|
57
|
-
// Emit audio
|
|
58
|
-
this.ws.onmessage = (event) => {
|
|
59
|
-
const audio: ArrayBuffer = event.data as ArrayBuffer;
|
|
60
|
-
this.emit("audio", new Uint8Array(audio));
|
|
61
|
-
};
|
|
62
|
-
this.ws.onclose = (event) => {
|
|
63
|
-
this.emit("close", event);
|
|
64
|
-
};
|
|
65
|
-
this.call = data.call;
|
|
66
|
-
resolve(); // Resolve when the ready message is received
|
|
67
|
-
}
|
|
68
|
-
} catch (error) {
|
|
69
|
-
// Handle JSON parsing error
|
|
70
|
-
reject("malformed ready event.");
|
|
71
|
-
}
|
|
72
|
-
};
|
|
73
|
-
this.ws.onmessage = onMessage;
|
|
74
|
-
});
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
send(audio: Uint8Array) {
|
|
78
|
-
if (this.ws.readyState === 1) this.ws.send(audio);
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
close() {
|
|
82
|
-
this.ws.close();
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
getCall() {
|
|
86
|
-
return this.call;
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
export function convertUint8ToFloat32(array: Uint8Array): Float32Array {
|
|
91
|
-
const targetArray = new Float32Array(array.byteLength / 2);
|
|
92
|
-
|
|
93
|
-
// A DataView is used to read our 16-bit little-endian samples out of the Uint8Array buffer
|
|
94
|
-
const sourceDataView = new DataView(array.buffer);
|
|
95
|
-
|
|
96
|
-
// Loop through, get values, and divide by 32,768
|
|
97
|
-
for (let i = 0; i < targetArray.length; i++) {
|
|
98
|
-
targetArray[i] = sourceDataView.getInt16(i * 2, true) / Math.pow(2, 16 - 1);
|
|
99
|
-
}
|
|
100
|
-
return targetArray;
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
export function convertFloat32ToUint8(array: Float32Array): Uint8Array {
|
|
104
|
-
const buffer = new ArrayBuffer(array.length * 2);
|
|
105
|
-
const view = new DataView(buffer);
|
|
106
|
-
|
|
107
|
-
for (let i = 0; i < array.length; i++) {
|
|
108
|
-
const value = (array[i] as number) * 32768;
|
|
109
|
-
view.setInt16(i * 2, value, true); // true for little-endian
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
return new Uint8Array(buffer);
|
|
113
|
-
}
|