@guava-ai/guava-sdk 0.27.0 → 0.27.1

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 (37) hide show
  1. package/README.md +1 -1
  2. package/bin/example-runner.ts +67 -26
  3. package/dist/bin/example-runner.d.ts +1 -25
  4. package/dist/bin/example-runner.js +64 -24
  5. package/dist/bin/example-runner.js.map +1 -1
  6. package/dist/examples/help-desk.d.ts +1 -1
  7. package/dist/examples/help-desk.js +34 -23
  8. package/dist/examples/help-desk.js.map +1 -1
  9. package/dist/examples/multiple-agents.d.ts +1 -1
  10. package/dist/examples/multiple-agents.js +1 -1
  11. package/dist/examples/multiple-agents.js.map +1 -1
  12. package/dist/examples/polling-campaign.d.ts +1 -1
  13. package/dist/examples/polling-campaign.js +9 -7
  14. package/dist/examples/polling-campaign.js.map +1 -1
  15. package/dist/examples/property-insurance.d.ts +1 -1
  16. package/dist/examples/property-insurance.js +34 -23
  17. package/dist/examples/property-insurance.js.map +1 -1
  18. package/dist/examples/restaurant-waitlist.d.ts +1 -1
  19. package/dist/examples/restaurant-waitlist.js +34 -23
  20. package/dist/examples/restaurant-waitlist.js.map +1 -1
  21. package/dist/examples/scheduling-outbound.d.ts +1 -1
  22. package/dist/examples/scheduling-outbound.js +24 -14
  23. package/dist/examples/scheduling-outbound.js.map +1 -1
  24. package/dist/src/agent.d.ts +2 -2
  25. package/dist/src/agent.js +4 -4
  26. package/dist/src/agent.js.map +1 -1
  27. package/dist/src/version.d.ts +1 -1
  28. package/dist/src/version.js +1 -1
  29. package/examples/help-desk.ts +42 -20
  30. package/examples/multiple-agents.ts +1 -1
  31. package/examples/polling-campaign.ts +12 -7
  32. package/examples/property-insurance.ts +42 -22
  33. package/examples/restaurant-waitlist.ts +42 -22
  34. package/examples/scheduling-outbound.ts +26 -15
  35. package/package.json +2 -1
  36. package/src/agent.ts +16 -8
  37. package/src/version.ts +1 -1
@@ -1,3 +1,4 @@
1
+ import { Command } from "commander";
1
2
  import * as guava from "@guava-ai/guava-sdk";
2
3
  import { DatetimeFilter } from "@guava-ai/guava-sdk/helpers";
3
4
  import { mockAppointmentsForFuture } from "@guava-ai/guava-sdk/example-data";
@@ -42,22 +43,32 @@ agent.onTaskComplete("schedule_appointment", async (call) => {
42
43
  await call.hangup("Thank them for their time and hang up the call.");
43
44
  });
44
45
 
45
- export async function run(args: string[]) {
46
- if (args.includes("--chat")) {
47
- const patientName = args[args.indexOf("--chat") + 1] ?? "Benjamin Buttons";
48
- await agent.chat({ patientName });
49
- return;
50
- }
46
+ export async function run(prog: string, args: string[]) {
47
+ const program = new Command().name(prog).showHelpAfterError();
51
48
 
52
- const [toNumber, patientName = "Benjamin Buttons"] = args;
49
+ program
50
+ .command("phone <number>")
51
+ .description("Call a phone number.")
52
+ .option("-n, --name <name>", "Name of the patient.", "Benjamin Buttons")
53
+ .action(async (number: string, options: { name: string }) => {
54
+ await agent.callPhone(await getAgentNumber(), number, { patientName: options.name });
55
+ });
53
56
 
54
- if (!toNumber) {
55
- console.error("Usage: guava-example scheduling-outbound <phone> [name]");
56
- console.error(" guava-example scheduling-outbound --chat [name]");
57
- process.exit(1);
58
- }
57
+ program
58
+ .command("local")
59
+ .description("Start a local call (for testing).")
60
+ .option("-n, --name <name>", "Name of the patient.", "Benjamin Buttons")
61
+ .action(async (options: { name: string }) => {
62
+ await agent.callLocal({ patientName: options.name });
63
+ });
64
+
65
+ program
66
+ .command("chat")
67
+ .description("Start a local chat session (for testing).")
68
+ .option("-n, --name <name>", "Name of the patient.", "Benjamin Buttons")
69
+ .action(async (options: { name: string }) => {
70
+ await agent.chat({ patientName: options.name });
71
+ });
59
72
 
60
- agent.callPhone(await getAgentNumber(), toNumber, {
61
- patientName: patientName,
62
- });
73
+ await program.parseAsync(args, { from: "user" });
63
74
  }
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@guava-ai/guava-sdk",
3
3
  "description": "The official TypeScript SDK for building Guava voice agents.",
4
4
  "homepage": "https://docs.goguava.ai/typescript-sdk/",
5
- "version": "0.27.0",
5
+ "version": "0.27.1",
6
6
  "type": "commonjs",
7
7
  "main": "dist/src/index.js",
8
8
  "types": "dist/src/index.d.ts",
@@ -46,6 +46,7 @@
46
46
  "guava-example": "dist/bin/example-runner.js"
47
47
  },
48
48
  "dependencies": {
49
+ "commander": "^15.0.0",
49
50
  "openai": "^6.16.0",
50
51
  "ws": "^8.19.0",
51
52
  "zod": "^4.3.5"
package/src/agent.ts CHANGED
@@ -276,12 +276,14 @@ export class Agent {
276
276
  return this._listenInbound(healthCtx, { sip_code: sipCode });
277
277
  }
278
278
 
279
- async callLocal(): Promise<void> {
279
+ async callLocal(variables: Record<string, any> = {}): Promise<void> {
280
280
  const webrtcCode = await this._client.createWebrtcAgent(300);
281
281
  // No health-server for call_local.
282
- this._listenInbound(new HealthContext(), { webrtc_code: webrtcCode }).catch((err) => {
283
- this._logger.error("Listen loop error: %s", err);
284
- });
282
+ this._listenInbound(new HealthContext(), { webrtc_code: webrtcCode }, variables).catch(
283
+ (err) => {
284
+ this._logger.error("Listen loop error: %s", err);
285
+ },
286
+ );
285
287
  await runWebrtcHelper(webrtcCode, getBaseUrl());
286
288
  }
287
289
 
@@ -574,7 +576,11 @@ export class Agent {
574
576
  }
575
577
  }
576
578
 
577
- async _listenInbound(healthCtx: HealthContext, conn: InboundConnection): Promise<void> {
579
+ async _listenInbound(
580
+ healthCtx: HealthContext,
581
+ conn: InboundConnection,
582
+ initialVariables: Record<string, any> = {},
583
+ ): Promise<void> {
578
584
  const url = new URL("v2/listen-inbound", this._client.getWebsocketBase());
579
585
  if ("agent_number" in conn) {
580
586
  url.searchParams.set("phone_number", conn.agent_number);
@@ -632,9 +638,11 @@ export class Agent {
632
638
  case "assign-call": {
633
639
  const { call_id, call_info } = msg;
634
640
  this._logger.info("Received call (session ID: %s)", call_id);
635
- this._handleAssignedCall(call_id, call_info, socket).catch((err) => {
636
- this._logger.error("Error handling assigned call %s: %s", call_id, err);
637
- });
641
+ this._handleAssignedCall(call_id, call_info, socket, initialVariables).catch(
642
+ (err) => {
643
+ this._logger.error("Error handling assigned call %s: %s", call_id, err);
644
+ },
645
+ );
638
646
  break;
639
647
  }
640
648
  }
package/src/version.ts CHANGED
@@ -1 +1 @@
1
- export const SDK_VERSION = "0.27.0";
1
+ export const SDK_VERSION = "0.27.1";