phonic 0.31.8 → 0.31.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.
- package/README.md +1 -0
- package/dist/cjs/BaseClient.js +2 -2
- package/dist/cjs/api/resources/agents/client/Client.d.ts +3 -0
- package/dist/cjs/api/resources/agents/client/Client.js +3 -0
- package/dist/cjs/api/resources/agents/client/requests/AgentsCreateRequest.d.ts +3 -0
- package/dist/cjs/api/resources/agents/client/requests/UpdateAgentRequest.d.ts +3 -0
- package/dist/cjs/api/resources/agents/client/requests/UpsertAgentRequest.d.ts +1 -0
- package/dist/cjs/api/resources/conversations/client/requests/ConversationsSipOutboundCallRequest.d.ts +2 -0
- package/dist/cjs/api/resources/conversations/client/requests/OutboundCallRequest.d.ts +5 -1
- package/dist/cjs/api/resources/conversations/types/ConversationsOutboundCallResponse.d.ts +2 -4
- package/dist/cjs/api/resources/conversations/types/ConversationsSipOutboundCallResponse.d.ts +2 -6
- package/dist/cjs/api/types/Agent.d.ts +2 -0
- package/dist/cjs/api/types/ConfigPayload.d.ts +2 -0
- package/dist/cjs/api/types/Conversation.d.ts +2 -0
- package/dist/cjs/api/types/CreateAgentRequest.d.ts +2 -0
- package/dist/cjs/api/types/OutboundCallConfig.d.ts +2 -0
- package/dist/cjs/api/types/OutboundCallInitiatedResponse.d.ts +6 -0
- package/dist/cjs/api/types/{InterruptedResponsePayload.js → OutboundCallInitiatedResponse.js} +1 -3
- package/dist/cjs/api/types/OutboundDryRunResponse.d.ts +6 -0
- package/dist/cjs/api/{resources/agents/client/requests/AgentsRemoveCustomPhoneNumberRequest.js → types/OutboundDryRunResponse.js} +1 -3
- package/dist/cjs/api/types/SipOutboundCallInitiatedResponse.d.ts +8 -0
- package/dist/cjs/api/types/{AudioFinishedPayload.js → SipOutboundCallInitiatedResponse.js} +1 -3
- package/dist/cjs/api/types/SipOutboundDryRunResponse.d.ts +8 -0
- package/dist/cjs/api/{resources/agents/types/AgentsRemoveCustomPhoneNumberResponse.js → types/SipOutboundDryRunResponse.js} +1 -3
- package/dist/cjs/api/types/index.d.ts +4 -0
- package/dist/cjs/api/types/index.js +4 -0
- package/dist/cjs/version.d.ts +1 -1
- package/dist/cjs/version.js +1 -1
- package/dist/esm/BaseClient.mjs +2 -2
- package/dist/esm/api/resources/agents/client/Client.d.mts +3 -0
- package/dist/esm/api/resources/agents/client/Client.mjs +3 -0
- package/dist/esm/api/resources/agents/client/requests/AgentsCreateRequest.d.mts +3 -0
- package/dist/esm/api/resources/agents/client/requests/UpdateAgentRequest.d.mts +3 -0
- package/dist/esm/api/resources/agents/client/requests/UpsertAgentRequest.d.mts +1 -0
- package/dist/esm/api/resources/conversations/client/requests/ConversationsSipOutboundCallRequest.d.mts +2 -0
- package/dist/esm/api/resources/conversations/client/requests/OutboundCallRequest.d.mts +5 -1
- package/dist/esm/api/resources/conversations/types/ConversationsOutboundCallResponse.d.mts +2 -4
- package/dist/esm/api/resources/conversations/types/ConversationsSipOutboundCallResponse.d.mts +2 -6
- package/dist/esm/api/types/Agent.d.mts +2 -0
- package/dist/esm/api/types/ConfigPayload.d.mts +2 -0
- package/dist/esm/api/types/Conversation.d.mts +2 -0
- package/dist/esm/api/types/CreateAgentRequest.d.mts +2 -0
- package/dist/esm/api/types/OutboundCallConfig.d.mts +2 -0
- package/dist/esm/api/types/OutboundCallInitiatedResponse.d.mts +6 -0
- package/dist/esm/api/types/OutboundCallInitiatedResponse.mjs +2 -0
- package/dist/esm/api/types/OutboundDryRunResponse.d.mts +6 -0
- package/dist/esm/api/types/OutboundDryRunResponse.mjs +2 -0
- package/dist/esm/api/types/SipOutboundCallInitiatedResponse.d.mts +8 -0
- package/dist/esm/api/types/SipOutboundCallInitiatedResponse.mjs +2 -0
- package/dist/esm/api/types/SipOutboundDryRunResponse.d.mts +8 -0
- package/dist/esm/api/types/SipOutboundDryRunResponse.mjs +2 -0
- package/dist/esm/api/types/index.d.mts +4 -0
- package/dist/esm/api/types/index.mjs +4 -0
- package/dist/esm/version.d.mts +1 -1
- package/dist/esm/version.mjs +1 -1
- package/package.json +1 -1
- package/reference.md +6 -1
- package/dist/cjs/api/resources/agents/client/requests/AgentsRemoveCustomPhoneNumberRequest.d.ts +0 -16
- package/dist/cjs/api/resources/agents/types/AgentsRemoveCustomPhoneNumberResponse.d.ts +0 -6
- package/dist/cjs/api/types/AudioFinishedPayload.d.ts +0 -6
- package/dist/cjs/api/types/InterruptedResponsePayload.d.ts +0 -8
- package/dist/cjs/api/types/IsUserSpeakingPayload.d.ts +0 -8
- package/dist/cjs/api/types/IsUserSpeakingPayload.js +0 -5
- package/dist/cjs/api/types/SetTwilioCallSidPayload.d.ts +0 -8
- package/dist/cjs/api/types/SetTwilioCallSidPayload.js +0 -5
- package/dist/cjs/core/fetcher/ResponseWithBody.d.ts +0 -4
- package/dist/cjs/core/fetcher/ResponseWithBody.js +0 -6
- package/dist/esm/api/resources/agents/client/requests/AgentsRemoveCustomPhoneNumberRequest.d.mts +0 -16
- package/dist/esm/api/resources/agents/client/requests/AgentsRemoveCustomPhoneNumberRequest.mjs +0 -4
- package/dist/esm/api/resources/agents/types/AgentsRemoveCustomPhoneNumberResponse.d.mts +0 -6
- package/dist/esm/api/resources/agents/types/AgentsRemoveCustomPhoneNumberResponse.mjs +0 -4
- package/dist/esm/api/types/AudioFinishedPayload.d.mts +0 -6
- package/dist/esm/api/types/AudioFinishedPayload.mjs +0 -4
- package/dist/esm/api/types/InterruptedResponsePayload.d.mts +0 -8
- package/dist/esm/api/types/InterruptedResponsePayload.mjs +0 -4
- package/dist/esm/api/types/IsUserSpeakingPayload.d.mts +0 -8
- package/dist/esm/api/types/IsUserSpeakingPayload.mjs +0 -4
- package/dist/esm/api/types/SetTwilioCallSidPayload.d.mts +0 -8
- package/dist/esm/api/types/SetTwilioCallSidPayload.mjs +0 -4
- package/dist/esm/core/fetcher/ResponseWithBody.d.mts +0 -4
- package/dist/esm/core/fetcher/ResponseWithBody.mjs +0 -3
- package/dist/index.d.mts +0 -686
- package/dist/index.d.ts +0 -686
- package/dist/index.js +0 -643
- package/dist/index.mjs +0 -606
package/dist/index.mjs
DELETED
|
@@ -1,606 +0,0 @@
|
|
|
1
|
-
// package.json
|
|
2
|
-
var version = "0.29.1";
|
|
3
|
-
|
|
4
|
-
// src/agents/index.ts
|
|
5
|
-
var Agents = class {
|
|
6
|
-
constructor(phonic) {
|
|
7
|
-
this.phonic = phonic;
|
|
8
|
-
}
|
|
9
|
-
getQueryString(params) {
|
|
10
|
-
const project = params?.project;
|
|
11
|
-
const queryString = new URLSearchParams({
|
|
12
|
-
...project !== void 0 && { project }
|
|
13
|
-
}).toString();
|
|
14
|
-
return queryString;
|
|
15
|
-
}
|
|
16
|
-
getTemplateVariablesForBody(templateVariables) {
|
|
17
|
-
if (templateVariables === void 0) {
|
|
18
|
-
return void 0;
|
|
19
|
-
}
|
|
20
|
-
return Object.fromEntries(
|
|
21
|
-
Object.entries(templateVariables).map(([key, value]) => [
|
|
22
|
-
key,
|
|
23
|
-
{
|
|
24
|
-
default_value: value.defaultValue
|
|
25
|
-
}
|
|
26
|
-
])
|
|
27
|
-
);
|
|
28
|
-
}
|
|
29
|
-
getConfigurationEndpointForBody(configurationEndpoint) {
|
|
30
|
-
if (configurationEndpoint === void 0 || configurationEndpoint === null) {
|
|
31
|
-
return configurationEndpoint;
|
|
32
|
-
}
|
|
33
|
-
return {
|
|
34
|
-
url: configurationEndpoint.url,
|
|
35
|
-
headers: configurationEndpoint.headers,
|
|
36
|
-
timeout_ms: configurationEndpoint.timeoutMs
|
|
37
|
-
};
|
|
38
|
-
}
|
|
39
|
-
async list(params) {
|
|
40
|
-
const response = await this.phonic.get(
|
|
41
|
-
`/agents?${this.getQueryString(params)}`
|
|
42
|
-
);
|
|
43
|
-
return response;
|
|
44
|
-
}
|
|
45
|
-
async get(nameOrId, params) {
|
|
46
|
-
const response = await this.phonic.get(
|
|
47
|
-
`/agents/${nameOrId}?${this.getQueryString(params)}`
|
|
48
|
-
);
|
|
49
|
-
return response;
|
|
50
|
-
}
|
|
51
|
-
async create(params) {
|
|
52
|
-
const response = await this.phonic.post(
|
|
53
|
-
`/agents?${this.getQueryString(params)}`,
|
|
54
|
-
{
|
|
55
|
-
name: params.name,
|
|
56
|
-
phone_number: params.phoneNumber,
|
|
57
|
-
timezone: params.timezone,
|
|
58
|
-
audio_format: params.phoneNumber === "assign-automatically" ? "mulaw_8000" : params.audioFormat,
|
|
59
|
-
audio_speed: params.audioSpeed,
|
|
60
|
-
voice_id: params.voiceId,
|
|
61
|
-
welcome_message: params.welcomeMessage,
|
|
62
|
-
system_prompt: params.systemPrompt,
|
|
63
|
-
template_variables: this.getTemplateVariablesForBody(
|
|
64
|
-
params.templateVariables
|
|
65
|
-
),
|
|
66
|
-
tools: params.tools,
|
|
67
|
-
no_input_poke_sec: params.noInputPokeSec,
|
|
68
|
-
no_input_poke_text: params.noInputPokeText,
|
|
69
|
-
no_input_end_conversation_sec: params.noInputEndConversationSec,
|
|
70
|
-
boosted_keywords: params.boostedKeywords,
|
|
71
|
-
configuration_endpoint: this.getConfigurationEndpointForBody(
|
|
72
|
-
params.configurationEndpoint
|
|
73
|
-
)
|
|
74
|
-
}
|
|
75
|
-
);
|
|
76
|
-
return response;
|
|
77
|
-
}
|
|
78
|
-
async update(nameOrId, params) {
|
|
79
|
-
const response = await this.phonic.patch(
|
|
80
|
-
`/agents/${nameOrId}?${this.getQueryString(params)}`,
|
|
81
|
-
{
|
|
82
|
-
name: params.name,
|
|
83
|
-
phone_number: params.phoneNumber,
|
|
84
|
-
timezone: params.timezone,
|
|
85
|
-
audio_format: params.phoneNumber === "assign-automatically" ? "mulaw_8000" : params.audioFormat,
|
|
86
|
-
voice_id: params.voiceId,
|
|
87
|
-
audio_speed: params.audioSpeed,
|
|
88
|
-
welcome_message: params.welcomeMessage,
|
|
89
|
-
system_prompt: params.systemPrompt,
|
|
90
|
-
template_variables: this.getTemplateVariablesForBody(
|
|
91
|
-
params.templateVariables
|
|
92
|
-
),
|
|
93
|
-
tools: params.tools,
|
|
94
|
-
no_input_poke_sec: params.noInputPokeSec,
|
|
95
|
-
no_input_poke_text: params.noInputPokeText,
|
|
96
|
-
no_input_end_conversation_sec: params.noInputEndConversationSec,
|
|
97
|
-
boosted_keywords: params.boostedKeywords,
|
|
98
|
-
configuration_endpoint: this.getConfigurationEndpointForBody(
|
|
99
|
-
params.configurationEndpoint
|
|
100
|
-
)
|
|
101
|
-
}
|
|
102
|
-
);
|
|
103
|
-
return response;
|
|
104
|
-
}
|
|
105
|
-
async upsert(params) {
|
|
106
|
-
const response = await this.phonic.put(
|
|
107
|
-
`/agents/upsert?${this.getQueryString(params)}`,
|
|
108
|
-
{
|
|
109
|
-
name: params.name,
|
|
110
|
-
phone_number: params.phoneNumber,
|
|
111
|
-
timezone: params.timezone,
|
|
112
|
-
audio_format: params.phoneNumber === "assign-automatically" ? "mulaw_8000" : params.audioFormat,
|
|
113
|
-
voice_id: params.voiceId,
|
|
114
|
-
welcome_message: params.welcomeMessage,
|
|
115
|
-
system_prompt: params.systemPrompt,
|
|
116
|
-
audio_speed: params.audioSpeed,
|
|
117
|
-
template_variables: this.getTemplateVariablesForBody(
|
|
118
|
-
params.templateVariables
|
|
119
|
-
),
|
|
120
|
-
tools: params.tools,
|
|
121
|
-
no_input_poke_sec: params.noInputPokeSec,
|
|
122
|
-
no_input_poke_text: params.noInputPokeText,
|
|
123
|
-
no_input_end_conversation_sec: params.noInputEndConversationSec,
|
|
124
|
-
boosted_keywords: params.boostedKeywords,
|
|
125
|
-
configuration_endpoint: this.getConfigurationEndpointForBody(
|
|
126
|
-
params.configurationEndpoint
|
|
127
|
-
)
|
|
128
|
-
}
|
|
129
|
-
);
|
|
130
|
-
return response;
|
|
131
|
-
}
|
|
132
|
-
async delete(nameOrId, params) {
|
|
133
|
-
const response = await this.phonic.delete(
|
|
134
|
-
`/agents/${nameOrId}?${this.getQueryString(params)}`
|
|
135
|
-
);
|
|
136
|
-
return response;
|
|
137
|
-
}
|
|
138
|
-
};
|
|
139
|
-
|
|
140
|
-
// src/conversations/twilio/index.ts
|
|
141
|
-
var Twilio = class {
|
|
142
|
-
constructor(phonic) {
|
|
143
|
-
this.phonic = phonic;
|
|
144
|
-
}
|
|
145
|
-
async outboundCall(params, config) {
|
|
146
|
-
const response = await this.phonic.post(
|
|
147
|
-
"/conversations/twilio/outbound_call",
|
|
148
|
-
{
|
|
149
|
-
from_phone_number: params.from_phone_number,
|
|
150
|
-
to_phone_number: params.to_phone_number,
|
|
151
|
-
config
|
|
152
|
-
},
|
|
153
|
-
{
|
|
154
|
-
"X-Twilio-Account-Sid": params.account_sid,
|
|
155
|
-
"X-Twilio-Api-Key-Sid": params.api_key_sid,
|
|
156
|
-
"X-Twilio-Api-Key-Secret": params.api_key_secret
|
|
157
|
-
}
|
|
158
|
-
);
|
|
159
|
-
return response;
|
|
160
|
-
}
|
|
161
|
-
};
|
|
162
|
-
|
|
163
|
-
// src/conversations/index.ts
|
|
164
|
-
var Conversations = class {
|
|
165
|
-
constructor(phonic) {
|
|
166
|
-
this.phonic = phonic;
|
|
167
|
-
this.twilio = new Twilio(phonic);
|
|
168
|
-
}
|
|
169
|
-
twilio;
|
|
170
|
-
async list({
|
|
171
|
-
project,
|
|
172
|
-
durationMin,
|
|
173
|
-
durationMax,
|
|
174
|
-
startedAtMin,
|
|
175
|
-
startedAtMax
|
|
176
|
-
}) {
|
|
177
|
-
const queryString = new URLSearchParams({
|
|
178
|
-
...project !== void 0 && { project },
|
|
179
|
-
...durationMin !== void 0 && { duration_min: String(durationMin) },
|
|
180
|
-
...durationMax !== void 0 && { duration_max: String(durationMax) },
|
|
181
|
-
...startedAtMin !== void 0 && { started_at_min: startedAtMin },
|
|
182
|
-
...startedAtMax !== void 0 && { started_at_max: startedAtMax }
|
|
183
|
-
}).toString();
|
|
184
|
-
const response = await this.phonic.get(
|
|
185
|
-
`/conversations?${queryString}`
|
|
186
|
-
);
|
|
187
|
-
return response;
|
|
188
|
-
}
|
|
189
|
-
async get(id) {
|
|
190
|
-
const response = await this.phonic.get(
|
|
191
|
-
`/conversations/${id}`
|
|
192
|
-
);
|
|
193
|
-
return response;
|
|
194
|
-
}
|
|
195
|
-
async getByExternalId({
|
|
196
|
-
project,
|
|
197
|
-
externalId
|
|
198
|
-
}) {
|
|
199
|
-
const queryString = new URLSearchParams({
|
|
200
|
-
...project !== void 0 && { project },
|
|
201
|
-
external_id: externalId
|
|
202
|
-
}).toString();
|
|
203
|
-
const response = await this.phonic.get(
|
|
204
|
-
`/conversations?${queryString}`
|
|
205
|
-
);
|
|
206
|
-
return response;
|
|
207
|
-
}
|
|
208
|
-
async outboundCall(toPhoneNumber, config) {
|
|
209
|
-
const response = await this.phonic.post(
|
|
210
|
-
"/conversations/outbound_call",
|
|
211
|
-
{
|
|
212
|
-
to_phone_number: toPhoneNumber,
|
|
213
|
-
config
|
|
214
|
-
}
|
|
215
|
-
);
|
|
216
|
-
return response;
|
|
217
|
-
}
|
|
218
|
-
};
|
|
219
|
-
|
|
220
|
-
// src/projects/index.ts
|
|
221
|
-
var Projects = class {
|
|
222
|
-
constructor(phonic) {
|
|
223
|
-
this.phonic = phonic;
|
|
224
|
-
}
|
|
225
|
-
async list() {
|
|
226
|
-
const response = await this.phonic.get("/projects");
|
|
227
|
-
return response;
|
|
228
|
-
}
|
|
229
|
-
async get(nameOrId) {
|
|
230
|
-
const response = await this.phonic.get(
|
|
231
|
-
`/projects/${nameOrId}`
|
|
232
|
-
);
|
|
233
|
-
return response;
|
|
234
|
-
}
|
|
235
|
-
async create(params) {
|
|
236
|
-
const response = await this.phonic.post(
|
|
237
|
-
"/projects",
|
|
238
|
-
{
|
|
239
|
-
name: params.name
|
|
240
|
-
}
|
|
241
|
-
);
|
|
242
|
-
return response;
|
|
243
|
-
}
|
|
244
|
-
async update(nameOrId, params) {
|
|
245
|
-
const response = await this.phonic.patch(
|
|
246
|
-
`/projects/${nameOrId}`,
|
|
247
|
-
{
|
|
248
|
-
name: params.name,
|
|
249
|
-
default_agent: params.defaultAgent
|
|
250
|
-
}
|
|
251
|
-
);
|
|
252
|
-
return response;
|
|
253
|
-
}
|
|
254
|
-
async delete(nameOrId) {
|
|
255
|
-
const response = await this.phonic.delete(
|
|
256
|
-
`/projects/${nameOrId}`
|
|
257
|
-
);
|
|
258
|
-
return response;
|
|
259
|
-
}
|
|
260
|
-
};
|
|
261
|
-
|
|
262
|
-
// src/sts/index.ts
|
|
263
|
-
import WebSocket from "ws";
|
|
264
|
-
|
|
265
|
-
// src/sts/websocket.ts
|
|
266
|
-
var PhonicSTSWebSocket = class {
|
|
267
|
-
constructor(ws, config) {
|
|
268
|
-
this.ws = ws;
|
|
269
|
-
this.config = config;
|
|
270
|
-
this.buffer.push(
|
|
271
|
-
JSON.stringify({
|
|
272
|
-
type: "config",
|
|
273
|
-
...this.config
|
|
274
|
-
})
|
|
275
|
-
);
|
|
276
|
-
this.ws.onopen = () => {
|
|
277
|
-
for (const message of this.buffer) {
|
|
278
|
-
this.ws.send(message);
|
|
279
|
-
}
|
|
280
|
-
this.isOpen = true;
|
|
281
|
-
};
|
|
282
|
-
this.ws.onmessage = (event) => {
|
|
283
|
-
if (this.onMessageCallback === null) {
|
|
284
|
-
return;
|
|
285
|
-
}
|
|
286
|
-
if (typeof event.data !== "string") {
|
|
287
|
-
throw new Error("Received non-string message");
|
|
288
|
-
}
|
|
289
|
-
const dataObj = JSON.parse(
|
|
290
|
-
event.data
|
|
291
|
-
);
|
|
292
|
-
this.onMessageCallback(dataObj);
|
|
293
|
-
};
|
|
294
|
-
this.ws.onclose = (event) => {
|
|
295
|
-
if (this.onCloseCallback === null) {
|
|
296
|
-
return;
|
|
297
|
-
}
|
|
298
|
-
this.onCloseCallback(event);
|
|
299
|
-
};
|
|
300
|
-
this.ws.onerror = (event) => {
|
|
301
|
-
if (this.onErrorCallback === null) {
|
|
302
|
-
return;
|
|
303
|
-
}
|
|
304
|
-
this.onErrorCallback(event);
|
|
305
|
-
};
|
|
306
|
-
this.onMessage = this.onMessage.bind(this);
|
|
307
|
-
this.onClose = this.onClose.bind(this);
|
|
308
|
-
this.onError = this.onError.bind(this);
|
|
309
|
-
this.audioChunk = this.audioChunk.bind(this);
|
|
310
|
-
this.sendToolCallOutput = this.sendToolCallOutput.bind(this);
|
|
311
|
-
this.updateSystemPrompt = this.updateSystemPrompt.bind(this);
|
|
312
|
-
this.setExternalId = this.setExternalId.bind(this);
|
|
313
|
-
this.close = this.close.bind(this);
|
|
314
|
-
}
|
|
315
|
-
onMessageCallback = null;
|
|
316
|
-
onCloseCallback = null;
|
|
317
|
-
onErrorCallback = null;
|
|
318
|
-
buffer = [];
|
|
319
|
-
isOpen = false;
|
|
320
|
-
processUserMessage(message) {
|
|
321
|
-
const messageStr = JSON.stringify(message);
|
|
322
|
-
if (this.isOpen) {
|
|
323
|
-
this.ws.send(messageStr);
|
|
324
|
-
} else {
|
|
325
|
-
this.buffer.push(messageStr);
|
|
326
|
-
}
|
|
327
|
-
}
|
|
328
|
-
onMessage(callback) {
|
|
329
|
-
this.onMessageCallback = callback;
|
|
330
|
-
}
|
|
331
|
-
onClose(callback) {
|
|
332
|
-
this.onCloseCallback = callback;
|
|
333
|
-
}
|
|
334
|
-
onError(callback) {
|
|
335
|
-
this.onErrorCallback = callback;
|
|
336
|
-
}
|
|
337
|
-
audioChunk({ audio }) {
|
|
338
|
-
this.processUserMessage({
|
|
339
|
-
type: "audio_chunk",
|
|
340
|
-
audio
|
|
341
|
-
});
|
|
342
|
-
}
|
|
343
|
-
sendToolCallOutput({
|
|
344
|
-
toolCallId,
|
|
345
|
-
output
|
|
346
|
-
}) {
|
|
347
|
-
this.processUserMessage({
|
|
348
|
-
type: "tool_call_output",
|
|
349
|
-
tool_call_id: toolCallId,
|
|
350
|
-
output
|
|
351
|
-
});
|
|
352
|
-
}
|
|
353
|
-
updateSystemPrompt({ systemPrompt }) {
|
|
354
|
-
this.processUserMessage({
|
|
355
|
-
type: "update_system_prompt",
|
|
356
|
-
system_prompt: systemPrompt
|
|
357
|
-
});
|
|
358
|
-
}
|
|
359
|
-
setExternalId({ externalId }) {
|
|
360
|
-
this.processUserMessage({
|
|
361
|
-
type: "set_external_id",
|
|
362
|
-
external_id: externalId
|
|
363
|
-
});
|
|
364
|
-
}
|
|
365
|
-
close(code) {
|
|
366
|
-
this.ws.close(code ?? 1e3);
|
|
367
|
-
}
|
|
368
|
-
};
|
|
369
|
-
|
|
370
|
-
// src/sts/index.ts
|
|
371
|
-
var SpeechToSpeech = class {
|
|
372
|
-
constructor(phonic) {
|
|
373
|
-
this.phonic = phonic;
|
|
374
|
-
}
|
|
375
|
-
websocket(config) {
|
|
376
|
-
const wsBaseUrl = this.phonic.baseUrl.replace(/^http/, "ws");
|
|
377
|
-
const queryString = new URLSearchParams({
|
|
378
|
-
...this.phonic.__downstreamWebSocketUrl !== null && {
|
|
379
|
-
downstream_websocket_url: this.phonic.__downstreamWebSocketUrl
|
|
380
|
-
}
|
|
381
|
-
}).toString();
|
|
382
|
-
const phonicApiWsUrl = `${wsBaseUrl}/v1/sts/ws?${queryString}`;
|
|
383
|
-
const ws = new WebSocket(phonicApiWsUrl, {
|
|
384
|
-
headers: this.phonic.headers
|
|
385
|
-
});
|
|
386
|
-
return new PhonicSTSWebSocket(ws, config);
|
|
387
|
-
}
|
|
388
|
-
};
|
|
389
|
-
|
|
390
|
-
// src/tools/index.ts
|
|
391
|
-
var Tools = class {
|
|
392
|
-
constructor(phonic) {
|
|
393
|
-
this.phonic = phonic;
|
|
394
|
-
}
|
|
395
|
-
getQueryString(params) {
|
|
396
|
-
const project = params?.project;
|
|
397
|
-
const queryString = new URLSearchParams({
|
|
398
|
-
...project !== void 0 && { project }
|
|
399
|
-
}).toString();
|
|
400
|
-
return queryString;
|
|
401
|
-
}
|
|
402
|
-
getParametersForBody(parameters) {
|
|
403
|
-
if (parameters === void 0) {
|
|
404
|
-
return void 0;
|
|
405
|
-
}
|
|
406
|
-
return parameters.map((parameter) => {
|
|
407
|
-
return {
|
|
408
|
-
type: parameter.type,
|
|
409
|
-
name: parameter.name,
|
|
410
|
-
description: parameter.description,
|
|
411
|
-
is_required: parameter.isRequired,
|
|
412
|
-
...parameter.type === "array" && {
|
|
413
|
-
item_type: parameter.itemType
|
|
414
|
-
}
|
|
415
|
-
};
|
|
416
|
-
});
|
|
417
|
-
}
|
|
418
|
-
async list(params) {
|
|
419
|
-
const response = await this.phonic.get(
|
|
420
|
-
`/tools?${this.getQueryString(params)}`
|
|
421
|
-
);
|
|
422
|
-
return response;
|
|
423
|
-
}
|
|
424
|
-
async get(nameOrId, params) {
|
|
425
|
-
const response = await this.phonic.get(
|
|
426
|
-
`/tools/${nameOrId}?${this.getQueryString(params)}`
|
|
427
|
-
);
|
|
428
|
-
return response;
|
|
429
|
-
}
|
|
430
|
-
async create(params) {
|
|
431
|
-
const body = {
|
|
432
|
-
name: params.name,
|
|
433
|
-
description: params.description,
|
|
434
|
-
type: params.type,
|
|
435
|
-
execution_mode: params.executionMode,
|
|
436
|
-
parameters: this.getParametersForBody(params.parameters)
|
|
437
|
-
};
|
|
438
|
-
if (params.type === "custom_webhook") {
|
|
439
|
-
body.endpoint_method = params.endpointMethod;
|
|
440
|
-
body.endpoint_url = params.endpointUrl;
|
|
441
|
-
body.endpoint_headers = params.endpointHeaders;
|
|
442
|
-
body.endpoint_timeout_ms = params.endpointTimeoutMs;
|
|
443
|
-
}
|
|
444
|
-
if (params.type === "custom_websocket") {
|
|
445
|
-
body.tool_call_output_timeout_ms = params.toolCallOutputTimeoutMs;
|
|
446
|
-
}
|
|
447
|
-
const response = await this.phonic.post(
|
|
448
|
-
`/tools?${this.getQueryString(params)}`,
|
|
449
|
-
body
|
|
450
|
-
);
|
|
451
|
-
return response;
|
|
452
|
-
}
|
|
453
|
-
async update(nameOrId, params) {
|
|
454
|
-
const response = await this.phonic.patch(
|
|
455
|
-
`/tools/${nameOrId}?${this.getQueryString(params)}`,
|
|
456
|
-
{
|
|
457
|
-
name: params.name,
|
|
458
|
-
description: params.description,
|
|
459
|
-
type: params.type,
|
|
460
|
-
execution_mode: params.executionMode,
|
|
461
|
-
endpoint_method: params.endpointMethod,
|
|
462
|
-
endpoint_url: params.endpointUrl,
|
|
463
|
-
endpoint_headers: params.endpointHeaders,
|
|
464
|
-
endpoint_timeout_ms: params.endpointTimeoutMs,
|
|
465
|
-
parameters: this.getParametersForBody(params.parameters),
|
|
466
|
-
tool_call_output_timeout_ms: params.toolCallOutputTimeoutMs
|
|
467
|
-
}
|
|
468
|
-
);
|
|
469
|
-
return response;
|
|
470
|
-
}
|
|
471
|
-
async delete(nameOrId, params) {
|
|
472
|
-
const response = await this.phonic.delete(
|
|
473
|
-
`/tools/${nameOrId}?${this.getQueryString(params)}`
|
|
474
|
-
);
|
|
475
|
-
return response;
|
|
476
|
-
}
|
|
477
|
-
};
|
|
478
|
-
|
|
479
|
-
// src/voices/index.ts
|
|
480
|
-
var Voices = class {
|
|
481
|
-
constructor(phonic) {
|
|
482
|
-
this.phonic = phonic;
|
|
483
|
-
}
|
|
484
|
-
async list({ model }) {
|
|
485
|
-
const response = await this.phonic.get(
|
|
486
|
-
`/voices?model=${encodeURIComponent(model)}`
|
|
487
|
-
);
|
|
488
|
-
return response;
|
|
489
|
-
}
|
|
490
|
-
async get(id) {
|
|
491
|
-
const response = await this.phonic.get(
|
|
492
|
-
`/voices/${id}`
|
|
493
|
-
);
|
|
494
|
-
return response;
|
|
495
|
-
}
|
|
496
|
-
};
|
|
497
|
-
|
|
498
|
-
// src/phonic.ts
|
|
499
|
-
var defaultBaseUrl = "https://api.phonic.co";
|
|
500
|
-
var defaultUserAgent = `phonic-node:${version}`;
|
|
501
|
-
var Phonic = class {
|
|
502
|
-
constructor(apiKey, config) {
|
|
503
|
-
this.apiKey = apiKey;
|
|
504
|
-
if (typeof process === "undefined") {
|
|
505
|
-
throw new Error(
|
|
506
|
-
"Phonic SDK is intended to be used in Node.js environment."
|
|
507
|
-
);
|
|
508
|
-
}
|
|
509
|
-
if (!this.apiKey) {
|
|
510
|
-
throw new Error(
|
|
511
|
-
'API key is missing. Pass it to the constructor: `new Phonic("ph_...")`'
|
|
512
|
-
);
|
|
513
|
-
}
|
|
514
|
-
this.baseUrl = (config?.baseUrl ?? defaultBaseUrl).replace(/\/$/, "");
|
|
515
|
-
this.__downstreamWebSocketUrl = config?.__downstreamWebSocketUrl || null;
|
|
516
|
-
this.headers = {
|
|
517
|
-
Authorization: `Bearer ${this.apiKey}`,
|
|
518
|
-
"User-Agent": process.env.PHONIC_USER_AGENT || defaultUserAgent,
|
|
519
|
-
"Content-Type": "application/json",
|
|
520
|
-
...config?.headers
|
|
521
|
-
};
|
|
522
|
-
}
|
|
523
|
-
baseUrl;
|
|
524
|
-
__downstreamWebSocketUrl;
|
|
525
|
-
headers;
|
|
526
|
-
agents = new Agents(this);
|
|
527
|
-
conversations = new Conversations(this);
|
|
528
|
-
projects = new Projects(this);
|
|
529
|
-
tools = new Tools(this);
|
|
530
|
-
voices = new Voices(this);
|
|
531
|
-
sts = new SpeechToSpeech(this);
|
|
532
|
-
async fetchRequest(path, options) {
|
|
533
|
-
try {
|
|
534
|
-
const { headers, ...restOptions } = options;
|
|
535
|
-
const response = await fetch(`${this.baseUrl}/v1${path}`, {
|
|
536
|
-
headers: {
|
|
537
|
-
...this.headers,
|
|
538
|
-
...headers
|
|
539
|
-
},
|
|
540
|
-
...restOptions
|
|
541
|
-
});
|
|
542
|
-
if (response.ok) {
|
|
543
|
-
const data = await response.json();
|
|
544
|
-
return { data, error: null };
|
|
545
|
-
}
|
|
546
|
-
try {
|
|
547
|
-
const data = await response.json();
|
|
548
|
-
return {
|
|
549
|
-
data: null,
|
|
550
|
-
error: {
|
|
551
|
-
message: data.error.message || response.statusText,
|
|
552
|
-
param_errors: data.param_errors
|
|
553
|
-
}
|
|
554
|
-
};
|
|
555
|
-
} catch (error) {
|
|
556
|
-
return {
|
|
557
|
-
data: null,
|
|
558
|
-
error: {
|
|
559
|
-
message: response.statusText
|
|
560
|
-
}
|
|
561
|
-
};
|
|
562
|
-
}
|
|
563
|
-
} catch (error) {
|
|
564
|
-
console.error(error);
|
|
565
|
-
return {
|
|
566
|
-
data: null,
|
|
567
|
-
error: {
|
|
568
|
-
message: "Fetch request failed"
|
|
569
|
-
}
|
|
570
|
-
};
|
|
571
|
-
}
|
|
572
|
-
}
|
|
573
|
-
async get(path) {
|
|
574
|
-
return this.fetchRequest(path, { method: "GET" });
|
|
575
|
-
}
|
|
576
|
-
async post(path, body, headers) {
|
|
577
|
-
return this.fetchRequest(path, {
|
|
578
|
-
method: "POST",
|
|
579
|
-
body: JSON.stringify(body),
|
|
580
|
-
headers
|
|
581
|
-
});
|
|
582
|
-
}
|
|
583
|
-
async patch(path, body, headers) {
|
|
584
|
-
return this.fetchRequest(path, {
|
|
585
|
-
method: "PATCH",
|
|
586
|
-
body: JSON.stringify(body),
|
|
587
|
-
headers
|
|
588
|
-
});
|
|
589
|
-
}
|
|
590
|
-
async put(path, body, headers) {
|
|
591
|
-
return this.fetchRequest(path, {
|
|
592
|
-
method: "PUT",
|
|
593
|
-
body: JSON.stringify(body),
|
|
594
|
-
headers
|
|
595
|
-
});
|
|
596
|
-
}
|
|
597
|
-
async delete(path, headers) {
|
|
598
|
-
return this.fetchRequest(path, {
|
|
599
|
-
method: "DELETE",
|
|
600
|
-
headers
|
|
601
|
-
});
|
|
602
|
-
}
|
|
603
|
-
};
|
|
604
|
-
export {
|
|
605
|
-
Phonic
|
|
606
|
-
};
|