@guava-ai/guava-sdk 0.43.0 → 0.44.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
@@ -57,7 +57,7 @@ You can also load a prebuilt bundle from a CDN.
57
57
 
58
58
  ```html
59
59
  <script
60
- src="https://cdn.jsdelivr.net/npm/@guava-ai/guava-sdk@0.43.0/dist/guava-webrtc.min.js"
60
+ src="https://cdn.jsdelivr.net/npm/@guava-ai/guava-sdk@0.44.0/dist/guava-webrtc.min.js"
61
61
  integrity="sha384-CqOmyWgWQBezum+sb7uPDUvYIN4/0eKmWbgs/LEjsn+KmW8PoP9zwB1FVQR7v3c3"
62
62
  crossorigin="anonymous"
63
63
  ></script>
@@ -73,12 +73,12 @@ Or as an ES module:
73
73
  <script type="importmap">
74
74
  {
75
75
  "integrity": {
76
- "https://cdn.jsdelivr.net/npm/@guava-ai/guava-sdk@0.43.0/dist/guava-webrtc.esm.min.js": "sha384-Lf/SBkHjXX4aPSR9S2XcqQXaI21CnugMUu7ROfHLJGnvtPMS0lFNuYTnUal6eAZ8"
76
+ "https://cdn.jsdelivr.net/npm/@guava-ai/guava-sdk@0.44.0/dist/guava-webrtc.esm.min.js": "sha384-Lf/SBkHjXX4aPSR9S2XcqQXaI21CnugMUu7ROfHLJGnvtPMS0lFNuYTnUal6eAZ8"
77
77
  }
78
78
  }
79
79
  </script>
80
80
  <script type="module">
81
- import * as Guava from "https://cdn.jsdelivr.net/npm/@guava-ai/guava-sdk@0.43.0/dist/guava-webrtc.esm.min.js";
81
+ import * as Guava from "https://cdn.jsdelivr.net/npm/@guava-ai/guava-sdk@0.44.0/dist/guava-webrtc.esm.min.js";
82
82
  const call = new Guava.Call({ webrtcCode: "..." });
83
83
  await call.start();
84
84
  </script>
@@ -142,6 +142,10 @@ const EXAMPLES: Record<string, ExampleEntry> = {
142
142
  description: "Inbound agent that speaks at a slower speed preset",
143
143
  load: () => import("../examples/slow-speech"),
144
144
  },
145
+ "warm-transfer": {
146
+ description: "Inbound agent that briefs a rep on a second call, then joins the two",
147
+ load: () => import("../examples/warm-transfer"),
148
+ },
145
149
  "agent-testing": {
146
150
  description: "Run agent unit tests and conversation simulations",
147
151
  load: async () => ({ run: runAgentTesting }),
@@ -150,6 +150,10 @@ const EXAMPLES = {
150
150
  description: "Inbound agent that speaks at a slower speed preset",
151
151
  load: () => Promise.resolve().then(() => __importStar(require("../examples/slow-speech"))),
152
152
  },
153
+ "warm-transfer": {
154
+ description: "Inbound agent that briefs a rep on a second call, then joins the two",
155
+ load: () => Promise.resolve().then(() => __importStar(require("../examples/warm-transfer"))),
156
+ },
153
157
  "agent-testing": {
154
158
  description: "Run agent unit tests and conversation simulations",
155
159
  load: async () => ({ run: runAgentTesting }),
@@ -1 +1 @@
1
- {"version":3,"file":"example-runner.js","sourceRoot":"","sources":["../../bin/example-runner.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEA,gDAAkC;AAClC,yCAAoC;AAEpC,MAAM,SAAS,GAAG,OAAO,CAAC,MAAM,CAAC,KAAK,KAAK,IAAI,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,QAAQ,CAAC;AACzE,MAAM,CAAC,GAAG;IACR,KAAK,EAAE,SAAS,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE;IACjC,GAAG,EAAE,SAAS,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE;IAC/B,KAAK,EAAE,SAAS,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,EAAE;IAClC,GAAG,EAAE,SAAS,CAAC,CAAC,CAAC,gBAAgB,CAAC,CAAC,CAAC,EAAE;IACtC,IAAI,EAAE,SAAS,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE;IAChC,IAAI,EAAE,SAAS,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,EAAE;CAClC,CAAC;AA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,CAAC,CAAC;IACnB,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AAClB,CAAC,CAAC,CAAC"}
@@ -0,0 +1 @@
1
+ export declare function run(prog: string, args: string[]): Promise<void>;
@@ -0,0 +1,111 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ var __importDefault = (this && this.__importDefault) || function (mod) {
36
+ return (mod && mod.__esModule) ? mod : { "default": mod };
37
+ };
38
+ Object.defineProperty(exports, "__esModule", { value: true });
39
+ exports.run = run;
40
+ const node_crypto_1 = __importDefault(require("node:crypto"));
41
+ const commander_1 = require("commander");
42
+ const guava = __importStar(require("@guava-ai/guava-sdk"));
43
+ const example_utils_1 = require("@guava-ai/guava-sdk/example-utils");
44
+ let agentNumber;
45
+ let transferDestination;
46
+ const agent = new guava.Agent({
47
+ name: "Nova",
48
+ organization: "Acme Corp",
49
+ });
50
+ agent.onCallStart(async (call) => {
51
+ await call.setTask({
52
+ taskId: "collect_reason",
53
+ checklist: [guava.Field({ key: "reason_for_calling", fieldType: "text" })],
54
+ });
55
+ });
56
+ agent.onTaskComplete("collect_reason", async (call) => {
57
+ await call.setTask({
58
+ taskId: "stall_customer",
59
+ objective: `Inform the caller that you're checking if a customer service
60
+ representative is ready to help them. Stay with the caller on the
61
+ line until the expert notifies you that the representative is ready.`,
62
+ });
63
+ // Generate a random conference ID that will be eventually used to join the two calls.
64
+ const conferenceId = node_crypto_1.default.randomBytes(10).toString("hex");
65
+ // Place the outbound call in the background, so this handler doesn't block until it
66
+ // ends. Pass this call's ID so the outbound call can transfer it later.
67
+ outboundAgent
68
+ .callPhone(agentNumber, transferDestination, {
69
+ conference_id: conferenceId,
70
+ original_call_id: call.id,
71
+ call_reason: await call.getField("reason_for_calling"),
72
+ })
73
+ .catch((err) => console.error("Outbound call failed:", err));
74
+ });
75
+ const outboundAgent = new guava.Agent({
76
+ name: "Nova",
77
+ organization: "Acme Corp",
78
+ purpose: "You are an outbound calling agent. You talk to customer service representatives on behalf of callers and brief them before a warm transfer.",
79
+ });
80
+ outboundAgent.onCallStart(async (call) => {
81
+ await call.setTask({
82
+ taskId: "confirm_ready",
83
+ objective: `A caller is calling about ${await call.getVariable("call_reason")}. You are not talking to the caller - you are talking to a customer service representative.`,
84
+ checklist: [
85
+ "Inform the customer service agent of the caller's reason for calling.",
86
+ "Determine if the service agent is ready for a transfer.",
87
+ ],
88
+ });
89
+ });
90
+ outboundAgent.onTaskComplete("confirm_ready", async (call) => {
91
+ const conferenceId = await call.getVariable("conference_id");
92
+ const otherCall = new guava.RemoteCall(await call.getVariable("original_call_id"));
93
+ // Join the two calls.
94
+ const destination = `conference:${conferenceId}`;
95
+ await otherCall.transfer(destination, "The customer service representative is ready.");
96
+ await call.transfer(destination, "Transfer to the caller. Tell the rep that you are 'Patching in the caller.'");
97
+ });
98
+ async function run(prog, args) {
99
+ const program = new commander_1.Command()
100
+ .name(prog)
101
+ .showHelpAfterError()
102
+ .requiredOption("--transfer-destination <phone_number>", "Number to warm transfer callers to.")
103
+ .option("--agent-number <phone_number>", "Number to listen on. Defaults to GUAVA_AGENT_NUMBER or your account's number.")
104
+ .action(async (options) => {
105
+ transferDestination = options.transferDestination;
106
+ agentNumber = options.agentNumber ?? (await (0, example_utils_1.getAgentNumber)());
107
+ await agent.listenPhone(agentNumber);
108
+ });
109
+ await program.parseAsync(args, { from: "user" });
110
+ }
111
+ //# sourceMappingURL=warm-transfer.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"warm-transfer.js","sourceRoot":"","sources":["../../examples/warm-transfer.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAyEA,kBAgBC;AAzFD,8DAAiC;AACjC,yCAAoC;AACpC,2DAA6C;AAC7C,qEAAmE;AAEnE,IAAI,WAAmB,CAAC;AACxB,IAAI,mBAA2B,CAAC;AAEhC,MAAM,KAAK,GAAG,IAAI,KAAK,CAAC,KAAK,CAAC;IAC5B,IAAI,EAAE,MAAM;IACZ,YAAY,EAAE,WAAW;CAC1B,CAAC,CAAC;AAEH,KAAK,CAAC,WAAW,CAAC,KAAK,EAAE,IAAgB,EAAE,EAAE;IAC3C,MAAM,IAAI,CAAC,OAAO,CAAC;QACjB,MAAM,EAAE,gBAAgB;QACxB,SAAS,EAAE,CAAC,KAAK,CAAC,KAAK,CAAC,EAAE,GAAG,EAAE,oBAAoB,EAAE,SAAS,EAAE,MAAM,EAAE,CAAC,CAAC;KAC3E,CAAC,CAAC;AACL,CAAC,CAAC,CAAC;AAEH,KAAK,CAAC,cAAc,CAAC,gBAAgB,EAAE,KAAK,EAAE,IAAgB,EAAE,EAAE;IAChE,MAAM,IAAI,CAAC,OA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,CAAC,CAAC,CAAC;IAEnF,sBAAsB;IACtB,MAAM,WAAW,GAAG,cAAc,YAAY,EAAE,CAAC;IACjD,MAAM,SAAS,CAAC,QAAQ,CAAC,WAAW,EAAE,+CAA+C,CAAC,CAAC;IACvF,MAAM,IAAI,CAAC,QAAQ,CACjB,WAAW,EACX,6EAA6E,CAC9E,CAAC;AACJ,CAAC,CAAC,CAAC;AAEI,KAAK,UAAU,GAAG,CAAC,IAAY,EAAE,IAAc;IACpD,MAAM,OAAO,GAAG,IAAI,mBAAO,EAAE;SAC1B,IAAI,CAAC,IAAI,CAAC;SACV,kBAAkB,EAAE;SACpB,cAAc,CAAC,uCAAuC,EAAE,qCAAqC,CAAC;SAC9F,MAAM,CACL,+BAA+B,EAC/B,+EAA+E,CAChF;SACA,MAAM,CAAC,KAAK,EAAE,OAA8D,EAAE,EAAE;QAC/E,mBAAmB,GAAG,OAAO,CAAC,mBAAmB,CAAC;QAClD,WAAW,GAAG,OAAO,CAAC,WAAW,IAAI,CAAC,MAAM,IAAA,8BAAc,GAAE,CAAC,CAAC;QAC9D,MAAM,KAAK,CAAC,WAAW,CAAC,WAAW,CAAC,CAAC;IACvC,CAAC,CAAC,CAAC;IAEL,MAAM,OAAO,CAAC,UAAU,CAAC,IAAI,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC,CAAC;AACnD,CAAC"}
@@ -1,5 +1,5 @@
1
1
  import { type SpeedPreset } from "./commands.ts";
2
- import { type AgentDTMFSentEvent, type AgentSpeechEvent, type BotSessionEnded, type CallerSpeechEvent, type DTMFPressedEvent, type EscalateEvent, type OutboundCallFailed } from "./events.ts";
2
+ import { type AgentDTMFSentEvent, type AgentSpeechEvent, type BotSessionEnded, type CallerSpeechEvent, type DTMFPressedEvent, type EscalateEvent, type OutboundCallFailed, type WebRTCMessageEvent } from "./events.ts";
3
3
  import { HealthContext } from "./health.ts";
4
4
  import { Call, Client } from "./index.ts";
5
5
  import type { CallInfo } from "./socket/call-info.ts";
@@ -55,6 +55,7 @@ export declare class Agent {
55
55
  private _onEscalate?;
56
56
  private _onCallerDtmf?;
57
57
  private _onAgentDtmf?;
58
+ private _onWebrtcMessage?;
58
59
  private _onOutboundFailed?;
59
60
  constructor(args?: {
60
61
  name?: string;
@@ -83,6 +84,8 @@ export declare class Agent {
83
84
  /** Alias for {@link onCallerDtmf}; will be marked deprecated in a future release. */
84
85
  onDtmf(callback: (call: Call, event: DTMFPressedEvent) => Promise<void>): void;
85
86
  onAgentDtmf(callback: (call: Call, event: AgentDTMFSentEvent) => Promise<void>): void;
87
+ /** Register a handler for messages sent by a connected WebRTC client. */
88
+ onWebrtcMessage(callback: (call: Call, event: WebRTCMessageEvent) => Promise<void>): void;
86
89
  onOutboundFailed(callback: (call: Call, event: OutboundCallFailed) => Promise<void>): void;
87
90
  get handlers(): {
88
91
  onCallReceived: (callInfo: CallInfo) => Promise<IncomingCallAction>;
@@ -104,7 +107,7 @@ export declare class Agent {
104
107
  private _invokeHandler;
105
108
  private _dispatchEvent;
106
109
  _initCall(callId: string, callInfo: CallInfo, variables?: Record<string, any>): Promise<Call>;
107
- _attachToCall(callId: string, callInfo: CallInfo, initialVariables?: Record<string, any>, testSession?: TestSession, route?: string): Promise<void>;
110
+ _attachToCall(callId: string, call: Call, testSession?: TestSession, route?: string): Promise<void>;
108
111
  _listenInbound(healthCtx: HealthContext, conn: InboundConnection, initialVariables?: Record<string, any>, drainSignal?: AbortSignal): Promise<void>;
109
112
  private _handleAssignedCall;
110
113
  /**
package/dist/src/agent.js CHANGED
@@ -134,6 +134,7 @@ const logging_ts_1 = require("./logging.js");
134
134
  const client_ts_1 = require("./socket/client.js");
135
135
  const ListenInbound = __importStar(require("./socket/listen-inbound.js"));
136
136
  const telemetry_ts_1 = require("./telemetry.js");
137
+ const runner_ts_1 = require("./runner.js");
137
138
  const chat_ts_1 = require("./testing/chat.js");
138
139
  const protocol_ts_1 = require("./testing/protocol.js");
139
140
  const session_ts_1 = require("./testing/session.js");
@@ -185,6 +186,7 @@ let Agent = (() => {
185
186
  _onEscalate;
186
187
  _onCallerDtmf;
187
188
  _onAgentDtmf;
189
+ _onWebrtcMessage;
188
190
  _onOutboundFailed;
189
191
  constructor(args) {
190
192
  this._name = args?.name;
@@ -263,6 +265,10 @@ let Agent = (() => {
263
265
  onAgentDtmf(callback) {
264
266
  this._onAgentDtmf = callback;
265
267
  }
268
+ /** Register a handler for messages sent by a connected WebRTC client. */
269
+ onWebrtcMessage(callback) {
270
+ this._onWebrtcMessage = callback;
271
+ }
266
272
  onOutboundFailed(callback) {
267
273
  this._onOutboundFailed = callback;
268
274
  }
@@ -327,59 +333,13 @@ let Agent = (() => {
327
333
  });
328
334
  }
329
335
  async listenPhone(phoneNumber) {
330
- const env_1 = { stack: [], error: void 0, hasError: false };
331
- try {
332
- const healthCtx = new health_ts_1.HealthContext();
333
- const _server = __addDisposableResource(env_1, await (0, health_ts_1.getHealthServer)(healthCtx), true);
334
- return await this._listenInbound(healthCtx, { agent_number: phoneNumber });
335
- }
336
- catch (e_1) {
337
- env_1.error = e_1;
338
- env_1.hasError = true;
339
- }
340
- finally {
341
- const result_1 = __disposeResources(env_1);
342
- if (result_1)
343
- await result_1;
344
- }
336
+ await new runner_ts_1.Runner().listenPhone(this, phoneNumber).run();
345
337
  }
346
338
  async listenWebrtc(webrtcCode) {
347
- const env_2 = { stack: [], error: void 0, hasError: false };
348
- try {
349
- if (!webrtcCode) {
350
- this._logger.info("No WebRTC code provided. Creating a temporary one.");
351
- webrtcCode = await this._client.createWebrtcAgent(3600);
352
- }
353
- const healthCtx = new health_ts_1.HealthContext();
354
- const _server = __addDisposableResource(env_2, await (0, health_ts_1.getHealthServer)(healthCtx), true);
355
- return await this._listenInbound(healthCtx, { webrtc_code: webrtcCode });
356
- }
357
- catch (e_2) {
358
- env_2.error = e_2;
359
- env_2.hasError = true;
360
- }
361
- finally {
362
- const result_2 = __disposeResources(env_2);
363
- if (result_2)
364
- await result_2;
365
- }
339
+ await new runner_ts_1.Runner().listenWebrtc(this, webrtcCode).run();
366
340
  }
367
341
  async listenSip(sipCode) {
368
- const env_3 = { stack: [], error: void 0, hasError: false };
369
- try {
370
- const healthCtx = new health_ts_1.HealthContext();
371
- const _server = __addDisposableResource(env_3, await (0, health_ts_1.getHealthServer)(healthCtx), true);
372
- return await this._listenInbound(healthCtx, { sip_code: sipCode });
373
- }
374
- catch (e_3) {
375
- env_3.error = e_3;
376
- env_3.hasError = true;
377
- }
378
- finally {
379
- const result_3 = __disposeResources(env_3);
380
- if (result_3)
381
- await result_3;
382
- }
342
+ await new runner_ts_1.Runner().listenSip(this, sipCode).run();
383
343
  }
384
344
  async callLocal(variables = {}) {
385
345
  const webrtcCode = await this._client.createWebrtcAgent(300);
@@ -587,6 +547,11 @@ let Agent = (() => {
587
547
  await this._invokeHandler(call, "onAgentDtmf", false, () => this._onAgentDtmf(call, event));
588
548
  }
589
549
  }
550
+ else if (event.event_type === "webrtc-message") {
551
+ if (this._onWebrtcMessage !== undefined) {
552
+ await this._invokeHandler(call, "onWebrtcMessage", false, () => this._onWebrtcMessage(call, event));
553
+ }
554
+ }
590
555
  else if (event.event_type === "escalate") {
591
556
  if (this._onEscalate !== undefined) {
592
557
  await this._invokeHandler(call, "onEscalate", true, () => this._onEscalate(call, event));
@@ -612,7 +577,7 @@ let Agent = (() => {
612
577
  }
613
578
  }
614
579
  async _initCall(callId, callInfo, variables = {}) {
615
- const call = new index_ts_1.Call(callId, callInfo, variables);
580
+ const call = new index_ts_1.Call(callId, callInfo);
616
581
  await call.setPersona({
617
582
  agentName: this._name,
618
583
  agentPurpose: this._purpose,
@@ -630,17 +595,19 @@ let Agent = (() => {
630
595
  accept_dtmf_for_numbers: this._acceptDtmfForNumbers,
631
596
  has_on_agent_dtmf: this._onAgentDtmf !== undefined,
632
597
  });
598
+ for (const [key, value] of Object.entries(variables)) {
599
+ await call.setVariable(key, value);
600
+ }
633
601
  if (this._onCallStart !== undefined) {
634
602
  await this._onCallStart(call);
635
603
  }
636
604
  return call;
637
605
  }
638
- async _attachToCall(callId, callInfo, initialVariables = {}, testSession, route = "v2/connect-call") {
639
- const env_4 = { stack: [], error: void 0, hasError: false };
606
+ async _attachToCall(callId, call, testSession, route = "v2/connect-call") {
607
+ const env_1 = { stack: [], error: void 0, hasError: false };
640
608
  try {
641
- const call = await this._initCall(callId, callInfo, initialVariables);
642
609
  const url = new URL(`${route}/${callId}`, this._client.getWebsocketBase());
643
- const socket = __addDisposableResource(env_4, await new client_ts_1.GuavaSocket(`call-connection-${callId}`, url.toString(), this._client, (cmd) => cmd, (payload) => (0, events_ts_1.decodeEventDict)(payload), 18000).connect(), true);
610
+ const socket = __addDisposableResource(env_1, await new client_ts_1.GuavaSocket(`call-connection-${callId}`, url.toString(), this._client, (cmd) => cmd, (payload) => (0, events_ts_1.decodeEventDict)(payload), 18000).connect(), true);
644
611
  await call.setDrain(async (commands) => {
645
612
  for (const command of commands.splice(0)) {
646
613
  socket.send(command);
@@ -662,14 +629,14 @@ let Agent = (() => {
662
629
  throw e;
663
630
  }
664
631
  }
665
- catch (e_4) {
666
- env_4.error = e_4;
667
- env_4.hasError = true;
632
+ catch (e_1) {
633
+ env_1.error = e_1;
634
+ env_1.hasError = true;
668
635
  }
669
636
  finally {
670
- const result_4 = __disposeResources(env_4);
671
- if (result_4)
672
- await result_4;
637
+ const result_1 = __disposeResources(env_1);
638
+ if (result_1)
639
+ await result_1;
673
640
  }
674
641
  }
675
642
  async _listenInbound(healthCtx, conn, initialVariables = {}, drainSignal = new AbortController().signal) {
@@ -685,10 +652,10 @@ let Agent = (() => {
685
652
  }
686
653
  const activeCalls = [];
687
654
  try {
688
- const env_5 = { stack: [], error: void 0, hasError: false };
655
+ const env_2 = { stack: [], error: void 0, hasError: false };
689
656
  try {
690
- const socket = __addDisposableResource(env_5, await new client_ts_1.GuavaSocket("listen-inbound", url.toString(), this._client, (msg) => msg, ListenInbound.decodeServerMessage).connect(), true);
691
- const _ = __addDisposableResource(env_5, (0, utils_ts_1.onAbort)(drainSignal, () => {
657
+ const socket = __addDisposableResource(env_2, await new client_ts_1.GuavaSocket("listen-inbound", url.toString(), this._client, (msg) => msg, ListenInbound.decodeServerMessage).connect(), true);
658
+ const _ = __addDisposableResource(env_2, (0, utils_ts_1.onAbort)(drainSignal, () => {
692
659
  socket.close();
693
660
  }), false);
694
661
  try {
@@ -728,14 +695,14 @@ let Agent = (() => {
728
695
  throw e;
729
696
  }
730
697
  }
731
- catch (e_5) {
732
- env_5.error = e_5;
733
- env_5.hasError = true;
698
+ catch (e_2) {
699
+ env_2.error = e_2;
700
+ env_2.hasError = true;
734
701
  }
735
702
  finally {
736
- const result_5 = __disposeResources(env_5);
737
- if (result_5)
738
- await result_5;
703
+ const result_2 = __disposeResources(env_2);
704
+ if (result_2)
705
+ await result_2;
739
706
  }
740
707
  }
741
708
  finally {
@@ -753,30 +720,60 @@ let Agent = (() => {
753
720
  }
754
721
  else {
755
722
  this._logger.info("Accepting call %s.", callId);
723
+ // Initialize the call, invoking onCallStart.
724
+ let call;
725
+ try {
726
+ call = await this._initCall(callId, callInfo, initialVariables);
727
+ }
728
+ catch (err) {
729
+ this._logger.error("Failed to initialize inbound call %s. Declining: %s", callId, err);
730
+ socket.send({ message_type: "decline-call", call_id: callId });
731
+ return;
732
+ }
756
733
  socket.send({ message_type: "answer-call", call_id: callId });
757
- await this._attachToCall(callId, callInfo, initialVariables);
734
+ await this._attachToCall(callId, call);
758
735
  }
759
736
  }
760
737
  /**
761
738
  * @description use the Guava API to call out to a number
762
739
  */
763
740
  async callPhone(fromNumber, toNumber, variables = {}) {
764
- const url = new URL("v2/create-outbound", this._client.getHttpBase());
765
- url.searchParams.set("from_number", fromNumber);
766
- url.searchParams.set("to_number", toNumber);
767
- const response = await (0, utils_ts_1.fetchOrThrow)(url, {
741
+ for (const [key, value] of Object.entries(variables)) {
742
+ if (!z.json().safeParse(value).success) {
743
+ throw new Error(`Variable '${key}' value is not JSON serializable: ${String(value)}`);
744
+ }
745
+ }
746
+ const reserveUrl = new URL("v3/reserve-outbound", this._client.getHttpBase());
747
+ reserveUrl.searchParams.set("from_number", fromNumber);
748
+ reserveUrl.searchParams.set("to_number", toNumber);
749
+ const response = await (0, utils_ts_1.fetchOrThrow)(reserveUrl, {
768
750
  method: "POST",
769
751
  headers: await this._client.headers(),
770
752
  });
771
753
  const { call_id } = (await response.json());
772
- this._logger.info("Outbound call created with session ID: %s", call_id);
773
754
  const callInfo = {
774
755
  call_type: "pstn",
775
756
  from_number: fromNumber ?? null,
776
757
  to_number: toNumber,
777
758
  caller_id: null,
778
759
  };
779
- await this._attachToCall(call_id, callInfo, variables);
760
+ // Initialize the call before dialing, invoking onCallStart.
761
+ let call;
762
+ try {
763
+ call = await this._initCall(call_id, callInfo, variables);
764
+ }
765
+ catch (err) {
766
+ this._logger.error("Failed to initialize outbound call %s. The call will not be dialed: %s", call_id, err);
767
+ throw err;
768
+ }
769
+ const createUrl = new URL("v3/create-outbound", this._client.getHttpBase());
770
+ createUrl.searchParams.set("call_id", call_id);
771
+ await (0, utils_ts_1.fetchOrThrow)(createUrl, {
772
+ method: "POST",
773
+ headers: await this._client.headers(),
774
+ });
775
+ this._logger.info("Outbound call created with session ID: %s", call_id);
776
+ await this._attachToCall(call_id, call);
780
777
  }
781
778
  /**
782
779
  * Run the agent against a live test session.
@@ -814,7 +811,16 @@ let Agent = (() => {
814
811
  to_number: "+15555555555",
815
812
  caller_id: null,
816
813
  };
817
- const attachPromise = this._attachToCall(sessionStarted.session_id, testCallInfo, variables, testSession).catch((err) => {
814
+ // Initialize the call, invoking onCallStart.
815
+ let call;
816
+ try {
817
+ call = await this._initCall(sessionStarted.session_id, testCallInfo, variables);
818
+ }
819
+ catch (err) {
820
+ ws.close();
821
+ throw err;
822
+ }
823
+ const attachPromise = this._attachToCall(sessionStarted.session_id, call, testSession).catch((err) => {
818
824
  this._logger.error("Error in _attachToCall during test: %s", err);
819
825
  });
820
826
  try {
@@ -923,6 +929,7 @@ Choose "speak" and provide your next utterance, or choose "hangup" if the conver
923
929
  * affecting the original agent.
924
930
  */
925
931
  patch() {
932
+ // Keep this up to date with the Agent constructor args.
926
933
  const cloned = new Agent({
927
934
  name: this._name,
928
935
  organization: this._organization,
@@ -932,6 +939,7 @@ Choose "speak" and provide your next utterance, or choose "hangup" if the conver
932
939
  acceptDtmf: this._acceptDtmfForNumbers,
933
940
  speechSpeed: this._speechSpeed,
934
941
  });
942
+ // Keep this up to date with the handlers on Agent.
935
943
  cloned._onCallReceived = this._onCallReceived;
936
944
  cloned._onCallStart = this._onCallStart;
937
945
  cloned._onCallerSpeech = this._onCallerSpeech;
@@ -948,6 +956,7 @@ Choose "speak" and provide your next utterance, or choose "hangup" if the conver
948
956
  cloned._onEscalate = this._onEscalate;
949
957
  cloned._onCallerDtmf = this._onCallerDtmf;
950
958
  cloned._onAgentDtmf = this._onAgentDtmf;
959
+ cloned._onWebrtcMessage = this._onWebrtcMessage;
951
960
  cloned._onOutboundFailed = this._onOutboundFailed;
952
961
  return cloned;
953
962
  }
@@ -957,13 +966,13 @@ Choose "speak" and provide your next utterance, or choose "hangup" if the conver
957
966
  this._logger.info("Connecting to campaign '%s' (id: %s).", campaign.name, campaign.id);
958
967
  const activeCalls = [];
959
968
  try {
960
- const env_6 = { stack: [], error: void 0, hasError: false };
969
+ const env_3 = { stack: [], error: void 0, hasError: false };
961
970
  try {
962
- const socket = __addDisposableResource(env_6, await new client_ts_1.GuavaSocket("serve-campaign", url.toString(), this._client, (msg) => msg, guavadialer_events_ts_1.decodeServerMessage).connect(), true);
971
+ const socket = __addDisposableResource(env_3, await new client_ts_1.GuavaSocket("serve-campaign", url.toString(), this._client, (msg) => msg, guavadialer_events_ts_1.decodeServerMessage).connect(), true);
963
972
  try {
964
- const env_7 = { stack: [], error: void 0, hasError: false };
973
+ const env_4 = { stack: [], error: void 0, hasError: false };
965
974
  try {
966
- const _ = __addDisposableResource(env_7, (0, utils_ts_1.onAbort)(drainSignal, () => {
975
+ const _ = __addDisposableResource(env_4, (0, utils_ts_1.onAbort)(drainSignal, () => {
967
976
  socket.close();
968
977
  }), false);
969
978
  for await (const msg of socket) {
@@ -979,7 +988,6 @@ Choose "speak" and provide your next utterance, or choose "hangup" if the conver
979
988
  this._logger.info("Ready to make call, id %s — initiating call setup and dispatch for contact %s.", call_id, logPhone);
980
989
  // TODO: Possible memory leak.
981
990
  activeCalls.push((async () => {
982
- socket.send({ message_type: "controller-ready", call_id });
983
991
  const variables = data?.data ?? {};
984
992
  const campaignCallInfo = {
985
993
  call_type: "pstn",
@@ -987,7 +995,19 @@ Choose "speak" and provide your next utterance, or choose "hangup" if the conver
987
995
  to_number: data?.phone_number ?? "",
988
996
  caller_id: null,
989
997
  };
990
- await this._attachToCall(call_id, campaignCallInfo, variables, undefined, "v2/connect-campaign-call");
998
+ // Initialize the call, invoking onCallStart.
999
+ let call;
1000
+ try {
1001
+ call = await this._initCall(call_id, campaignCallInfo, variables);
1002
+ }
1003
+ catch (err) {
1004
+ this._logger.error("Failed to initialize campaign call %s. The call will not be dialed: %s", call_id, err);
1005
+ socket.send({ message_type: "init-controller-failed", call_id });
1006
+ return;
1007
+ }
1008
+ // Signal that we're ready for this call to go out, and attach to the endpoint.
1009
+ socket.send({ message_type: "controller-ready", call_id });
1010
+ await this._attachToCall(call_id, call, undefined, "v2/connect-campaign-call");
991
1011
  })().catch((err) => {
992
1012
  this._logger.error("Error handling campaign call %s: %s", call_id, err);
993
1013
  }));
@@ -996,12 +1016,12 @@ Choose "speak" and provide your next utterance, or choose "hangup" if the conver
996
1016
  }
997
1017
  }
998
1018
  }
999
- catch (e_6) {
1000
- env_7.error = e_6;
1001
- env_7.hasError = true;
1019
+ catch (e_3) {
1020
+ env_4.error = e_3;
1021
+ env_4.hasError = true;
1002
1022
  }
1003
1023
  finally {
1004
- __disposeResources(env_7);
1024
+ __disposeResources(env_4);
1005
1025
  }
1006
1026
  }
1007
1027
  catch (e) {
@@ -1009,14 +1029,14 @@ Choose "speak" and provide your next utterance, or choose "hangup" if the conver
1009
1029
  throw e;
1010
1030
  }
1011
1031
  }
1012
- catch (e_7) {
1013
- env_6.error = e_7;
1014
- env_6.hasError = true;
1032
+ catch (e_4) {
1033
+ env_3.error = e_4;
1034
+ env_3.hasError = true;
1015
1035
  }
1016
1036
  finally {
1017
- const result_6 = __disposeResources(env_6);
1018
- if (result_6)
1019
- await result_6;
1037
+ const result_3 = __disposeResources(env_3);
1038
+ if (result_3)
1039
+ await result_3;
1020
1040
  }
1021
1041
  }
1022
1042
  finally {
@@ -1038,21 +1058,7 @@ Choose "speak" and provide your next utterance, or choose "hangup" if the conver
1038
1058
  * await agent.attachCampaign("gcmp-abc123");
1039
1059
  */
1040
1060
  async attachCampaign(campaignCode) {
1041
- const env_8 = { stack: [], error: void 0, hasError: false };
1042
- try {
1043
- const healthCtx = new health_ts_1.HealthContext();
1044
- const _server = __addDisposableResource(env_8, await (0, health_ts_1.getHealthServer)(healthCtx), true);
1045
- return await this._serveCampaign(healthCtx, campaignCode);
1046
- }
1047
- catch (e_8) {
1048
- env_8.error = e_8;
1049
- env_8.hasError = true;
1050
- }
1051
- finally {
1052
- const result_7 = __disposeResources(env_8);
1053
- if (result_7)
1054
- await result_7;
1055
- }
1061
+ await new runner_ts_1.Runner().attachCampaign(this, campaignCode).run();
1056
1062
  }
1057
1063
  /* ===== Aliases to be removed at some point. ===== */
1058
1064
  /** @deprecated Use {@link listenPhone} instead. */