@hamsa-ai/voice-agents-sdk 0.4.6 → 0.5.0-beta.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.
package/README.md CHANGED
@@ -39,8 +39,8 @@ Then, you can initialize the agent like this:
39
39
  ```javascript
40
40
  const agent = new HamsaVoiceAgent("YOUR_API_KEY");
41
41
 
42
- agent.on("callStarted", () => {
43
- console.log("Conversation has started!");
42
+ agent.on("callStarted", ({ jobId }) => {
43
+ console.log("Conversation has started! Job ID:", jobId);
44
44
  });
45
45
 
46
46
  // Example: Start a call
@@ -423,6 +423,70 @@ agent.start({
423
423
  });
424
424
  ```
425
425
 
426
+ ## Job/Call ID Tracking
427
+
428
+ Track and reference conversations using unique job IDs. The SDK provides two ways to access the job/call ID:
429
+
430
+ ### Getting Job ID from Events (Recommended)
431
+
432
+ The `callStarted` event includes the job ID in its data object:
433
+
434
+ ```javascript
435
+ agent.on("callStarted", ({ jobId }) => {
436
+ console.log("Call started with ID:", jobId);
437
+
438
+ // Send to analytics service
439
+ analytics.trackCall(jobId);
440
+
441
+ // Store for later reference
442
+ localStorage.setItem("lastCallId", jobId);
443
+ });
444
+ ```
445
+
446
+ ### Getting Job ID with Getter Method
447
+
448
+ Access the job ID anytime after the call has started:
449
+
450
+ ```javascript
451
+ // Get current job ID
452
+ const jobId = agent.getJobId();
453
+
454
+ if (jobId) {
455
+ console.log("Current call ID:", jobId);
456
+ } else {
457
+ console.log("No active call");
458
+ }
459
+
460
+ // Use in other events
461
+ agent.on("transcriptionReceived", (text) => {
462
+ const jobId = agent.getJobId();
463
+ saveTranscript(jobId, text);
464
+ });
465
+
466
+ // Check completion status later
467
+ agent.on("callEnded", async () => {
468
+ const jobId = agent.getJobId();
469
+ if (jobId) {
470
+ const details = await agent.getJobDetails();
471
+ console.log("Call completed:", details);
472
+ }
473
+ });
474
+ ```
475
+
476
+ ### TypeScript Support
477
+
478
+ ```typescript
479
+ import { CallStartedData } from '@hamsa-ai/voice-agents-sdk';
480
+
481
+ // Event-based (with destructuring)
482
+ agent.on("callStarted", ({ jobId }: CallStartedData) => {
483
+ console.log("Job ID:", jobId); // string
484
+ });
485
+
486
+ // Getter-based
487
+ const jobId: string | null = agent.getJobId();
488
+ ```
489
+
426
490
  ## Events
427
491
 
428
492
  During the conversation, the SDK emits events to update your application about the conversation status.
@@ -430,8 +494,8 @@ During the conversation, the SDK emits events to update your application about t
430
494
  ### Conversation Status Events
431
495
 
432
496
  ```javascript
433
- agent.on("callStarted", () => {
434
- console.log("Conversation has started!");
497
+ agent.on("callStarted", ({ jobId }) => {
498
+ console.log("Conversation has started with ID:", jobId);
435
499
  });
436
500
  agent.on("callEnded", () => {
437
501
  console.log("Conversation has ended!");
@@ -788,6 +852,7 @@ import {
788
852
  AudioCaptureOptions,
789
853
  AudioCaptureMetadata,
790
854
  CallAnalyticsResult,
855
+ CallStartedData,
791
856
  ParticipantData,
792
857
  CustomEventMetadata,
793
858
  } from "@hamsa-ai/voice-agents-sdk";
@@ -803,6 +868,9 @@ const participants = agent.getParticipants(); // ParticipantData[]
803
868
  const trackStats = agent.getTrackStats(); // TrackStatsResult | null
804
869
  const analytics = agent.getCallAnalytics(); // CallAnalyticsResult | null
805
870
 
871
+ // Job ID access
872
+ const jobId = agent.getJobId(); // string | null
873
+
806
874
  // Advanced audio control methods
807
875
  const outputVolume = agent.getOutputVolume(); // number
808
876
  const inputVolume = agent.getInputVolume(); // number
@@ -844,6 +912,11 @@ await agent.start({
844
912
  });
845
913
 
846
914
  // Strongly typed event handlers
915
+ agent.on("callStarted", ({ jobId }: CallStartedData) => {
916
+ console.log("Job ID:", jobId); // string
917
+ // Track conversation start
918
+ });
919
+
847
920
  agent.on("analyticsUpdated", (analytics: CallAnalyticsResult) => {
848
921
  console.log(analytics.connectionStats.quality); // string
849
922
  console.log(analytics.audioMetrics.userAudioLevel); // number