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.
Files changed (85) hide show
  1. package/README.md +1 -0
  2. package/dist/cjs/BaseClient.js +2 -2
  3. package/dist/cjs/api/resources/agents/client/Client.d.ts +3 -0
  4. package/dist/cjs/api/resources/agents/client/Client.js +3 -0
  5. package/dist/cjs/api/resources/agents/client/requests/AgentsCreateRequest.d.ts +3 -0
  6. package/dist/cjs/api/resources/agents/client/requests/UpdateAgentRequest.d.ts +3 -0
  7. package/dist/cjs/api/resources/agents/client/requests/UpsertAgentRequest.d.ts +1 -0
  8. package/dist/cjs/api/resources/conversations/client/requests/ConversationsSipOutboundCallRequest.d.ts +2 -0
  9. package/dist/cjs/api/resources/conversations/client/requests/OutboundCallRequest.d.ts +5 -1
  10. package/dist/cjs/api/resources/conversations/types/ConversationsOutboundCallResponse.d.ts +2 -4
  11. package/dist/cjs/api/resources/conversations/types/ConversationsSipOutboundCallResponse.d.ts +2 -6
  12. package/dist/cjs/api/types/Agent.d.ts +2 -0
  13. package/dist/cjs/api/types/ConfigPayload.d.ts +2 -0
  14. package/dist/cjs/api/types/Conversation.d.ts +2 -0
  15. package/dist/cjs/api/types/CreateAgentRequest.d.ts +2 -0
  16. package/dist/cjs/api/types/OutboundCallConfig.d.ts +2 -0
  17. package/dist/cjs/api/types/OutboundCallInitiatedResponse.d.ts +6 -0
  18. package/dist/cjs/api/types/{InterruptedResponsePayload.js → OutboundCallInitiatedResponse.js} +1 -3
  19. package/dist/cjs/api/types/OutboundDryRunResponse.d.ts +6 -0
  20. package/dist/cjs/api/{resources/agents/client/requests/AgentsRemoveCustomPhoneNumberRequest.js → types/OutboundDryRunResponse.js} +1 -3
  21. package/dist/cjs/api/types/SipOutboundCallInitiatedResponse.d.ts +8 -0
  22. package/dist/cjs/api/types/{AudioFinishedPayload.js → SipOutboundCallInitiatedResponse.js} +1 -3
  23. package/dist/cjs/api/types/SipOutboundDryRunResponse.d.ts +8 -0
  24. package/dist/cjs/api/{resources/agents/types/AgentsRemoveCustomPhoneNumberResponse.js → types/SipOutboundDryRunResponse.js} +1 -3
  25. package/dist/cjs/api/types/index.d.ts +4 -0
  26. package/dist/cjs/api/types/index.js +4 -0
  27. package/dist/cjs/version.d.ts +1 -1
  28. package/dist/cjs/version.js +1 -1
  29. package/dist/esm/BaseClient.mjs +2 -2
  30. package/dist/esm/api/resources/agents/client/Client.d.mts +3 -0
  31. package/dist/esm/api/resources/agents/client/Client.mjs +3 -0
  32. package/dist/esm/api/resources/agents/client/requests/AgentsCreateRequest.d.mts +3 -0
  33. package/dist/esm/api/resources/agents/client/requests/UpdateAgentRequest.d.mts +3 -0
  34. package/dist/esm/api/resources/agents/client/requests/UpsertAgentRequest.d.mts +1 -0
  35. package/dist/esm/api/resources/conversations/client/requests/ConversationsSipOutboundCallRequest.d.mts +2 -0
  36. package/dist/esm/api/resources/conversations/client/requests/OutboundCallRequest.d.mts +5 -1
  37. package/dist/esm/api/resources/conversations/types/ConversationsOutboundCallResponse.d.mts +2 -4
  38. package/dist/esm/api/resources/conversations/types/ConversationsSipOutboundCallResponse.d.mts +2 -6
  39. package/dist/esm/api/types/Agent.d.mts +2 -0
  40. package/dist/esm/api/types/ConfigPayload.d.mts +2 -0
  41. package/dist/esm/api/types/Conversation.d.mts +2 -0
  42. package/dist/esm/api/types/CreateAgentRequest.d.mts +2 -0
  43. package/dist/esm/api/types/OutboundCallConfig.d.mts +2 -0
  44. package/dist/esm/api/types/OutboundCallInitiatedResponse.d.mts +6 -0
  45. package/dist/esm/api/types/OutboundCallInitiatedResponse.mjs +2 -0
  46. package/dist/esm/api/types/OutboundDryRunResponse.d.mts +6 -0
  47. package/dist/esm/api/types/OutboundDryRunResponse.mjs +2 -0
  48. package/dist/esm/api/types/SipOutboundCallInitiatedResponse.d.mts +8 -0
  49. package/dist/esm/api/types/SipOutboundCallInitiatedResponse.mjs +2 -0
  50. package/dist/esm/api/types/SipOutboundDryRunResponse.d.mts +8 -0
  51. package/dist/esm/api/types/SipOutboundDryRunResponse.mjs +2 -0
  52. package/dist/esm/api/types/index.d.mts +4 -0
  53. package/dist/esm/api/types/index.mjs +4 -0
  54. package/dist/esm/version.d.mts +1 -1
  55. package/dist/esm/version.mjs +1 -1
  56. package/package.json +1 -1
  57. package/reference.md +6 -1
  58. package/dist/cjs/api/resources/agents/client/requests/AgentsRemoveCustomPhoneNumberRequest.d.ts +0 -16
  59. package/dist/cjs/api/resources/agents/types/AgentsRemoveCustomPhoneNumberResponse.d.ts +0 -6
  60. package/dist/cjs/api/types/AudioFinishedPayload.d.ts +0 -6
  61. package/dist/cjs/api/types/InterruptedResponsePayload.d.ts +0 -8
  62. package/dist/cjs/api/types/IsUserSpeakingPayload.d.ts +0 -8
  63. package/dist/cjs/api/types/IsUserSpeakingPayload.js +0 -5
  64. package/dist/cjs/api/types/SetTwilioCallSidPayload.d.ts +0 -8
  65. package/dist/cjs/api/types/SetTwilioCallSidPayload.js +0 -5
  66. package/dist/cjs/core/fetcher/ResponseWithBody.d.ts +0 -4
  67. package/dist/cjs/core/fetcher/ResponseWithBody.js +0 -6
  68. package/dist/esm/api/resources/agents/client/requests/AgentsRemoveCustomPhoneNumberRequest.d.mts +0 -16
  69. package/dist/esm/api/resources/agents/client/requests/AgentsRemoveCustomPhoneNumberRequest.mjs +0 -4
  70. package/dist/esm/api/resources/agents/types/AgentsRemoveCustomPhoneNumberResponse.d.mts +0 -6
  71. package/dist/esm/api/resources/agents/types/AgentsRemoveCustomPhoneNumberResponse.mjs +0 -4
  72. package/dist/esm/api/types/AudioFinishedPayload.d.mts +0 -6
  73. package/dist/esm/api/types/AudioFinishedPayload.mjs +0 -4
  74. package/dist/esm/api/types/InterruptedResponsePayload.d.mts +0 -8
  75. package/dist/esm/api/types/InterruptedResponsePayload.mjs +0 -4
  76. package/dist/esm/api/types/IsUserSpeakingPayload.d.mts +0 -8
  77. package/dist/esm/api/types/IsUserSpeakingPayload.mjs +0 -4
  78. package/dist/esm/api/types/SetTwilioCallSidPayload.d.mts +0 -8
  79. package/dist/esm/api/types/SetTwilioCallSidPayload.mjs +0 -4
  80. package/dist/esm/core/fetcher/ResponseWithBody.d.mts +0 -4
  81. package/dist/esm/core/fetcher/ResponseWithBody.mjs +0 -3
  82. package/dist/index.d.mts +0 -686
  83. package/dist/index.d.ts +0 -686
  84. package/dist/index.js +0 -643
  85. package/dist/index.mjs +0 -606
package/dist/index.d.ts DELETED
@@ -1,686 +0,0 @@
1
- import WebSocket from 'ws';
2
-
3
- type PhonicConfig = {
4
- baseUrl?: string;
5
- headers?: Record<string, string>;
6
- __downstreamWebSocketUrl?: string;
7
- };
8
- type FetchOptions = {
9
- method: "GET";
10
- headers?: Record<string, string>;
11
- } | {
12
- method: "POST";
13
- headers?: Record<string, string>;
14
- body: string;
15
- } | {
16
- method: "PATCH";
17
- headers?: Record<string, string>;
18
- body: string;
19
- } | {
20
- method: "PUT";
21
- headers?: Record<string, string>;
22
- body: string;
23
- } | {
24
- method: "DELETE";
25
- headers?: Record<string, string>;
26
- };
27
- type DataOrError<T> = Promise<{
28
- data: T;
29
- error: null;
30
- } | {
31
- data: null;
32
- error: {
33
- message: string;
34
- code?: string;
35
- param_errors?: Record<string, string>;
36
- };
37
- }>;
38
- type ISODate = `${string}-${string}-${string}`;
39
- type ISODateTime = `${string}Z`;
40
- type TaskStatus = "pending" | "completed" | "failed";
41
- type TaskResult = {
42
- name: string;
43
- description: string;
44
- status: TaskStatus;
45
- commentary: string | null;
46
- };
47
- type TaskResults = {
48
- results: Array<TaskResult>;
49
- };
50
- type ConversationItem = {
51
- role: "user";
52
- item_idx: number;
53
- text: string;
54
- duration_ms: number;
55
- started_at: string;
56
- } | {
57
- role: "assistant";
58
- item_idx: number;
59
- text: string;
60
- voice_id: string;
61
- system_prompt: string;
62
- audio_speed: number;
63
- duration_ms: number;
64
- started_at: string;
65
- };
66
- type Conversation = {
67
- id: string;
68
- external_id: string | null;
69
- workspace: string;
70
- agent: {
71
- id: string;
72
- name: string;
73
- } | null;
74
- model: string;
75
- welcome_message: string | null;
76
- input_format: "pcm_44100" | "mulaw_8000";
77
- output_format: "pcm_44100" | "mulaw_8000";
78
- live_transcript: string;
79
- post_call_transcript: string | null;
80
- audio_url: string | null;
81
- duration_ms: number;
82
- task_results: TaskResults;
83
- started_at: ISODateTime;
84
- ended_at: ISODateTime | null;
85
- items: Array<ConversationItem>;
86
- };
87
- type ConversationEndedWebhookPayload = {
88
- event_type: "conversation.ended";
89
- created_at: ISODateTime;
90
- data: {
91
- conversation: Conversation;
92
- call_info: {
93
- from_phone_number: string;
94
- to_phone_number: string;
95
- } | null;
96
- };
97
- };
98
- type ConversationAnalysisWebhookPayload = {
99
- event_type: "conversation.analysis";
100
- created_at: ISODateTime;
101
- data: {
102
- conversation: {
103
- latencies_ms: number[];
104
- interruptions_count: number;
105
- };
106
- call_info: {
107
- from_phone_number: string;
108
- to_phone_number: string;
109
- } | null;
110
- };
111
- };
112
-
113
- type PhonicSTSTool = "keypad_input" | "natural_conversation_ending" | (string & {});
114
- interface PhonicSTSConfigBase {
115
- input_format: "pcm_44100" | "mulaw_8000";
116
- output_format?: "pcm_44100" | "mulaw_8000";
117
- voice_id?: string;
118
- audio_speed?: number;
119
- welcome_message?: string;
120
- system_prompt?: string;
121
- template_variables?: Record<string, string>;
122
- enable_silent_audio_fallback?: boolean;
123
- experimental_params?: Record<string, unknown>;
124
- tools?: Array<PhonicSTSTool>;
125
- vad_prebuffer_duration_ms?: number;
126
- vad_min_speech_duration_ms?: number;
127
- vad_min_silence_duration_ms?: number;
128
- vad_threshold?: number;
129
- }
130
- interface PhonicSTSConfigWithAgent extends PhonicSTSConfigBase {
131
- agent: string;
132
- }
133
- interface PhonicSTSConfigWithProject extends PhonicSTSConfigBase {
134
- project: string;
135
- }
136
- type PhonicSTSConfig = PhonicSTSConfigWithAgent | PhonicSTSConfigWithProject;
137
- type PhonicSTSWebSocketResponseMessage = {
138
- type: "conversation_created";
139
- conversation_id: string;
140
- } | {
141
- type: "ready_to_start_conversation";
142
- } | {
143
- type: "input_text";
144
- text: string;
145
- } | {
146
- type: "audio_chunk";
147
- text: string;
148
- audio: string;
149
- } | {
150
- type: "audio_finished";
151
- } | {
152
- type: "is_user_speaking";
153
- is_user_speaking: boolean;
154
- } | {
155
- type: "user_started_speaking";
156
- } | {
157
- type: "user_finished_speaking";
158
- } | {
159
- type: "interrupted_response";
160
- text: string;
161
- } | {
162
- type: "assistant_chose_not_to_respond";
163
- } | {
164
- type: "assistant_ended_conversation";
165
- } | {
166
- type: "dtmf";
167
- digits: string;
168
- } | {
169
- type: "tool_call_output_processed";
170
- tool_call_id: string;
171
- tool: {
172
- id: string;
173
- name: string;
174
- };
175
- endpoint_url: string | null;
176
- endpoint_timeout_ms: number | null;
177
- endpoint_called_at: string | null;
178
- request_body: {
179
- call_info: {
180
- from_phone_number: string;
181
- to_phone_number: string;
182
- } | null;
183
- [key: string]: unknown;
184
- } | null;
185
- parameters: Record<string, unknown> | null;
186
- output: unknown | null;
187
- response_body: unknown | null;
188
- response_status_code: number | null;
189
- timed_out: boolean | null;
190
- error_message: string | null;
191
- } | {
192
- type: "tool_call";
193
- tool_call_id: string;
194
- tool_name: string;
195
- parameters: Record<string, unknown>;
196
- } | {
197
- type: "error";
198
- error: {
199
- message: string;
200
- code?: string;
201
- };
202
- param_errors?: {
203
- input_format?: string;
204
- system_prompt?: string;
205
- welcome_message?: string;
206
- voice_id?: string;
207
- output_format?: string;
208
- };
209
- };
210
- type OnMessageCallback = (message: PhonicSTSWebSocketResponseMessage) => void;
211
- type OnCloseCallback = (event: WebSocket.CloseEvent) => void;
212
- type OnErrorCallback = (event: WebSocket.ErrorEvent) => void;
213
- type PhonicTool = "send_dtmf_tone" | "end_conversation";
214
- type PhonicConfigurationEndpointRequestPayload = {
215
- project: {
216
- name: string;
217
- };
218
- agent: {
219
- name: string;
220
- welcome_message: string;
221
- system_prompt: string;
222
- tools: Array<PhonicTool>;
223
- boosted_keywords: string[];
224
- };
225
- from_phone_number?: string;
226
- to_phone_number?: string;
227
- };
228
- type PhonicConfigurationEndpointResponsePayload = {
229
- welcome_message?: string | null;
230
- system_prompt?: string;
231
- template_variables?: Record<string, string>;
232
- tools?: Array<PhonicTool>;
233
- boosted_keywords?: string[];
234
- };
235
-
236
- type Agent = {
237
- id: string;
238
- name: string;
239
- org_id: string;
240
- project: {
241
- id: string;
242
- name: string;
243
- };
244
- phone_number: string | null;
245
- voice_id: string;
246
- audio_format: "pcm_44100" | "mulaw_8000";
247
- welcome_message: string | null;
248
- system_prompt: string;
249
- template_variables: Record<string, {
250
- default_value: string | null;
251
- }>;
252
- tools: Array<PhonicSTSTool>;
253
- no_input_poke_sec: number | null;
254
- no_input_poke_text: string;
255
- no_input_end_conversation_sec: number;
256
- boosted_keywords: string[];
257
- configuration_endpoint: {
258
- url: string;
259
- headers: Record<string, string>;
260
- timeout_ms: number;
261
- } | null;
262
- };
263
- type ListAgentsParams = {
264
- project?: string;
265
- };
266
- type ListAgentsSuccessResponse = {
267
- agents: Array<Agent>;
268
- };
269
- type GetAgentParams = {
270
- project?: string;
271
- };
272
- type GetAgentSuccessResponse = {
273
- agent: Agent;
274
- };
275
- interface AgentOptionalParams {
276
- project?: string;
277
- timezone?: string;
278
- voiceId?: string;
279
- audioSpeed?: number;
280
- welcomeMessage?: string;
281
- systemPrompt?: string;
282
- templateVariables?: Record<string, {
283
- defaultValue: string | null;
284
- }>;
285
- tools?: Array<PhonicSTSTool>;
286
- noInputPokeSec?: number | null;
287
- noInputPokeText?: string;
288
- noInputEndConversationSec?: number;
289
- boostedKeywords?: string[];
290
- configurationEndpoint?: {
291
- url: string;
292
- headers?: Record<string, string>;
293
- timeoutMs?: number;
294
- } | null;
295
- }
296
- interface CreateAgentBaseParams extends AgentOptionalParams {
297
- name: string;
298
- }
299
- interface AgentPhoneNumberParams {
300
- phoneNumber: "assign-automatically";
301
- audioFormat?: "mulaw_8000";
302
- }
303
- interface AgentNoPhoneNumberParams {
304
- phoneNumber?: null;
305
- audioFormat?: "pcm_44100" | "mulaw_8000";
306
- }
307
- interface CreateAgentWithPhoneNumberParams extends CreateAgentBaseParams, AgentPhoneNumberParams {
308
- }
309
- interface CreateAgentWithoutPhoneNumberParams extends CreateAgentBaseParams, AgentNoPhoneNumberParams {
310
- }
311
- type CreateAgentParams = CreateAgentWithPhoneNumberParams | CreateAgentWithoutPhoneNumberParams;
312
- type CreateAgentSuccessResponse = {
313
- id: string;
314
- name: string;
315
- };
316
- interface UpdateAgentBaseParams extends AgentOptionalParams {
317
- name?: string;
318
- }
319
- interface UpdateAgentWithPhoneNumberParams extends UpdateAgentBaseParams, AgentPhoneNumberParams {
320
- }
321
- interface UpdateAgentWithoutPhoneNumberParams extends UpdateAgentBaseParams, AgentNoPhoneNumberParams {
322
- }
323
- type UpdateAgentParams = UpdateAgentWithPhoneNumberParams | UpdateAgentWithoutPhoneNumberParams;
324
- type UpdateAgentSuccessResponse = {
325
- success: true;
326
- };
327
- interface UpsertAgentBaseParams extends AgentOptionalParams {
328
- name: string;
329
- }
330
- interface UpsertAgentWithPhoneNumberParams extends UpsertAgentBaseParams, AgentPhoneNumberParams {
331
- }
332
- interface UpsertAgentWithoutPhoneNumberParams extends UpsertAgentBaseParams, AgentNoPhoneNumberParams {
333
- }
334
- type UpsertAgentParams = UpsertAgentWithPhoneNumberParams | UpsertAgentWithoutPhoneNumberParams;
335
- interface UpsertAgentSuccessResponseBase {
336
- agent: Agent;
337
- }
338
- interface UpsertAgentInsertedSuccessResponse extends UpsertAgentSuccessResponseBase {
339
- inserted: true;
340
- updated: false;
341
- }
342
- interface UpsertAgentUpdatedSuccessResponse extends UpsertAgentSuccessResponseBase {
343
- inserted: false;
344
- updated: true;
345
- }
346
- type UpsertAgentSuccessResponse = UpsertAgentInsertedSuccessResponse | UpsertAgentUpdatedSuccessResponse;
347
- type DeleteAgentParams = {
348
- project?: string;
349
- };
350
- type DeleteAgentSuccessResponse = {
351
- success: true;
352
- };
353
-
354
- declare class Agents {
355
- private readonly phonic;
356
- constructor(phonic: Phonic);
357
- private getQueryString;
358
- private getTemplateVariablesForBody;
359
- private getConfigurationEndpointForBody;
360
- list(params?: ListAgentsParams): DataOrError<ListAgentsSuccessResponse>;
361
- get(nameOrId: string, params?: GetAgentParams): DataOrError<GetAgentSuccessResponse>;
362
- create(params: CreateAgentParams): DataOrError<CreateAgentSuccessResponse>;
363
- update(nameOrId: string, params: UpdateAgentParams): DataOrError<UpdateAgentSuccessResponse>;
364
- upsert(params: UpsertAgentParams): DataOrError<UpsertAgentSuccessResponse>;
365
- delete(nameOrId: string, params?: DeleteAgentParams): DataOrError<DeleteAgentSuccessResponse>;
366
- }
367
-
368
- type ConversationSuccessResponse = {
369
- conversation: Conversation;
370
- };
371
- type ConversationsSuccessResponse = {
372
- conversations: Array<Conversation>;
373
- };
374
- type OutboundCallConfig = Omit<PhonicSTSConfigWithAgent, "input_format" | "output_format"> | Omit<PhonicSTSConfigWithProject, "input_format" | "output_format">;
375
- type OutboundCallSuccessResponse = {
376
- conversation_id: string;
377
- };
378
-
379
- type TwilioOutboundCallParams = {
380
- account_sid: string;
381
- api_key_sid: string;
382
- api_key_secret: string;
383
- from_phone_number: string;
384
- to_phone_number: string;
385
- };
386
- type TwilioOutboundCallConfig = OutboundCallConfig;
387
- type TwilioOutboundCallSuccessResponse = {
388
- callSid: string;
389
- };
390
-
391
- declare class Twilio {
392
- private readonly phonic;
393
- constructor(phonic: Phonic);
394
- outboundCall(params: TwilioOutboundCallParams, config: TwilioOutboundCallConfig): DataOrError<TwilioOutboundCallSuccessResponse>;
395
- }
396
-
397
- declare class Conversations {
398
- private readonly phonic;
399
- readonly twilio: Twilio;
400
- constructor(phonic: Phonic);
401
- list({ project, durationMin, durationMax, startedAtMin, startedAtMax, }: {
402
- project?: string;
403
- durationMin?: number;
404
- durationMax?: number;
405
- startedAtMin?: ISODate | ISODateTime;
406
- startedAtMax?: ISODate | ISODateTime;
407
- }): DataOrError<ConversationsSuccessResponse>;
408
- get(id: string): DataOrError<ConversationSuccessResponse>;
409
- getByExternalId({ project, externalId, }: {
410
- project?: string;
411
- externalId: string;
412
- }): DataOrError<ConversationSuccessResponse>;
413
- outboundCall(toPhoneNumber: string, config: OutboundCallConfig): DataOrError<OutboundCallSuccessResponse>;
414
- }
415
-
416
- type Project = {
417
- id: string;
418
- name: string;
419
- default_agent: {
420
- id: string;
421
- name: string;
422
- } | null;
423
- };
424
- type ListProjectsSuccessResponse = {
425
- projects: Array<Project>;
426
- };
427
- type GetProjectSuccessResponse = {
428
- project: Project;
429
- };
430
- type CreateProjectParams = {
431
- name: string;
432
- };
433
- type CreateProjectSuccessResponse = {
434
- id: string;
435
- name: string;
436
- };
437
- type UpdateProjectParams = {
438
- name?: string;
439
- defaultAgent?: string;
440
- };
441
- type UpdateProjectSuccessResponse = {
442
- success: true;
443
- };
444
- type DeleteProjectSuccessResponse = {
445
- success: true;
446
- };
447
-
448
- declare class Projects {
449
- private readonly phonic;
450
- constructor(phonic: Phonic);
451
- list(): DataOrError<ListProjectsSuccessResponse>;
452
- get(nameOrId: string): DataOrError<GetProjectSuccessResponse>;
453
- create(params: CreateProjectParams): DataOrError<CreateProjectSuccessResponse>;
454
- update(nameOrId: string, params: UpdateProjectParams): DataOrError<UpdateProjectSuccessResponse>;
455
- delete(nameOrId: string): DataOrError<DeleteProjectSuccessResponse>;
456
- }
457
-
458
- declare class PhonicSTSWebSocket {
459
- private readonly ws;
460
- private readonly config;
461
- private onMessageCallback;
462
- private onCloseCallback;
463
- private onErrorCallback;
464
- private buffer;
465
- private isOpen;
466
- constructor(ws: WebSocket, config: PhonicSTSConfig);
467
- private processUserMessage;
468
- onMessage(callback: OnMessageCallback): void;
469
- onClose(callback: OnCloseCallback): void;
470
- onError(callback: OnErrorCallback): void;
471
- audioChunk({ audio }: {
472
- audio: string;
473
- }): void;
474
- sendToolCallOutput({ toolCallId, output, }: {
475
- toolCallId: string;
476
- output: unknown;
477
- }): void;
478
- updateSystemPrompt({ systemPrompt }: {
479
- systemPrompt: string;
480
- }): void;
481
- setExternalId({ externalId }: {
482
- externalId: string;
483
- }): void;
484
- close(code?: number): void;
485
- }
486
-
487
- declare class SpeechToSpeech {
488
- private readonly phonic;
489
- constructor(phonic: Phonic);
490
- websocket(config: PhonicSTSConfig): PhonicSTSWebSocket;
491
- }
492
-
493
- interface ParameterBase {
494
- name: string;
495
- description: string;
496
- isRequired: boolean;
497
- }
498
- interface PrimitiveParameter extends ParameterBase {
499
- type: "string" | "integer" | "number" | "boolean";
500
- }
501
- interface ArrayParameter extends ParameterBase {
502
- type: "array";
503
- itemType: "string" | "integer" | "number" | "boolean";
504
- }
505
- type ToolParameters = Array<PrimitiveParameter | ArrayParameter>;
506
- type ExecutionMode = "sync" | "async";
507
- interface ToolBase {
508
- id: string;
509
- name: string;
510
- description: string;
511
- execution_mode: ExecutionMode;
512
- parameters: ToolParameters;
513
- }
514
- interface WebhookTool extends ToolBase {
515
- type: "custom_webhook";
516
- endpoint_method: "POST";
517
- endpoint_url: string;
518
- endpoint_headers: Record<string, string>;
519
- endpoint_timeout_ms: number;
520
- }
521
- interface WebSocketTool extends ToolBase {
522
- type: "custom_websocket";
523
- tool_call_output_timeout_ms: number;
524
- }
525
- type Tool = WebhookTool | WebSocketTool;
526
- type ListToolsParams = {
527
- project?: string;
528
- };
529
- type ListToolsSuccessResponse = DataOrError<{
530
- tools: Array<Tool>;
531
- }>;
532
- type GetToolParams = {
533
- project?: string;
534
- };
535
- type GetToolSuccessResponse = DataOrError<{
536
- tool: Tool;
537
- }>;
538
- interface CreateToolParamsBase {
539
- project?: string;
540
- name: string;
541
- description: string;
542
- executionMode: ExecutionMode;
543
- parameters?: ToolParameters;
544
- }
545
- interface CreateWebhookToolParams extends CreateToolParamsBase {
546
- type: "custom_webhook";
547
- endpointMethod: "POST";
548
- endpointUrl: string;
549
- endpointHeaders?: Record<string, string>;
550
- endpointTimeoutMs?: number;
551
- }
552
- interface CreateWebSocketToolParams extends CreateToolParamsBase {
553
- type: "custom_websocket";
554
- toolCallOutputTimeoutMs?: number;
555
- }
556
- type CreateToolParams = CreateWebhookToolParams | CreateWebSocketToolParams;
557
- type CreateToolSuccessResponse = {
558
- id: string;
559
- name: string;
560
- };
561
- type UpdateToolParams = {
562
- project?: string;
563
- name?: string;
564
- description?: string;
565
- type?: "custom_webhook" | "custom_websocket";
566
- executionMode?: ExecutionMode;
567
- endpointMethod?: "POST";
568
- endpointUrl?: string;
569
- endpointHeaders?: Record<string, string>;
570
- endpointTimeoutMs?: number;
571
- toolCallOutputTimeoutMs?: number;
572
- parameters?: ToolParameters;
573
- };
574
- type UpdateToolSuccessResponse = {
575
- success: true;
576
- };
577
- type DeleteToolParams = {
578
- project?: string;
579
- };
580
- type DeleteToolSuccessResponse = {
581
- success: true;
582
- };
583
-
584
- declare class Tools {
585
- private readonly phonic;
586
- constructor(phonic: Phonic);
587
- private getQueryString;
588
- private getParametersForBody;
589
- list(params?: ListToolsParams): DataOrError<ListToolsSuccessResponse>;
590
- get(nameOrId: string, params?: GetToolParams): DataOrError<GetToolSuccessResponse>;
591
- create(params: CreateToolParams): DataOrError<CreateToolSuccessResponse>;
592
- update(nameOrId: string, params: UpdateToolParams): DataOrError<UpdateToolSuccessResponse>;
593
- delete(nameOrId: string, params?: DeleteToolParams): DataOrError<DeleteToolSuccessResponse>;
594
- }
595
-
596
- type Voice = {
597
- id: string;
598
- name: string;
599
- };
600
- type VoicesSuccessResponse = {
601
- voices: Array<Voice>;
602
- };
603
- type VoiceSuccessResponse = {
604
- voice: Voice;
605
- };
606
-
607
- declare class Voices {
608
- private readonly phonic;
609
- constructor(phonic: Phonic);
610
- list({ model }: {
611
- model: string;
612
- }): DataOrError<VoicesSuccessResponse>;
613
- get(id: string): DataOrError<VoiceSuccessResponse>;
614
- }
615
-
616
- declare class Phonic {
617
- readonly apiKey: string;
618
- readonly baseUrl: string;
619
- readonly __downstreamWebSocketUrl: string | null;
620
- readonly headers: Record<string, string>;
621
- readonly agents: Agents;
622
- readonly conversations: Conversations;
623
- readonly projects: Projects;
624
- readonly tools: Tools;
625
- readonly voices: Voices;
626
- readonly sts: SpeechToSpeech;
627
- constructor(apiKey: string, config?: PhonicConfig);
628
- fetchRequest<T>(path: string, options: FetchOptions): DataOrError<T>;
629
- get<T>(path: string): Promise<{
630
- data: null;
631
- error: {
632
- message: string;
633
- code?: string;
634
- param_errors?: Record<string, string>;
635
- };
636
- } | {
637
- data: T;
638
- error: null;
639
- }>;
640
- post<T>(path: string, body: Record<string, unknown>, headers?: Record<string, string>): Promise<{
641
- data: null;
642
- error: {
643
- message: string;
644
- code?: string;
645
- param_errors?: Record<string, string>;
646
- };
647
- } | {
648
- data: T;
649
- error: null;
650
- }>;
651
- patch<T>(path: string, body: Record<string, unknown>, headers?: Record<string, string>): Promise<{
652
- data: null;
653
- error: {
654
- message: string;
655
- code?: string;
656
- param_errors?: Record<string, string>;
657
- };
658
- } | {
659
- data: T;
660
- error: null;
661
- }>;
662
- put<T>(path: string, body: Record<string, unknown>, headers?: Record<string, string>): Promise<{
663
- data: null;
664
- error: {
665
- message: string;
666
- code?: string;
667
- param_errors?: Record<string, string>;
668
- };
669
- } | {
670
- data: T;
671
- error: null;
672
- }>;
673
- delete<T>(path: string, headers?: Record<string, string>): Promise<{
674
- data: null;
675
- error: {
676
- message: string;
677
- code?: string;
678
- param_errors?: Record<string, string>;
679
- };
680
- } | {
681
- data: T;
682
- error: null;
683
- }>;
684
- }
685
-
686
- export { type ConversationAnalysisWebhookPayload, type ConversationEndedWebhookPayload, Phonic, type PhonicConfigurationEndpointRequestPayload, type PhonicConfigurationEndpointResponsePayload, type PhonicSTSConfig, PhonicSTSWebSocket, type PhonicSTSWebSocketResponseMessage };