phonic 0.28.0 → 0.29.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
@@ -28,6 +28,12 @@ Node.js library for the Phonic API.
28
28
  - [Outbound call using own Twilio account](#outbound-call-using-own-twilio-account)
29
29
  - [STS via WebSocket](#sts-via-websocket)
30
30
  - [Messages that Phonic sends back to you](#messages-that-phonic-sends-back-to-you)
31
+ - [Projects](#projects)
32
+ - [List projects](#list-projects)
33
+ - [Get project](#get-project)
34
+ - [Create project](#create-project)
35
+ - [Update project](#update-project)
36
+ - [Delete project](#delete-project)
31
37
  - [License](#license)
32
38
 
33
39
  ## Installation
@@ -51,19 +57,21 @@ const phonic = new Phonic("ph_...");
51
57
  ### List agents
52
58
 
53
59
  ```ts
54
- const agentsResult = await phonic.agents.list({ project: "main" });
60
+ const result = await phonic.agents.list({ project: "main" });
55
61
  ```
56
62
 
57
63
  ### Get agent
58
64
 
65
+ Returns an agent by name or ID.
66
+
59
67
  ```ts
60
- const agentResult = await phonic.agents.get("chris", { project: "main" });
68
+ const result = await phonic.agents.get("chris", { project: "main" });
61
69
  ```
62
70
 
63
71
  ### Create agent
64
72
 
65
73
  ```ts
66
- const createAgentResult = await phonic.agents.create({
74
+ const result = await phonic.agents.create({
67
75
  name: "chris",
68
76
 
69
77
  // Optional fields
@@ -100,7 +108,7 @@ const createAgentResult = await phonic.agents.create({
100
108
  ### Update agent
101
109
 
102
110
  ```ts
103
- const updateAgentResult = await phonic.agents.update("chris", {
111
+ const result = await phonic.agents.update("chris", {
104
112
  name: "chris",
105
113
 
106
114
  // Optional fields
@@ -137,7 +145,7 @@ const updateAgentResult = await phonic.agents.update("chris", {
137
145
  ### Upsert agent
138
146
 
139
147
  ```ts
140
- const upsertAgentResult = await phonic.agents.upsert({
148
+ const result = await phonic.agents.upsert({
141
149
  name: "chris",
142
150
 
143
151
  // Optional fields
@@ -174,7 +182,7 @@ const upsertAgentResult = await phonic.agents.upsert({
174
182
  ### Delete agent
175
183
 
176
184
  ```ts
177
- const deleteAgentResult = await phonic.agents.delete("chris", {
185
+ const result = await phonic.agents.delete("chris", {
178
186
  // Optional fields
179
187
  project: "main",
180
188
  });
@@ -185,26 +193,28 @@ const deleteAgentResult = await phonic.agents.delete("chris", {
185
193
  ### List tools
186
194
 
187
195
  ```ts
188
- const toolsResult = await phonic.tools.list();
196
+ const result = await phonic.tools.list({
197
+ project: "customer-support" // Optional. Defaults to "main".
198
+ });
189
199
  ```
190
200
 
191
201
  ### Get tool
192
202
 
193
- Gets a tool by its ID or name.
203
+ Returns a tool by name or ID.
194
204
 
195
205
  ```ts
196
- const toolResult = await phonic.tools.get("next_invoice");
197
- const toolByIdResult = await phonic.tools.get("tool_12cf6e88-c254-4d3e-a149-ddf1bdd2254c");
206
+ const result = await phonic.tools.get("next_invoice", {
207
+ project: "customer-support" // Optional. Defaults to "main".
208
+ });
198
209
  ```
199
210
 
200
211
  ### Create tool
201
212
 
202
- Tools can be either webhook-based (HTTP endpoints) or WebSocket-based.
203
-
204
213
  #### Create webhook tool
205
214
 
206
215
  ```ts
207
- const createWebhookToolResult = await phonic.tools.create({
216
+ const result = await phonic.tools.create({
217
+ project: "customer-support", // Optional. Defaults to "main".
208
218
  name: "next_invoice",
209
219
  description: "Returns the next invoice of the given user",
210
220
  type: "custom_webhook",
@@ -244,7 +254,8 @@ const createWebhookToolResult = await phonic.tools.create({
244
254
  WebSocket tools allow you to handle tool execution through the WebSocket connection. When the agent calls a WebSocket tool, you'll receive a `tool_call` message and must respond with a `tool_call_output` message that contains the tool result.
245
255
 
246
256
  ```ts
247
- const createWebSocketToolResult = await phonic.tools.create({
257
+ const result = await phonic.tools.create({
258
+ project: "customer-support", // Optional. Defaults to "main".
248
259
  name: "get_product_recommendations",
249
260
  description: "Gets personalized product recommendations",
250
261
  type: "custom_websocket",
@@ -265,7 +276,7 @@ To use this tool in a conversation, add it to your agent or config:
265
276
 
266
277
  ```ts
267
278
  // When creating an agent
268
- const agent = await phonic.agents.create({
279
+ const result = await phonic.agents.create({
269
280
  name: "shopping-assistant",
270
281
  tools: ["get_product_recommendations"],
271
282
  // ... other config
@@ -303,7 +314,8 @@ phonicWebSocket.onMessage(async (message) => {
303
314
  Updates a tool by ID or name. All fields are optional - only provided fields will be updated.
304
315
 
305
316
  ```ts
306
- const updateWebhookToolResult = await phonic.tools.update("next_invoice", {
317
+ const result = await phonic.tools.update("next_invoice", {
318
+ project: "customer-support", // Optional. Defaults to "main".
307
319
  name: "next_invoice_updated",
308
320
  description: "Updated description.",
309
321
  type: "custom_webhook",
@@ -341,7 +353,7 @@ const updateWebhookToolResult = await phonic.tools.update("next_invoice", {
341
353
  For WebSocket tools, you would use `toolCallOutputTimeoutMs` instead of the endpoint fields:
342
354
 
343
355
  ```ts
344
- const updateWebSocketToolResult = await phonic.tools.update("get_product_recommendations", {
356
+ const result = await phonic.tools.update("get_product_recommendations", {
345
357
  description: "Updated product recommendation tool",
346
358
  toolCallOutputTimeoutMs: 7000
347
359
  });
@@ -352,23 +364,24 @@ const updateWebSocketToolResult = await phonic.tools.update("get_product_recomme
352
364
  Deletes a tool by ID or name.
353
365
 
354
366
  ```ts
355
- const deleteToolResult = await phonic.tools.delete("next_invoice");
367
+ const result = await phonic.tools.delete("next_invoice", {
368
+ project: "customer-support" // Optional. Defaults to "main".
369
+ });
356
370
  ```
357
371
 
358
-
359
372
  ## Voices
360
373
 
361
374
  ### List voices
362
375
 
363
376
  ```ts
364
- const voicesResult = await phonic.voices.list({ model: "merritt" });
377
+ const result = await phonic.voices.list({ model: "merritt" });
365
378
  ```
366
379
 
367
380
 
368
381
  ### Get voice
369
382
 
370
383
  ```ts
371
- const voiceResult = await phonic.voices.get("grant");
384
+ const result = await phonic.voices.get("grant");
372
385
  ```
373
386
 
374
387
  ## Conversations
@@ -376,7 +389,7 @@ const voiceResult = await phonic.voices.get("grant");
376
389
  ### List conversations
377
390
 
378
391
  ```ts
379
- const conversationsResult = await phonic.conversations.list({
392
+ const result = await phonic.conversations.list({
380
393
  project: "main",
381
394
  durationMin: 10, // sec
382
395
  durationMax: 20, // sec
@@ -389,13 +402,13 @@ const conversationsResult = await phonic.conversations.list({
389
402
  ### Get conversation by id
390
403
 
391
404
  ```ts
392
- const conversationResult = await phonic.conversations.get("conv_b1804883-5be4-42fe-b1cf-aa84450d5c84");
405
+ const result = await phonic.conversations.get("conv_b1804883-5be4-42fe-b1cf-aa84450d5c84");
393
406
  ```
394
407
 
395
408
  ### Get conversation by external id
396
409
 
397
410
  ```ts
398
- const conversationResult = await phonic.conversations.getByExternalId({
411
+ const result = await phonic.conversations.getByExternalId({
399
412
  project: "main",
400
413
  externalId: "CAdb9c032c809fec7feb932ea4c96d71e1"
401
414
  });
@@ -404,7 +417,7 @@ const conversationResult = await phonic.conversations.getByExternalId({
404
417
  ### Outbound call
405
418
 
406
419
  ```ts
407
- const outboundCallResult = await phonic.conversations.outboundCall("+19189396241", {
420
+ const result = await phonic.conversations.outboundCall("+19189396241", {
408
421
  // Optional fields
409
422
  agent: "chris",
410
423
  template_variables: {
@@ -419,7 +432,7 @@ const outboundCallResult = await phonic.conversations.outboundCall("+19189396241
419
432
  In Twilio, create a restricted API key with the following permissions: `voice -> calls -> read` and `voice -> calls -> create`.
420
433
 
421
434
  ```ts
422
- const twilioOutboundCallResult = await phonic.conversations.twilio.outboundCall(
435
+ const result = await phonic.conversations.twilio.outboundCall(
423
436
  {
424
437
  account_sid: "AC...",
425
438
  api_key_sid: "SK...",
@@ -753,6 +766,45 @@ If the conversation is not a phone call, `call_info` will be `null`. If it is a
753
766
 
754
767
  Sent when an error occurs during the conversation.
755
768
 
769
+ ## Projects
770
+
771
+ ### List projects
772
+
773
+ ```ts
774
+ const result = await phonic.projects.list();
775
+ ```
776
+
777
+ ### Get project
778
+
779
+ Returns a project by name or ID.
780
+
781
+ ```ts
782
+ const result = await phonic.projects.get("main");
783
+ ```
784
+
785
+ ### Create project
786
+
787
+ ```ts
788
+ const result = await phonic.projects.create({
789
+ name: "customer-support",
790
+ });
791
+ ```
792
+
793
+ ### Update project
794
+
795
+ ```ts
796
+ const result = await phonic.projects.update("customer-support", {
797
+ name: "updated-customer-support",
798
+ defaultAgent: "another-agent"
799
+ });
800
+ ```
801
+
802
+ ### Delete project
803
+
804
+ ```ts
805
+ const result = await phonic.projects.delete("customer-support");
806
+ ```
807
+
756
808
  ## License
757
809
 
758
810
  MIT
package/dist/index.d.mts CHANGED
@@ -479,13 +479,20 @@ interface WebSocketTool extends ToolBase {
479
479
  tool_call_output_timeout_ms: number;
480
480
  }
481
481
  type Tool = WebhookTool | WebSocketTool;
482
+ type ListToolsParams = {
483
+ project?: string;
484
+ };
482
485
  type ListToolsSuccessResponse = DataOrError<{
483
486
  tools: Array<Tool>;
484
487
  }>;
488
+ type GetToolParams = {
489
+ project?: string;
490
+ };
485
491
  type GetToolSuccessResponse = DataOrError<{
486
492
  tool: Tool;
487
493
  }>;
488
494
  interface CreateToolParamsBase {
495
+ project?: string;
489
496
  name: string;
490
497
  description: string;
491
498
  executionMode: ExecutionMode;
@@ -508,6 +515,7 @@ type CreateToolSuccessResponse = {
508
515
  name: string;
509
516
  };
510
517
  type UpdateToolParams = {
518
+ project?: string;
511
519
  name?: string;
512
520
  description?: string;
513
521
  type?: "custom_webhook" | "custom_websocket";
@@ -522,6 +530,9 @@ type UpdateToolParams = {
522
530
  type UpdateToolSuccessResponse = {
523
531
  success: true;
524
532
  };
533
+ type DeleteToolParams = {
534
+ project?: string;
535
+ };
525
536
  type DeleteToolSuccessResponse = {
526
537
  success: true;
527
538
  };
@@ -529,12 +540,13 @@ type DeleteToolSuccessResponse = {
529
540
  declare class Tools {
530
541
  private readonly phonic;
531
542
  constructor(phonic: Phonic);
543
+ private getQueryString;
532
544
  private getParametersForBody;
533
- list(): DataOrError<ListToolsSuccessResponse>;
534
- get(nameOrId: string): DataOrError<GetToolSuccessResponse>;
545
+ list(params?: ListToolsParams): DataOrError<ListToolsSuccessResponse>;
546
+ get(nameOrId: string, params?: GetToolParams): DataOrError<GetToolSuccessResponse>;
535
547
  create(params: CreateToolParams): DataOrError<CreateToolSuccessResponse>;
536
548
  update(nameOrId: string, params: UpdateToolParams): DataOrError<UpdateToolSuccessResponse>;
537
- delete(nameOrId: string): DataOrError<DeleteToolSuccessResponse>;
549
+ delete(nameOrId: string, params?: DeleteToolParams): DataOrError<DeleteToolSuccessResponse>;
538
550
  }
539
551
 
540
552
  type Voice = {
package/dist/index.d.ts CHANGED
@@ -479,13 +479,20 @@ interface WebSocketTool extends ToolBase {
479
479
  tool_call_output_timeout_ms: number;
480
480
  }
481
481
  type Tool = WebhookTool | WebSocketTool;
482
+ type ListToolsParams = {
483
+ project?: string;
484
+ };
482
485
  type ListToolsSuccessResponse = DataOrError<{
483
486
  tools: Array<Tool>;
484
487
  }>;
488
+ type GetToolParams = {
489
+ project?: string;
490
+ };
485
491
  type GetToolSuccessResponse = DataOrError<{
486
492
  tool: Tool;
487
493
  }>;
488
494
  interface CreateToolParamsBase {
495
+ project?: string;
489
496
  name: string;
490
497
  description: string;
491
498
  executionMode: ExecutionMode;
@@ -508,6 +515,7 @@ type CreateToolSuccessResponse = {
508
515
  name: string;
509
516
  };
510
517
  type UpdateToolParams = {
518
+ project?: string;
511
519
  name?: string;
512
520
  description?: string;
513
521
  type?: "custom_webhook" | "custom_websocket";
@@ -522,6 +530,9 @@ type UpdateToolParams = {
522
530
  type UpdateToolSuccessResponse = {
523
531
  success: true;
524
532
  };
533
+ type DeleteToolParams = {
534
+ project?: string;
535
+ };
525
536
  type DeleteToolSuccessResponse = {
526
537
  success: true;
527
538
  };
@@ -529,12 +540,13 @@ type DeleteToolSuccessResponse = {
529
540
  declare class Tools {
530
541
  private readonly phonic;
531
542
  constructor(phonic: Phonic);
543
+ private getQueryString;
532
544
  private getParametersForBody;
533
- list(): DataOrError<ListToolsSuccessResponse>;
534
- get(nameOrId: string): DataOrError<GetToolSuccessResponse>;
545
+ list(params?: ListToolsParams): DataOrError<ListToolsSuccessResponse>;
546
+ get(nameOrId: string, params?: GetToolParams): DataOrError<GetToolSuccessResponse>;
535
547
  create(params: CreateToolParams): DataOrError<CreateToolSuccessResponse>;
536
548
  update(nameOrId: string, params: UpdateToolParams): DataOrError<UpdateToolSuccessResponse>;
537
- delete(nameOrId: string): DataOrError<DeleteToolSuccessResponse>;
549
+ delete(nameOrId: string, params?: DeleteToolParams): DataOrError<DeleteToolSuccessResponse>;
538
550
  }
539
551
 
540
552
  type Voice = {
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.28.0";
38
+ var version = "0.29.0";
39
39
 
40
40
  // src/agents/index.ts
41
41
  var Agents = class {
@@ -425,6 +425,13 @@ var Tools = class {
425
425
  constructor(phonic) {
426
426
  this.phonic = phonic;
427
427
  }
428
+ getQueryString(params) {
429
+ const project = params?.project;
430
+ const queryString = new URLSearchParams({
431
+ ...project !== void 0 && { project }
432
+ }).toString();
433
+ return queryString;
434
+ }
428
435
  getParametersForBody(parameters) {
429
436
  if (parameters === void 0) {
430
437
  return void 0;
@@ -441,13 +448,15 @@ var Tools = class {
441
448
  };
442
449
  });
443
450
  }
444
- async list() {
445
- const response = await this.phonic.get("/tools");
451
+ async list(params) {
452
+ const response = await this.phonic.get(
453
+ `/tools?${this.getQueryString(params)}`
454
+ );
446
455
  return response;
447
456
  }
448
- async get(nameOrId) {
457
+ async get(nameOrId, params) {
449
458
  const response = await this.phonic.get(
450
- `/tools/${nameOrId}`
459
+ `/tools/${nameOrId}?${this.getQueryString(params)}`
451
460
  );
452
461
  return response;
453
462
  }
@@ -469,14 +478,14 @@ var Tools = class {
469
478
  body.tool_call_output_timeout_ms = params.toolCallOutputTimeoutMs;
470
479
  }
471
480
  const response = await this.phonic.post(
472
- "/tools",
481
+ `/tools?${this.getQueryString(params)}`,
473
482
  body
474
483
  );
475
484
  return response;
476
485
  }
477
486
  async update(nameOrId, params) {
478
487
  const response = await this.phonic.patch(
479
- `/tools/${nameOrId}`,
488
+ `/tools/${nameOrId}?${this.getQueryString(params)}`,
480
489
  {
481
490
  name: params.name,
482
491
  description: params.description,
@@ -492,9 +501,9 @@ var Tools = class {
492
501
  );
493
502
  return response;
494
503
  }
495
- async delete(nameOrId) {
504
+ async delete(nameOrId, params) {
496
505
  const response = await this.phonic.delete(
497
- `/tools/${nameOrId}`
506
+ `/tools/${nameOrId}?${this.getQueryString(params)}`
498
507
  );
499
508
  return response;
500
509
  }
package/dist/index.mjs CHANGED
@@ -1,5 +1,5 @@
1
1
  // package.json
2
- var version = "0.28.0";
2
+ var version = "0.29.0";
3
3
 
4
4
  // src/agents/index.ts
5
5
  var Agents = class {
@@ -389,6 +389,13 @@ var Tools = class {
389
389
  constructor(phonic) {
390
390
  this.phonic = phonic;
391
391
  }
392
+ getQueryString(params) {
393
+ const project = params?.project;
394
+ const queryString = new URLSearchParams({
395
+ ...project !== void 0 && { project }
396
+ }).toString();
397
+ return queryString;
398
+ }
392
399
  getParametersForBody(parameters) {
393
400
  if (parameters === void 0) {
394
401
  return void 0;
@@ -405,13 +412,15 @@ var Tools = class {
405
412
  };
406
413
  });
407
414
  }
408
- async list() {
409
- const response = await this.phonic.get("/tools");
415
+ async list(params) {
416
+ const response = await this.phonic.get(
417
+ `/tools?${this.getQueryString(params)}`
418
+ );
410
419
  return response;
411
420
  }
412
- async get(nameOrId) {
421
+ async get(nameOrId, params) {
413
422
  const response = await this.phonic.get(
414
- `/tools/${nameOrId}`
423
+ `/tools/${nameOrId}?${this.getQueryString(params)}`
415
424
  );
416
425
  return response;
417
426
  }
@@ -433,14 +442,14 @@ var Tools = class {
433
442
  body.tool_call_output_timeout_ms = params.toolCallOutputTimeoutMs;
434
443
  }
435
444
  const response = await this.phonic.post(
436
- "/tools",
445
+ `/tools?${this.getQueryString(params)}`,
437
446
  body
438
447
  );
439
448
  return response;
440
449
  }
441
450
  async update(nameOrId, params) {
442
451
  const response = await this.phonic.patch(
443
- `/tools/${nameOrId}`,
452
+ `/tools/${nameOrId}?${this.getQueryString(params)}`,
444
453
  {
445
454
  name: params.name,
446
455
  description: params.description,
@@ -456,9 +465,9 @@ var Tools = class {
456
465
  );
457
466
  return response;
458
467
  }
459
- async delete(nameOrId) {
468
+ async delete(nameOrId, params) {
460
469
  const response = await this.phonic.delete(
461
- `/tools/${nameOrId}`
470
+ `/tools/${nameOrId}?${this.getQueryString(params)}`
462
471
  );
463
472
  return response;
464
473
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "phonic",
3
- "version": "0.28.0",
3
+ "version": "0.29.0",
4
4
  "description": "Phonic Node.js SDK",
5
5
  "scripts": {
6
6
  "build": "tsup",