phonic 0.22.0 → 0.23.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)
@@ -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,7 +280,6 @@ const conversationResult = await phonic.conversations.getByExternalId({
183
280
  });
184
281
  ```
185
282
 
186
-
187
283
  ## STS outbound call
188
284
 
189
285
  ```ts
package/dist/index.d.mts CHANGED
@@ -144,10 +144,10 @@ type Agent = {
144
144
  timeout_ms: number;
145
145
  } | null;
146
146
  };
147
- type ListAgentParams = {
147
+ type ListAgentsParams = {
148
148
  project?: string;
149
149
  };
150
- type ListAgentSuccessResponse = DataOrError<{
150
+ type ListAgentsSuccessResponse = DataOrError<{
151
151
  agents: Array<Agent>;
152
152
  }>;
153
153
  type GetAgentParams = {
@@ -220,7 +220,7 @@ declare class Agents {
220
220
  private getQueryString;
221
221
  private getTemplateVariablesForBody;
222
222
  private getConfigurationEndpointForBody;
223
- list(params?: ListAgentParams): DataOrError<ListAgentSuccessResponse>;
223
+ list(params?: ListAgentsParams): DataOrError<ListAgentsSuccessResponse>;
224
224
  get(name: string, params?: GetAgentParams): DataOrError<GetAgentSuccessResponse>;
225
225
  create(params: CreateAgentParams): DataOrError<CreateAgentSuccessResponse>;
226
226
  update(name: string, params: UpdateAgentParams): DataOrError<UpdateAgentSuccessResponse>;
@@ -332,6 +332,72 @@ declare class SpeechToSpeech {
332
332
  outboundCall(toPhoneNumber: string, config: PhonicSTSOutboundCallConfig): DataOrError<OutboundCallSuccessResponse>;
333
333
  }
334
334
 
335
+ interface ParameterBase {
336
+ name: string;
337
+ description: string;
338
+ isRequired: boolean;
339
+ }
340
+ interface PrimitiveParameter extends ParameterBase {
341
+ type: "string" | "integer" | "number" | "boolean";
342
+ }
343
+ interface ArrayParameter extends ParameterBase {
344
+ type: "array";
345
+ itemType: "string" | "integer" | "number" | "boolean";
346
+ }
347
+ type ToolParameters = Array<PrimitiveParameter | ArrayParameter>;
348
+ type Tool = {
349
+ id: string;
350
+ name: string;
351
+ description: string;
352
+ endpoint_url: string;
353
+ endpoint_headers: Record<string, string>;
354
+ endpoint_timeout_ms: number;
355
+ parameters: ToolParameters;
356
+ };
357
+ type ListToolsSuccessResponse = DataOrError<{
358
+ tools: Array<Tool>;
359
+ }>;
360
+ type GetToolSuccessResponse = DataOrError<{
361
+ tool: Tool;
362
+ }>;
363
+ type CreateToolParams = {
364
+ name: string;
365
+ description: string;
366
+ endpointUrl: string;
367
+ endpointHeaders?: Record<string, string>;
368
+ endpointTimeoutMs?: number;
369
+ parameters?: ToolParameters;
370
+ };
371
+ type CreateToolSuccessResponse = {
372
+ id: string;
373
+ name: string;
374
+ };
375
+ type UpdateToolParams = {
376
+ name?: string;
377
+ description?: string;
378
+ endpointUrl?: string;
379
+ endpointHeaders?: Record<string, string>;
380
+ endpointTimeoutMs?: number;
381
+ parameters?: Array<PrimitiveParameter | ArrayParameter>;
382
+ };
383
+ type UpdateToolSuccessResponse = {
384
+ success: true;
385
+ };
386
+ type DeleteToolSuccessResponse = {
387
+ success: true;
388
+ };
389
+
390
+ declare class Tools {
391
+ private readonly phonic;
392
+ constructor(phonic: Phonic);
393
+ private getParametersForBody;
394
+ list(): DataOrError<ListToolsSuccessResponse>;
395
+ get(name: string): DataOrError<GetToolSuccessResponse>;
396
+ create(params: CreateToolParams): DataOrError<CreateToolSuccessResponse>;
397
+ update(name: string, params: UpdateToolParams): DataOrError<UpdateToolSuccessResponse>;
398
+ delete(name: string): DataOrError<DeleteToolSuccessResponse>;
399
+ }
400
+
335
401
  type Voice = {
336
402
  id: string;
337
403
  name: string;
@@ -359,6 +425,7 @@ declare class Phonic {
359
425
  readonly headers: Record<string, string>;
360
426
  readonly agents: Agents;
361
427
  readonly conversations: Conversations;
428
+ readonly tools: Tools;
362
429
  readonly voices: Voices;
363
430
  readonly sts: SpeechToSpeech;
364
431
  constructor(apiKey: string, config?: PhonicConfig);
package/dist/index.d.ts CHANGED
@@ -144,10 +144,10 @@ type Agent = {
144
144
  timeout_ms: number;
145
145
  } | null;
146
146
  };
147
- type ListAgentParams = {
147
+ type ListAgentsParams = {
148
148
  project?: string;
149
149
  };
150
- type ListAgentSuccessResponse = DataOrError<{
150
+ type ListAgentsSuccessResponse = DataOrError<{
151
151
  agents: Array<Agent>;
152
152
  }>;
153
153
  type GetAgentParams = {
@@ -220,7 +220,7 @@ declare class Agents {
220
220
  private getQueryString;
221
221
  private getTemplateVariablesForBody;
222
222
  private getConfigurationEndpointForBody;
223
- list(params?: ListAgentParams): DataOrError<ListAgentSuccessResponse>;
223
+ list(params?: ListAgentsParams): DataOrError<ListAgentsSuccessResponse>;
224
224
  get(name: string, params?: GetAgentParams): DataOrError<GetAgentSuccessResponse>;
225
225
  create(params: CreateAgentParams): DataOrError<CreateAgentSuccessResponse>;
226
226
  update(name: string, params: UpdateAgentParams): DataOrError<UpdateAgentSuccessResponse>;
@@ -332,6 +332,72 @@ declare class SpeechToSpeech {
332
332
  outboundCall(toPhoneNumber: string, config: PhonicSTSOutboundCallConfig): DataOrError<OutboundCallSuccessResponse>;
333
333
  }
334
334
 
335
+ interface ParameterBase {
336
+ name: string;
337
+ description: string;
338
+ isRequired: boolean;
339
+ }
340
+ interface PrimitiveParameter extends ParameterBase {
341
+ type: "string" | "integer" | "number" | "boolean";
342
+ }
343
+ interface ArrayParameter extends ParameterBase {
344
+ type: "array";
345
+ itemType: "string" | "integer" | "number" | "boolean";
346
+ }
347
+ type ToolParameters = Array<PrimitiveParameter | ArrayParameter>;
348
+ type Tool = {
349
+ id: string;
350
+ name: string;
351
+ description: string;
352
+ endpoint_url: string;
353
+ endpoint_headers: Record<string, string>;
354
+ endpoint_timeout_ms: number;
355
+ parameters: ToolParameters;
356
+ };
357
+ type ListToolsSuccessResponse = DataOrError<{
358
+ tools: Array<Tool>;
359
+ }>;
360
+ type GetToolSuccessResponse = DataOrError<{
361
+ tool: Tool;
362
+ }>;
363
+ type CreateToolParams = {
364
+ name: string;
365
+ description: string;
366
+ endpointUrl: string;
367
+ endpointHeaders?: Record<string, string>;
368
+ endpointTimeoutMs?: number;
369
+ parameters?: ToolParameters;
370
+ };
371
+ type CreateToolSuccessResponse = {
372
+ id: string;
373
+ name: string;
374
+ };
375
+ type UpdateToolParams = {
376
+ name?: string;
377
+ description?: string;
378
+ endpointUrl?: string;
379
+ endpointHeaders?: Record<string, string>;
380
+ endpointTimeoutMs?: number;
381
+ parameters?: Array<PrimitiveParameter | ArrayParameter>;
382
+ };
383
+ type UpdateToolSuccessResponse = {
384
+ success: true;
385
+ };
386
+ type DeleteToolSuccessResponse = {
387
+ success: true;
388
+ };
389
+
390
+ declare class Tools {
391
+ private readonly phonic;
392
+ constructor(phonic: Phonic);
393
+ private getParametersForBody;
394
+ list(): DataOrError<ListToolsSuccessResponse>;
395
+ get(name: string): DataOrError<GetToolSuccessResponse>;
396
+ create(params: CreateToolParams): DataOrError<CreateToolSuccessResponse>;
397
+ update(name: string, params: UpdateToolParams): DataOrError<UpdateToolSuccessResponse>;
398
+ delete(name: string): DataOrError<DeleteToolSuccessResponse>;
399
+ }
400
+
335
401
  type Voice = {
336
402
  id: string;
337
403
  name: string;
@@ -359,6 +425,7 @@ declare class Phonic {
359
425
  readonly headers: Record<string, string>;
360
426
  readonly agents: Agents;
361
427
  readonly conversations: Conversations;
428
+ readonly tools: Tools;
362
429
  readonly voices: Voices;
363
430
  readonly sts: SpeechToSpeech;
364
431
  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.23.0";
39
39
 
40
40
  // src/agents/index.ts
41
41
  var Agents = class {
@@ -346,6 +346,73 @@ var SpeechToSpeech = class {
346
346
  }
347
347
  };
348
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) {
381
+ const response = await this.phonic.post(
382
+ "/tools",
383
+ {
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)
404
+ }
405
+ );
406
+ return response;
407
+ }
408
+ async delete(name) {
409
+ const response = await this.phonic.delete(
410
+ `/tools/${name}`
411
+ );
412
+ return response;
413
+ }
414
+ };
415
+
349
416
  // src/voices/index.ts
350
417
  var Voices = class {
351
418
  constructor(phonic) {
@@ -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.23.0";
3
3
 
4
4
  // src/agents/index.ts
5
5
  var Agents = class {
@@ -310,6 +310,73 @@ var SpeechToSpeech = class {
310
310
  }
311
311
  };
312
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) {
345
+ const response = await this.phonic.post(
346
+ "/tools",
347
+ {
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)
368
+ }
369
+ );
370
+ return response;
371
+ }
372
+ async delete(name) {
373
+ const response = await this.phonic.delete(
374
+ `/tools/${name}`
375
+ );
376
+ return response;
377
+ }
378
+ };
379
+
313
380
  // src/voices/index.ts
314
381
  var Voices = class {
315
382
  constructor(phonic) {
@@ -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,6 +1,6 @@
1
1
  {
2
2
  "name": "phonic",
3
- "version": "0.22.0",
3
+ "version": "0.23.0",
4
4
  "description": "Phonic Node.js SDK",
5
5
  "scripts": {
6
6
  "build": "tsup",