@anganyai/voice-sdk 0.0.4 → 0.0.6

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/dist/index.js CHANGED
@@ -16473,7 +16473,12 @@ var SipManager = class extends EventEmitter {
16473
16473
  }
16474
16474
  this.logger.info("\u{1F4F5} Hanging up call...");
16475
16475
  try {
16476
- this.currentSession.bye();
16476
+ const sessionState = this.currentSession.state;
16477
+ if (sessionState === "Established" || sessionState === "Establishing") {
16478
+ this.currentSession.bye();
16479
+ } else {
16480
+ this.logger.debug("Session already terminated, skipping BYE", { state: sessionState });
16481
+ }
16477
16482
  } catch (error) {
16478
16483
  this.logger.warn("\u26A0\uFE0F Error sending BYE", { error });
16479
16484
  }
@@ -17418,27 +17423,35 @@ var Conversation = class extends EventEmitter {
17418
17423
  throw new AuthenticationError("Not authenticated");
17419
17424
  }
17420
17425
  this.logger.debug("\u2713 Authentication check passed");
17421
- this.logger.debug("=== STEP 2: GETTING ACCESS TOKEN ===");
17426
+ this.logger.debug("=== STEP 2: GETTING ACCESS TOKEN (OPTIONAL) ===");
17422
17427
  let accessToken = authStatus.tokens?.accessToken;
17423
17428
  this.logger.debug("OAuth access token", { hasOAuthToken: !!accessToken });
17424
17429
  if (!accessToken) {
17425
17430
  this.logger.debug("No OAuth access token in auth status, trying to get from AuthManager");
17426
- accessToken = await this.authManager.getAccessToken();
17431
+ try {
17432
+ accessToken = await this.authManager.getAccessToken();
17433
+ } catch {
17434
+ }
17427
17435
  this.logger.debug("Access token from AuthManager", { hasToken: !!accessToken });
17428
17436
  }
17429
17437
  if (!accessToken) {
17430
- this.logger.error("No access token available for API calls", {
17431
- hasOAuthToken: !!authStatus.tokens?.accessToken,
17432
- hasEphemeralCredentials: this.authManager.hasValidEphemeralCredentials()
17433
- });
17434
- throw new AuthenticationError(
17435
- "No access token available for API calls. Ephemeral credentials are only for SIP/WebRTC connections."
17438
+ this.logger.debug("No OAuth access token, checking ephemeral credentials for API token");
17439
+ const cachedCreds = this.authManager.getCachedEphemeralCredentials();
17440
+ if (cachedCreds?.apiToken) {
17441
+ accessToken = cachedCreds.apiToken;
17442
+ this.logger.debug("Using API token from ephemeral credentials");
17443
+ }
17444
+ }
17445
+ if (!accessToken) {
17446
+ this.logger.info(
17447
+ "No access token available - running in SIP-only mode (no transcription/API features)"
17436
17448
  );
17449
+ } else {
17450
+ this.accessToken = accessToken;
17451
+ this.logger.debug("\u2713 Access token obtained for API calls", {
17452
+ tokenLength: accessToken.length
17453
+ });
17437
17454
  }
17438
- this.accessToken = accessToken;
17439
- this.logger.debug("\u2713 Access token obtained for API calls", {
17440
- tokenLength: accessToken.length
17441
- });
17442
17455
  this.logger.debug("=== STEP 3: ENSURING EPHEMERAL CREDENTIALS ===");
17443
17456
  if (!this.ephemeralCredentials) {
17444
17457
  this.logger.debug("Getting ephemeral credentials");
@@ -17547,19 +17560,23 @@ var Conversation = class extends EventEmitter {
17547
17560
  this.setupSipHandlers();
17548
17561
  this.logger.debug("Registering with SIP server");
17549
17562
  await this.sipManager.register();
17550
- this.transcriptionService.setTokenRefreshCallback(async () => {
17551
- this.logger.debug("TranscriptionService requesting fresh token");
17552
- const freshToken = await this.authManager.getAccessToken();
17553
- if (!freshToken) {
17554
- throw new Error("Unable to get fresh access token");
17555
- }
17556
- this.accessToken = freshToken;
17557
- this.logger.debug("Fresh token provided to TranscriptionService");
17558
- return freshToken;
17559
- });
17560
- this.logger.debug("Starting transcription stream");
17561
- await this.transcriptionService.start(this.accessToken);
17562
- this.setupTranscriptionHandlers();
17563
+ if (this.accessToken) {
17564
+ this.transcriptionService.setTokenRefreshCallback(async () => {
17565
+ this.logger.debug("TranscriptionService requesting fresh token");
17566
+ const freshToken = await this.authManager.getAccessToken();
17567
+ if (!freshToken) {
17568
+ throw new Error("Unable to get fresh access token");
17569
+ }
17570
+ this.accessToken = freshToken;
17571
+ this.logger.debug("Fresh token provided to TranscriptionService");
17572
+ return freshToken;
17573
+ });
17574
+ this.logger.debug("Starting transcription stream");
17575
+ await this.transcriptionService.start(this.accessToken);
17576
+ this.setupTranscriptionHandlers();
17577
+ } else {
17578
+ this.logger.info("Skipping transcription service - no access token available");
17579
+ }
17563
17580
  this.logger.debug("Making call to resource", { resourceId: this.options.resource });
17564
17581
  const callOptions = {
17565
17582
  resourceId: this.options.resource,