phonic 0.22.0 → 0.24.0

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 CHANGED
@@ -10,6 +10,12 @@ Node.js library for the Phonic API.
10
10
  - [Create agent](#create-agent)
11
11
  - [Update agent](#update-agent)
12
12
  - [Delete agent](#delete-agent)
13
+ - [Tools](#tools)
14
+ - [List tools](#list-tools)
15
+ - [Get tool](#get-tool)
16
+ - [Create tool](#create-tool)
17
+ - [Update tool](#update-tool)
18
+ - [Delete tool](#delete-tool)
13
19
  - [Voices](#voices)
14
20
  - [List voices](#list-voices)
15
21
  - [Get voice](#get-voice)
@@ -17,8 +23,8 @@ Node.js library for the Phonic API.
17
23
  - [List conversations](#list-conversations)
18
24
  - [Get conversation by id](#get-conversation-by-id)
19
25
  - [Get conversation by external id](#get-conversation-by-external-id)
20
- - [STS outbound call](#sts-outbound-call)
21
- - [STS outbound call using own Twilio account](#sts-outbound-call-using-own-twilio-account)
26
+ - [Outbound call](#outbound-call)
27
+ - [Outbound call using own Twilio account](#outbound-call-using-own-twilio-account)
22
28
  - [STS via WebSocket](#sts-via-websocket)
23
29
  - [Messages that Phonic sends back to you](#messages-that-phonic-sends-back-to-you)
24
30
  - [License](#license)
@@ -138,6 +144,97 @@ const deleteAgentResult = await phonic.agents.delete({
138
144
  });
139
145
  ```
140
146
 
147
+ ## Tools
148
+
149
+ ### List tools
150
+
151
+ ```ts
152
+ const toolsResult = await phonic.tools.list();
153
+ ```
154
+
155
+ ### Get tool
156
+
157
+ ```ts
158
+ const toolResult = await phonic.tools.get("next_invoice");
159
+ ```
160
+
161
+ ### Create tool
162
+
163
+ ```ts
164
+ const createToolResult = await phonic.tools.create({
165
+ name: "next_invoice",
166
+ description: "Returns the next invoice of the given user",
167
+ endpointUrl: "https://myapp.com/webhooks/next-invoice",
168
+ endpointHeaders: {
169
+ Authorization: "Bearer 123"
170
+ },
171
+ endpointTimeoutMs: 20000, // Optional, defaults to 15000
172
+ parameters: [
173
+ {
174
+ type: "string",
175
+ name: "user",
176
+ description: "Full name of the user to get the invoice for",
177
+ isRequired: true
178
+ },
179
+ {
180
+ type: "array",
181
+ itemType: "string",
182
+ name: "invoice_items",
183
+ description: "List of invoice items",
184
+ isRequired: false
185
+ },
186
+ {
187
+ type: "number",
188
+ name: "invoice_total",
189
+ description: "Total invoice amount in USD",
190
+ isRequired: true
191
+ },
192
+ ]
193
+ });
194
+ ```
195
+
196
+ ### Update tool
197
+
198
+ ```ts
199
+ const updateToolResult = await phonic.tools.update("next_invoice", {
200
+ name: "next_invoice_updated",
201
+ description: "Updated description.",
202
+ endpointUrl: "https://myapp.com/webhooks/next-invoice-updated",
203
+ endpointHeaders: {
204
+ Authorization: "Bearer 456"
205
+ },
206
+ endpointTimeoutMs: 30000,
207
+ parameters: [
208
+ {
209
+ type: "string",
210
+ name: "user",
211
+ description: "Full name of the user to get the invoice for",
212
+ isRequired: true
213
+ },
214
+ {
215
+ type: "array",
216
+ itemType: "string",
217
+ name: "invoice_items",
218
+ description: "List of invoice items",
219
+ isRequired: true
220
+ },
221
+ {
222
+ type: "number",
223
+ name: "invoice_total",
224
+ description: "Total invoice amount in USD",
225
+ isRequired: true
226
+ },
227
+ ]
228
+ });
229
+ ```
230
+
231
+ ### Delete tool
232
+
233
+ ```ts
234
+ const deleteToolResult = await phonic.tools.delete("next_invoice");
235
+ ```
236
+
237
+
141
238
  ## Voices
142
239
 
143
240
  ### List voices
@@ -183,11 +280,10 @@ const conversationResult = await phonic.conversations.getByExternalId({
183
280
  });
184
281
  ```
185
282
 
186
-
187
- ## STS outbound call
283
+ ### Outbound call
188
284
 
189
285
  ```ts
190
- const { data, error } = await phonic.sts.outboundCall("+19189396241", {
286
+ const outboundCallResult = await phonic.conversations.outboundCall("+19189396241", {
191
287
  // Optional fields
192
288
  welcome_message: "Hello, how can I help you?",
193
289
  project: "main",
@@ -198,16 +294,16 @@ const { data, error } = await phonic.sts.outboundCall("+19189396241", {
198
294
  vad_min_speech_duration_ms: 40,
199
295
  vad_min_silence_duration_ms: 550,
200
296
  vad_threshold: 0.6,
201
- tools: ["send_dtmf_tone", "end_conversation"], // these are the only available tools so far
297
+ tools: ["keypad_input", "natural_conversation_ending"]
202
298
  });
203
299
  ```
204
300
 
205
- ## STS outbound call using own Twilio account
301
+ ### Outbound call using own Twilio account
206
302
 
207
303
  In Twilio, create a restricted API key with the following permissions: `voice -> calls -> read` and `voice -> calls -> create`.
208
304
 
209
305
  ```ts
210
- const { data, error } = await phonic.sts.twilio.outboundCall(
306
+ const twilioOutboundCallResult = await phonic.conversations.twilio.outboundCall(
211
307
  {
212
308
  account_sid: "AC...",
213
309
  api_key_sid: "SK...",
@@ -226,7 +322,7 @@ const { data, error } = await phonic.sts.twilio.outboundCall(
226
322
  vad_min_speech_duration_ms: 40,
227
323
  vad_min_silence_duration_ms: 550,
228
324
  vad_threshold: 0.6,
229
- tools: ["send_dtmf_tone", "end_conversation"], // these are the only available tools so far
325
+ tools: ["keypad_input", "natural_conversation_ending"]
230
326
  }
231
327
  );
232
328
  ```
@@ -250,7 +346,7 @@ const phonicWebSocket = phonic.sts.websocket({
250
346
  vad_min_speech_duration_ms: 40,
251
347
  vad_min_silence_duration_ms: 550,
252
348
  vad_threshold: 0.6,
253
- tools: ["send_dtmf_tone", "end_conversation"], // these are the only available tools so far
349
+ tools: ["keypad_input", "natural_conversation_ending"]
254
350
  });
255
351
  ```
256
352
 
package/dist/index.d.mts CHANGED
@@ -90,10 +90,6 @@ type PhonicSTSWebSocketResponseMessage = {
90
90
  type OnMessageCallback = (message: PhonicSTSWebSocketResponseMessage) => void;
91
91
  type OnCloseCallback = (event: WebSocket.CloseEvent) => void;
92
92
  type OnErrorCallback = (event: WebSocket.ErrorEvent) => void;
93
- type PhonicSTSOutboundCallConfig = Omit<PhonicSTSConfig, "input_format" | "output_format">;
94
- type OutboundCallSuccessResponse = {
95
- success: true;
96
- };
97
93
  type PhonicTool = "send_dtmf_tone" | "end_conversation";
98
94
  type PhonicConfigurationEndpointRequestPayload = {
99
95
  project: {
@@ -144,10 +140,10 @@ type Agent = {
144
140
  timeout_ms: number;
145
141
  } | null;
146
142
  };
147
- type ListAgentParams = {
143
+ type ListAgentsParams = {
148
144
  project?: string;
149
145
  };
150
- type ListAgentSuccessResponse = DataOrError<{
146
+ type ListAgentsSuccessResponse = DataOrError<{
151
147
  agents: Array<Agent>;
152
148
  }>;
153
149
  type GetAgentParams = {
@@ -220,7 +216,7 @@ declare class Agents {
220
216
  private getQueryString;
221
217
  private getTemplateVariablesForBody;
222
218
  private getConfigurationEndpointForBody;
223
- list(params?: ListAgentParams): DataOrError<ListAgentSuccessResponse>;
219
+ list(params?: ListAgentsParams): DataOrError<ListAgentsSuccessResponse>;
224
220
  get(name: string, params?: GetAgentParams): DataOrError<GetAgentSuccessResponse>;
225
221
  create(params: CreateAgentParams): DataOrError<CreateAgentSuccessResponse>;
226
222
  update(name: string, params: UpdateAgentParams): DataOrError<UpdateAgentSuccessResponse>;
@@ -263,41 +259,46 @@ type ConversationSuccessResponse = {
263
259
  type ConversationsSuccessResponse = {
264
260
  conversations: Array<Conversation>;
265
261
  };
262
+ type OutboundCallConfig = Omit<PhonicSTSConfigWithAgent, "input_format" | "output_format"> | Omit<PhonicSTSConfigWithProject, "input_format" | "output_format">;
263
+ type OutboundCallSuccessResponse = {
264
+ conversation_id: string;
265
+ };
266
266
 
267
- declare class Conversations {
268
- private readonly phonic;
269
- constructor(phonic: Phonic);
270
- get(id: string): DataOrError<ConversationSuccessResponse>;
271
- getByExternalId({ project, externalId, }: {
272
- project?: string;
273
- externalId: string;
274
- }): DataOrError<ConversationSuccessResponse>;
275
- list({ project, durationMin, durationMax, startedAtMin, startedAtMax, }: {
276
- project?: string;
277
- durationMin?: number;
278
- durationMax?: number;
279
- startedAtMin?: ISODate | ISODateTime$1;
280
- startedAtMax?: ISODate | ISODateTime$1;
281
- }): DataOrError<ConversationsSuccessResponse>;
282
- }
283
-
284
- type PhonicSTSTwilioOutboundCallParams = {
267
+ type TwilioOutboundCallParams = {
285
268
  account_sid: string;
286
269
  api_key_sid: string;
287
270
  api_key_secret: string;
288
271
  from_phone_number: string;
289
272
  to_phone_number: string;
290
273
  };
291
- type PhonicSTSTwilioOutboundCallConfig = PhonicSTSOutboundCallConfig;
274
+ type TwilioOutboundCallConfig = OutboundCallConfig;
292
275
  type TwilioOutboundCallSuccessResponse = {
293
- success: true;
294
276
  callSid: string;
295
277
  };
296
278
 
297
279
  declare class Twilio {
298
280
  private readonly phonic;
299
281
  constructor(phonic: Phonic);
300
- outboundCall(params: PhonicSTSTwilioOutboundCallParams, config: PhonicSTSTwilioOutboundCallConfig): DataOrError<TwilioOutboundCallSuccessResponse>;
282
+ outboundCall(params: TwilioOutboundCallParams, config: TwilioOutboundCallConfig): DataOrError<TwilioOutboundCallSuccessResponse>;
283
+ }
284
+
285
+ declare class Conversations {
286
+ private readonly phonic;
287
+ readonly twilio: Twilio;
288
+ constructor(phonic: Phonic);
289
+ list({ project, durationMin, durationMax, startedAtMin, startedAtMax, }: {
290
+ project?: string;
291
+ durationMin?: number;
292
+ durationMax?: number;
293
+ startedAtMin?: ISODate | ISODateTime$1;
294
+ startedAtMax?: ISODate | ISODateTime$1;
295
+ }): DataOrError<ConversationsSuccessResponse>;
296
+ get(id: string): DataOrError<ConversationSuccessResponse>;
297
+ getByExternalId({ project, externalId, }: {
298
+ project?: string;
299
+ externalId: string;
300
+ }): DataOrError<ConversationSuccessResponse>;
301
+ outboundCall(toPhoneNumber: string, config: OutboundCallConfig): DataOrError<OutboundCallSuccessResponse>;
301
302
  }
302
303
 
303
304
  declare class PhonicSTSWebSocket {
@@ -326,10 +327,74 @@ declare class PhonicSTSWebSocket {
326
327
 
327
328
  declare class SpeechToSpeech {
328
329
  private readonly phonic;
329
- readonly twilio: Twilio;
330
330
  constructor(phonic: Phonic);
331
331
  websocket(config: PhonicSTSConfig): PhonicSTSWebSocket;
332
- outboundCall(toPhoneNumber: string, config: PhonicSTSOutboundCallConfig): DataOrError<OutboundCallSuccessResponse>;
332
+ }
333
+
334
+ interface ParameterBase {
335
+ name: string;
336
+ description: string;
337
+ isRequired: boolean;
338
+ }
339
+ interface PrimitiveParameter extends ParameterBase {
340
+ type: "string" | "integer" | "number" | "boolean";
341
+ }
342
+ interface ArrayParameter extends ParameterBase {
343
+ type: "array";
344
+ itemType: "string" | "integer" | "number" | "boolean";
345
+ }
346
+ type ToolParameters = Array<PrimitiveParameter | ArrayParameter>;
347
+ type Tool = {
348
+ id: string;
349
+ name: string;
350
+ description: string;
351
+ endpoint_url: string;
352
+ endpoint_headers: Record<string, string>;
353
+ endpoint_timeout_ms: number;
354
+ parameters: ToolParameters;
355
+ };
356
+ type ListToolsSuccessResponse = DataOrError<{
357
+ tools: Array<Tool>;
358
+ }>;
359
+ type GetToolSuccessResponse = DataOrError<{
360
+ tool: Tool;
361
+ }>;
362
+ type CreateToolParams = {
363
+ name: string;
364
+ description: string;
365
+ endpointUrl: string;
366
+ endpointHeaders?: Record<string, string>;
367
+ endpointTimeoutMs?: number;
368
+ parameters?: ToolParameters;
369
+ };
370
+ type CreateToolSuccessResponse = {
371
+ id: string;
372
+ name: string;
373
+ };
374
+ type UpdateToolParams = {
375
+ name?: string;
376
+ description?: string;
377
+ endpointUrl?: string;
378
+ endpointHeaders?: Record<string, string>;
379
+ endpointTimeoutMs?: number;
380
+ parameters?: Array<PrimitiveParameter | ArrayParameter>;
381
+ };
382
+ type UpdateToolSuccessResponse = {
383
+ success: true;
384
+ };
385
+ type DeleteToolSuccessResponse = {
386
+ success: true;
387
+ };
388
+
389
+ declare class Tools {
390
+ private readonly phonic;
391
+ constructor(phonic: Phonic);
392
+ private getParametersForBody;
393
+ list(): DataOrError<ListToolsSuccessResponse>;
394
+ get(name: string): DataOrError<GetToolSuccessResponse>;
395
+ create(params: CreateToolParams): DataOrError<CreateToolSuccessResponse>;
396
+ update(name: string, params: UpdateToolParams): DataOrError<UpdateToolSuccessResponse>;
397
+ delete(name: string): DataOrError<DeleteToolSuccessResponse>;
333
398
  }
334
399
 
335
400
  type Voice = {
@@ -359,6 +424,7 @@ declare class Phonic {
359
424
  readonly headers: Record<string, string>;
360
425
  readonly agents: Agents;
361
426
  readonly conversations: Conversations;
427
+ readonly tools: Tools;
362
428
  readonly voices: Voices;
363
429
  readonly sts: SpeechToSpeech;
364
430
  constructor(apiKey: string, config?: PhonicConfig);
package/dist/index.d.ts CHANGED
@@ -90,10 +90,6 @@ type PhonicSTSWebSocketResponseMessage = {
90
90
  type OnMessageCallback = (message: PhonicSTSWebSocketResponseMessage) => void;
91
91
  type OnCloseCallback = (event: WebSocket.CloseEvent) => void;
92
92
  type OnErrorCallback = (event: WebSocket.ErrorEvent) => void;
93
- type PhonicSTSOutboundCallConfig = Omit<PhonicSTSConfig, "input_format" | "output_format">;
94
- type OutboundCallSuccessResponse = {
95
- success: true;
96
- };
97
93
  type PhonicTool = "send_dtmf_tone" | "end_conversation";
98
94
  type PhonicConfigurationEndpointRequestPayload = {
99
95
  project: {
@@ -144,10 +140,10 @@ type Agent = {
144
140
  timeout_ms: number;
145
141
  } | null;
146
142
  };
147
- type ListAgentParams = {
143
+ type ListAgentsParams = {
148
144
  project?: string;
149
145
  };
150
- type ListAgentSuccessResponse = DataOrError<{
146
+ type ListAgentsSuccessResponse = DataOrError<{
151
147
  agents: Array<Agent>;
152
148
  }>;
153
149
  type GetAgentParams = {
@@ -220,7 +216,7 @@ declare class Agents {
220
216
  private getQueryString;
221
217
  private getTemplateVariablesForBody;
222
218
  private getConfigurationEndpointForBody;
223
- list(params?: ListAgentParams): DataOrError<ListAgentSuccessResponse>;
219
+ list(params?: ListAgentsParams): DataOrError<ListAgentsSuccessResponse>;
224
220
  get(name: string, params?: GetAgentParams): DataOrError<GetAgentSuccessResponse>;
225
221
  create(params: CreateAgentParams): DataOrError<CreateAgentSuccessResponse>;
226
222
  update(name: string, params: UpdateAgentParams): DataOrError<UpdateAgentSuccessResponse>;
@@ -263,41 +259,46 @@ type ConversationSuccessResponse = {
263
259
  type ConversationsSuccessResponse = {
264
260
  conversations: Array<Conversation>;
265
261
  };
262
+ type OutboundCallConfig = Omit<PhonicSTSConfigWithAgent, "input_format" | "output_format"> | Omit<PhonicSTSConfigWithProject, "input_format" | "output_format">;
263
+ type OutboundCallSuccessResponse = {
264
+ conversation_id: string;
265
+ };
266
266
 
267
- declare class Conversations {
268
- private readonly phonic;
269
- constructor(phonic: Phonic);
270
- get(id: string): DataOrError<ConversationSuccessResponse>;
271
- getByExternalId({ project, externalId, }: {
272
- project?: string;
273
- externalId: string;
274
- }): DataOrError<ConversationSuccessResponse>;
275
- list({ project, durationMin, durationMax, startedAtMin, startedAtMax, }: {
276
- project?: string;
277
- durationMin?: number;
278
- durationMax?: number;
279
- startedAtMin?: ISODate | ISODateTime$1;
280
- startedAtMax?: ISODate | ISODateTime$1;
281
- }): DataOrError<ConversationsSuccessResponse>;
282
- }
283
-
284
- type PhonicSTSTwilioOutboundCallParams = {
267
+ type TwilioOutboundCallParams = {
285
268
  account_sid: string;
286
269
  api_key_sid: string;
287
270
  api_key_secret: string;
288
271
  from_phone_number: string;
289
272
  to_phone_number: string;
290
273
  };
291
- type PhonicSTSTwilioOutboundCallConfig = PhonicSTSOutboundCallConfig;
274
+ type TwilioOutboundCallConfig = OutboundCallConfig;
292
275
  type TwilioOutboundCallSuccessResponse = {
293
- success: true;
294
276
  callSid: string;
295
277
  };
296
278
 
297
279
  declare class Twilio {
298
280
  private readonly phonic;
299
281
  constructor(phonic: Phonic);
300
- outboundCall(params: PhonicSTSTwilioOutboundCallParams, config: PhonicSTSTwilioOutboundCallConfig): DataOrError<TwilioOutboundCallSuccessResponse>;
282
+ outboundCall(params: TwilioOutboundCallParams, config: TwilioOutboundCallConfig): DataOrError<TwilioOutboundCallSuccessResponse>;
283
+ }
284
+
285
+ declare class Conversations {
286
+ private readonly phonic;
287
+ readonly twilio: Twilio;
288
+ constructor(phonic: Phonic);
289
+ list({ project, durationMin, durationMax, startedAtMin, startedAtMax, }: {
290
+ project?: string;
291
+ durationMin?: number;
292
+ durationMax?: number;
293
+ startedAtMin?: ISODate | ISODateTime$1;
294
+ startedAtMax?: ISODate | ISODateTime$1;
295
+ }): DataOrError<ConversationsSuccessResponse>;
296
+ get(id: string): DataOrError<ConversationSuccessResponse>;
297
+ getByExternalId({ project, externalId, }: {
298
+ project?: string;
299
+ externalId: string;
300
+ }): DataOrError<ConversationSuccessResponse>;
301
+ outboundCall(toPhoneNumber: string, config: OutboundCallConfig): DataOrError<OutboundCallSuccessResponse>;
301
302
  }
302
303
 
303
304
  declare class PhonicSTSWebSocket {
@@ -326,10 +327,74 @@ declare class PhonicSTSWebSocket {
326
327
 
327
328
  declare class SpeechToSpeech {
328
329
  private readonly phonic;
329
- readonly twilio: Twilio;
330
330
  constructor(phonic: Phonic);
331
331
  websocket(config: PhonicSTSConfig): PhonicSTSWebSocket;
332
- outboundCall(toPhoneNumber: string, config: PhonicSTSOutboundCallConfig): DataOrError<OutboundCallSuccessResponse>;
332
+ }
333
+
334
+ interface ParameterBase {
335
+ name: string;
336
+ description: string;
337
+ isRequired: boolean;
338
+ }
339
+ interface PrimitiveParameter extends ParameterBase {
340
+ type: "string" | "integer" | "number" | "boolean";
341
+ }
342
+ interface ArrayParameter extends ParameterBase {
343
+ type: "array";
344
+ itemType: "string" | "integer" | "number" | "boolean";
345
+ }
346
+ type ToolParameters = Array<PrimitiveParameter | ArrayParameter>;
347
+ type Tool = {
348
+ id: string;
349
+ name: string;
350
+ description: string;
351
+ endpoint_url: string;
352
+ endpoint_headers: Record<string, string>;
353
+ endpoint_timeout_ms: number;
354
+ parameters: ToolParameters;
355
+ };
356
+ type ListToolsSuccessResponse = DataOrError<{
357
+ tools: Array<Tool>;
358
+ }>;
359
+ type GetToolSuccessResponse = DataOrError<{
360
+ tool: Tool;
361
+ }>;
362
+ type CreateToolParams = {
363
+ name: string;
364
+ description: string;
365
+ endpointUrl: string;
366
+ endpointHeaders?: Record<string, string>;
367
+ endpointTimeoutMs?: number;
368
+ parameters?: ToolParameters;
369
+ };
370
+ type CreateToolSuccessResponse = {
371
+ id: string;
372
+ name: string;
373
+ };
374
+ type UpdateToolParams = {
375
+ name?: string;
376
+ description?: string;
377
+ endpointUrl?: string;
378
+ endpointHeaders?: Record<string, string>;
379
+ endpointTimeoutMs?: number;
380
+ parameters?: Array<PrimitiveParameter | ArrayParameter>;
381
+ };
382
+ type UpdateToolSuccessResponse = {
383
+ success: true;
384
+ };
385
+ type DeleteToolSuccessResponse = {
386
+ success: true;
387
+ };
388
+
389
+ declare class Tools {
390
+ private readonly phonic;
391
+ constructor(phonic: Phonic);
392
+ private getParametersForBody;
393
+ list(): DataOrError<ListToolsSuccessResponse>;
394
+ get(name: string): DataOrError<GetToolSuccessResponse>;
395
+ create(params: CreateToolParams): DataOrError<CreateToolSuccessResponse>;
396
+ update(name: string, params: UpdateToolParams): DataOrError<UpdateToolSuccessResponse>;
397
+ delete(name: string): DataOrError<DeleteToolSuccessResponse>;
333
398
  }
334
399
 
335
400
  type Voice = {
@@ -359,6 +424,7 @@ declare class Phonic {
359
424
  readonly headers: Record<string, string>;
360
425
  readonly agents: Agents;
361
426
  readonly conversations: Conversations;
427
+ readonly tools: Tools;
362
428
  readonly voices: Voices;
363
429
  readonly sts: SpeechToSpeech;
364
430
  constructor(apiKey: string, config?: PhonicConfig);
package/dist/index.js CHANGED
@@ -35,7 +35,7 @@ __export(index_exports, {
35
35
  module.exports = __toCommonJS(index_exports);
36
36
 
37
37
  // package.json
38
- var version = "0.22.0";
38
+ var version = "0.24.0";
39
39
 
40
40
  // src/agents/index.ts
41
41
  var Agents = class {
@@ -144,30 +144,36 @@ var Agents = class {
144
144
  }
145
145
  };
146
146
 
147
- // src/conversations/index.ts
148
- var Conversations = class {
147
+ // src/conversations/twilio/index.ts
148
+ var Twilio = class {
149
149
  constructor(phonic) {
150
150
  this.phonic = phonic;
151
151
  }
152
- async get(id) {
153
- const response = await this.phonic.get(
154
- `/conversations/${id}`
152
+ async outboundCall(params, config) {
153
+ const response = await this.phonic.post(
154
+ "/conversations/twilio/outbound_call",
155
+ {
156
+ from_phone_number: params.from_phone_number,
157
+ to_phone_number: params.to_phone_number,
158
+ config
159
+ },
160
+ {
161
+ "X-Twilio-Account-Sid": params.account_sid,
162
+ "X-Twilio-Api-Key-Sid": params.api_key_sid,
163
+ "X-Twilio-Api-Key-Secret": params.api_key_secret
164
+ }
155
165
  );
156
166
  return response;
157
167
  }
158
- async getByExternalId({
159
- project,
160
- externalId
161
- }) {
162
- const queryString = new URLSearchParams({
163
- ...project !== void 0 && { project },
164
- external_id: externalId
165
- }).toString();
166
- const response = await this.phonic.get(
167
- `/conversations?${queryString}`
168
- );
169
- return response;
168
+ };
169
+
170
+ // src/conversations/index.ts
171
+ var Conversations = class {
172
+ constructor(phonic) {
173
+ this.phonic = phonic;
174
+ this.twilio = new Twilio(phonic);
170
175
  }
176
+ twilio;
171
177
  async list({
172
178
  project,
173
179
  durationMin,
@@ -187,34 +193,40 @@ var Conversations = class {
187
193
  );
188
194
  return response;
189
195
  }
190
- };
191
-
192
- // src/sts/index.ts
193
- var import_ws = __toESM(require("ws"));
194
-
195
- // src/sts/twilio/index.ts
196
- var Twilio = class {
197
- constructor(phonic) {
198
- this.phonic = phonic;
196
+ async get(id) {
197
+ const response = await this.phonic.get(
198
+ `/conversations/${id}`
199
+ );
200
+ return response;
199
201
  }
200
- async outboundCall(params, config) {
202
+ async getByExternalId({
203
+ project,
204
+ externalId
205
+ }) {
206
+ const queryString = new URLSearchParams({
207
+ ...project !== void 0 && { project },
208
+ external_id: externalId
209
+ }).toString();
210
+ const response = await this.phonic.get(
211
+ `/conversations?${queryString}`
212
+ );
213
+ return response;
214
+ }
215
+ async outboundCall(toPhoneNumber, config) {
201
216
  const response = await this.phonic.post(
202
- "/sts/twilio/outbound_call",
217
+ "/conversations/outbound_call",
203
218
  {
204
- from_phone_number: params.from_phone_number,
205
- to_phone_number: params.to_phone_number,
219
+ to_phone_number: toPhoneNumber,
206
220
  config
207
- },
208
- {
209
- "X-Twilio-Account-Sid": params.account_sid,
210
- "X-Twilio-Api-Key-Sid": params.api_key_sid,
211
- "X-Twilio-Api-Key-Secret": params.api_key_secret
212
221
  }
213
222
  );
214
223
  return response;
215
224
  }
216
225
  };
217
226
 
227
+ // src/sts/index.ts
228
+ var import_ws = __toESM(require("ws"));
229
+
218
230
  // src/sts/websocket.ts
219
231
  var PhonicSTSWebSocket = class {
220
232
  constructor(ws, config) {
@@ -318,9 +330,7 @@ var PhonicSTSWebSocket = class {
318
330
  var SpeechToSpeech = class {
319
331
  constructor(phonic) {
320
332
  this.phonic = phonic;
321
- this.twilio = new Twilio(phonic);
322
333
  }
323
- twilio;
324
334
  websocket(config) {
325
335
  const wsBaseUrl = this.phonic.baseUrl.replace(/^http/, "ws");
326
336
  const queryString = new URLSearchParams({
@@ -334,16 +344,73 @@ var SpeechToSpeech = class {
334
344
  });
335
345
  return new PhonicSTSWebSocket(ws, config);
336
346
  }
337
- async outboundCall(toPhoneNumber, config) {
347
+ };
348
+
349
+ // src/tools/index.ts
350
+ var Tools = class {
351
+ constructor(phonic) {
352
+ this.phonic = phonic;
353
+ }
354
+ getParametersForBody(parameters) {
355
+ if (parameters === void 0) {
356
+ return void 0;
357
+ }
358
+ return parameters.map((parameter) => {
359
+ return {
360
+ type: parameter.type,
361
+ name: parameter.name,
362
+ description: parameter.description,
363
+ is_required: parameter.isRequired,
364
+ ...parameter.type === "array" && {
365
+ item_type: parameter.itemType
366
+ }
367
+ };
368
+ });
369
+ }
370
+ async list() {
371
+ const response = await this.phonic.get("/tools");
372
+ return response;
373
+ }
374
+ async get(name) {
375
+ const response = await this.phonic.get(
376
+ `/tools/${name}`
377
+ );
378
+ return response;
379
+ }
380
+ async create(params) {
338
381
  const response = await this.phonic.post(
339
- "/sts/outbound_call",
382
+ "/tools",
340
383
  {
341
- to_phone_number: toPhoneNumber,
342
- config
384
+ name: params.name,
385
+ description: params.description,
386
+ endpoint_url: params.endpointUrl,
387
+ endpoint_headers: params.endpointHeaders,
388
+ endpoint_timeout_ms: params.endpointTimeoutMs,
389
+ parameters: this.getParametersForBody(params.parameters)
390
+ }
391
+ );
392
+ return response;
393
+ }
394
+ async update(name, params) {
395
+ const response = await this.phonic.patch(
396
+ `/tools/${name}`,
397
+ {
398
+ name: params.name,
399
+ description: params.description,
400
+ endpoint_url: params.endpointUrl,
401
+ endpoint_headers: params.endpointHeaders,
402
+ endpoint_timeout_ms: params.endpointTimeoutMs,
403
+ parameters: this.getParametersForBody(params.parameters)
343
404
  }
344
405
  );
345
406
  return response;
346
407
  }
408
+ async delete(name) {
409
+ const response = await this.phonic.delete(
410
+ `/tools/${name}`
411
+ );
412
+ return response;
413
+ }
347
414
  };
348
415
 
349
416
  // src/voices/index.ts
@@ -395,6 +462,7 @@ var Phonic = class {
395
462
  headers;
396
463
  agents = new Agents(this);
397
464
  conversations = new Conversations(this);
465
+ tools = new Tools(this);
398
466
  voices = new Voices(this);
399
467
  sts = new SpeechToSpeech(this);
400
468
  async fetchRequest(path, options) {
package/dist/index.mjs CHANGED
@@ -1,5 +1,5 @@
1
1
  // package.json
2
- var version = "0.22.0";
2
+ var version = "0.24.0";
3
3
 
4
4
  // src/agents/index.ts
5
5
  var Agents = class {
@@ -108,30 +108,36 @@ var Agents = class {
108
108
  }
109
109
  };
110
110
 
111
- // src/conversations/index.ts
112
- var Conversations = class {
111
+ // src/conversations/twilio/index.ts
112
+ var Twilio = class {
113
113
  constructor(phonic) {
114
114
  this.phonic = phonic;
115
115
  }
116
- async get(id) {
117
- const response = await this.phonic.get(
118
- `/conversations/${id}`
116
+ async outboundCall(params, config) {
117
+ const response = await this.phonic.post(
118
+ "/conversations/twilio/outbound_call",
119
+ {
120
+ from_phone_number: params.from_phone_number,
121
+ to_phone_number: params.to_phone_number,
122
+ config
123
+ },
124
+ {
125
+ "X-Twilio-Account-Sid": params.account_sid,
126
+ "X-Twilio-Api-Key-Sid": params.api_key_sid,
127
+ "X-Twilio-Api-Key-Secret": params.api_key_secret
128
+ }
119
129
  );
120
130
  return response;
121
131
  }
122
- async getByExternalId({
123
- project,
124
- externalId
125
- }) {
126
- const queryString = new URLSearchParams({
127
- ...project !== void 0 && { project },
128
- external_id: externalId
129
- }).toString();
130
- const response = await this.phonic.get(
131
- `/conversations?${queryString}`
132
- );
133
- return response;
132
+ };
133
+
134
+ // src/conversations/index.ts
135
+ var Conversations = class {
136
+ constructor(phonic) {
137
+ this.phonic = phonic;
138
+ this.twilio = new Twilio(phonic);
134
139
  }
140
+ twilio;
135
141
  async list({
136
142
  project,
137
143
  durationMin,
@@ -151,34 +157,40 @@ var Conversations = class {
151
157
  );
152
158
  return response;
153
159
  }
154
- };
155
-
156
- // src/sts/index.ts
157
- import WebSocket from "ws";
158
-
159
- // src/sts/twilio/index.ts
160
- var Twilio = class {
161
- constructor(phonic) {
162
- this.phonic = phonic;
160
+ async get(id) {
161
+ const response = await this.phonic.get(
162
+ `/conversations/${id}`
163
+ );
164
+ return response;
163
165
  }
164
- async outboundCall(params, config) {
166
+ async getByExternalId({
167
+ project,
168
+ externalId
169
+ }) {
170
+ const queryString = new URLSearchParams({
171
+ ...project !== void 0 && { project },
172
+ external_id: externalId
173
+ }).toString();
174
+ const response = await this.phonic.get(
175
+ `/conversations?${queryString}`
176
+ );
177
+ return response;
178
+ }
179
+ async outboundCall(toPhoneNumber, config) {
165
180
  const response = await this.phonic.post(
166
- "/sts/twilio/outbound_call",
181
+ "/conversations/outbound_call",
167
182
  {
168
- from_phone_number: params.from_phone_number,
169
- to_phone_number: params.to_phone_number,
183
+ to_phone_number: toPhoneNumber,
170
184
  config
171
- },
172
- {
173
- "X-Twilio-Account-Sid": params.account_sid,
174
- "X-Twilio-Api-Key-Sid": params.api_key_sid,
175
- "X-Twilio-Api-Key-Secret": params.api_key_secret
176
185
  }
177
186
  );
178
187
  return response;
179
188
  }
180
189
  };
181
190
 
191
+ // src/sts/index.ts
192
+ import WebSocket from "ws";
193
+
182
194
  // src/sts/websocket.ts
183
195
  var PhonicSTSWebSocket = class {
184
196
  constructor(ws, config) {
@@ -282,9 +294,7 @@ var PhonicSTSWebSocket = class {
282
294
  var SpeechToSpeech = class {
283
295
  constructor(phonic) {
284
296
  this.phonic = phonic;
285
- this.twilio = new Twilio(phonic);
286
297
  }
287
- twilio;
288
298
  websocket(config) {
289
299
  const wsBaseUrl = this.phonic.baseUrl.replace(/^http/, "ws");
290
300
  const queryString = new URLSearchParams({
@@ -298,16 +308,73 @@ var SpeechToSpeech = class {
298
308
  });
299
309
  return new PhonicSTSWebSocket(ws, config);
300
310
  }
301
- async outboundCall(toPhoneNumber, config) {
311
+ };
312
+
313
+ // src/tools/index.ts
314
+ var Tools = class {
315
+ constructor(phonic) {
316
+ this.phonic = phonic;
317
+ }
318
+ getParametersForBody(parameters) {
319
+ if (parameters === void 0) {
320
+ return void 0;
321
+ }
322
+ return parameters.map((parameter) => {
323
+ return {
324
+ type: parameter.type,
325
+ name: parameter.name,
326
+ description: parameter.description,
327
+ is_required: parameter.isRequired,
328
+ ...parameter.type === "array" && {
329
+ item_type: parameter.itemType
330
+ }
331
+ };
332
+ });
333
+ }
334
+ async list() {
335
+ const response = await this.phonic.get("/tools");
336
+ return response;
337
+ }
338
+ async get(name) {
339
+ const response = await this.phonic.get(
340
+ `/tools/${name}`
341
+ );
342
+ return response;
343
+ }
344
+ async create(params) {
302
345
  const response = await this.phonic.post(
303
- "/sts/outbound_call",
346
+ "/tools",
304
347
  {
305
- to_phone_number: toPhoneNumber,
306
- config
348
+ name: params.name,
349
+ description: params.description,
350
+ endpoint_url: params.endpointUrl,
351
+ endpoint_headers: params.endpointHeaders,
352
+ endpoint_timeout_ms: params.endpointTimeoutMs,
353
+ parameters: this.getParametersForBody(params.parameters)
354
+ }
355
+ );
356
+ return response;
357
+ }
358
+ async update(name, params) {
359
+ const response = await this.phonic.patch(
360
+ `/tools/${name}`,
361
+ {
362
+ name: params.name,
363
+ description: params.description,
364
+ endpoint_url: params.endpointUrl,
365
+ endpoint_headers: params.endpointHeaders,
366
+ endpoint_timeout_ms: params.endpointTimeoutMs,
367
+ parameters: this.getParametersForBody(params.parameters)
307
368
  }
308
369
  );
309
370
  return response;
310
371
  }
372
+ async delete(name) {
373
+ const response = await this.phonic.delete(
374
+ `/tools/${name}`
375
+ );
376
+ return response;
377
+ }
311
378
  };
312
379
 
313
380
  // src/voices/index.ts
@@ -359,6 +426,7 @@ var Phonic = class {
359
426
  headers;
360
427
  agents = new Agents(this);
361
428
  conversations = new Conversations(this);
429
+ tools = new Tools(this);
362
430
  voices = new Voices(this);
363
431
  sts = new SpeechToSpeech(this);
364
432
  async fetchRequest(path, options) {
package/package.json CHANGED
@@ -1,10 +1,11 @@
1
1
  {
2
2
  "name": "phonic",
3
- "version": "0.22.0",
3
+ "version": "0.24.0",
4
4
  "description": "Phonic Node.js SDK",
5
5
  "scripts": {
6
6
  "build": "tsup",
7
7
  "check": "biome check --write",
8
+ "ct": "bun check && bun tsc",
8
9
  "ci": "bun tsc && biome ci && bun test",
9
10
  "version": "changeset version && bun check",
10
11
  "release": "bun run build && changeset publish"