@hamsa-ai/voice-agents-sdk 0.3.1 → 4.0.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
@@ -1,6 +1,6 @@
1
1
  # Hamsa Voice Agents Web SDK
2
2
 
3
- Hamsa Voice Agents Web SDK is a JavaScript library for integrating voice agents from <https://dashboard.tryhamsa.com>. This SDK provides a seamless way to incorporate voice interactions into your web applications.
3
+ Hamsa Voice Agents Web SDK is a JavaScript library for integrating voice agents from <https://dashboard.tryhamsa.com>. This SDK provides a seamless way to incorporate voice interactions into your web applications with high-quality real-time audio communication.
4
4
 
5
5
  ## Installation
6
6
 
@@ -17,7 +17,7 @@ npm i @hamsa-ai/voice-agents-sdk
17
17
  First, import the package in your code:
18
18
 
19
19
  ```javascript
20
- import { HamsaVoiceAgent } from '@hamsa-ai/voice-agents-sdk'
20
+ import { HamsaVoiceAgent } from "@hamsa-ai/voice-agents-sdk";
21
21
  ```
22
22
 
23
23
  Initialize the SDK with your API key:
@@ -37,9 +37,11 @@ Include the script from a CDN:
37
37
  Then, you can initialize the agent like this:
38
38
 
39
39
  ```javascript
40
- const agent = new HamsaVoiceAgent('YOUR_API_KEY');
40
+ const agent = new HamsaVoiceAgent("YOUR_API_KEY");
41
41
 
42
- agent.on("callStarted", () => { console.log("Conversation has started!"); });
42
+ agent.on("callStarted", () => {
43
+ console.log("Conversation has started!");
44
+ });
43
45
 
44
46
  // Example: Start a call
45
47
  // agent.start({ agentId: 'YOUR_AGENT_ID' });
@@ -53,11 +55,11 @@ Start a conversation with an existing agent by calling the "start" function. You
53
55
 
54
56
  ```javascript
55
57
  agent.start({
56
- agentId: YOUR_AGENT_ID,
57
- params: {
58
- param1: "NAME",
59
- param2: "NAME2"
60
- }
58
+ agentId: YOUR_AGENT_ID,
59
+ params: {
60
+ param1: "NAME",
61
+ param2: "NAME2",
62
+ },
61
63
  });
62
64
  ```
63
65
 
@@ -92,29 +94,109 @@ During the conversation, the SDK emits events to update your application about t
92
94
  ### Conversation Status Events
93
95
 
94
96
  ```javascript
95
- agent.on("callStarted", () => { console.log("Conversation has started!"); });
96
- agent.on("callEnded", () => { console.log("Conversation has ended!"); });
97
- agent.on("callPaused", () => { console.log("The conversation is paused"); });
98
- agent.on("callResumed", () => { console.log("Conversation has resumed"); });
97
+ agent.on("callStarted", () => {
98
+ console.log("Conversation has started!");
99
+ });
100
+ agent.on("callEnded", () => {
101
+ console.log("Conversation has ended!");
102
+ });
103
+ agent.on("callPaused", () => {
104
+ console.log("The conversation is paused");
105
+ });
106
+ agent.on("callResumed", () => {
107
+ console.log("Conversation has resumed");
108
+ });
99
109
  ```
100
110
 
101
111
  ### Agent Status Events
102
112
 
103
113
  ```javascript
104
- agent.on("speaking", () => { console.log("The agent is speaking"); });
105
- agent.on("listening", () => { console.log("The agent is listening"); });
114
+ agent.on("speaking", () => {
115
+ console.log("The agent is speaking");
116
+ });
117
+ agent.on("listening", () => {
118
+ console.log("The agent is listening");
119
+ });
106
120
  ```
107
121
 
108
122
  ### Conversation Script Events
109
123
 
110
124
  ```javascript
111
- agent.on("transcriptionReceived", (text) => { console.log("User speech transcription received", text); });
112
- agent.on("answerReceived", (text) => { console.log("Agent answer received", text); });
125
+ agent.on("transcriptionReceived", (text) => {
126
+ console.log("User speech transcription received", text);
127
+ });
128
+ agent.on("answerReceived", (text) => {
129
+ console.log("Agent answer received", text);
130
+ });
113
131
  ```
114
132
 
115
133
  ### Error Events
116
134
 
117
135
  ```javascript
118
- agent.on("closed", () => { console.log("Conversation was closed"); });
119
- agent.on("error", (e) => { console.log("Error was received", e); });
136
+ agent.on("closed", () => {
137
+ console.log("Conversation was closed");
138
+ });
139
+ agent.on("error", (e) => {
140
+ console.log("Error was received", e);
141
+ });
142
+ ```
143
+
144
+ ## Configuration Options
145
+
146
+ The SDK accepts optional configuration parameters:
147
+
148
+ ```javascript
149
+ const agent = new HamsaVoiceAgent("YOUR_API_KEY", {
150
+ API_URL: "https://api.tryhamsa.com", // API endpoint (default)
151
+ });
152
+ ```
153
+
154
+ ## Client-Side Tools
155
+
156
+ You can register client-side tools that the agent can call during conversations:
157
+
158
+ ```javascript
159
+ const tools = [
160
+ {
161
+ function_name: "getUserInfo",
162
+ description: "Get user information",
163
+ parameters: [
164
+ {
165
+ name: "userId",
166
+ type: "string",
167
+ description: "User ID to look up",
168
+ },
169
+ ],
170
+ required: ["userId"],
171
+ fn: async (userId) => {
172
+ // Your tool implementation
173
+ const userInfo = await fetchUserInfo(userId);
174
+ return userInfo;
175
+ },
176
+ },
177
+ ];
178
+
179
+ agent.start({
180
+ agentId: "YOUR_AGENT_ID",
181
+ tools: tools,
182
+ voiceEnablement: true,
183
+ });
120
184
  ```
185
+
186
+ ## Migration from Previous Versions
187
+
188
+ If you're upgrading from a previous version, see the [Migration Guide](./MIGRATION_GUIDE.md) for detailed instructions. Connection details are now automatically managed and no longer need to be configured.
189
+
190
+ ## Browser Compatibility
191
+
192
+ This SDK supports modern browsers with WebRTC capabilities:
193
+
194
+ - Chrome 60+
195
+ - Firefox 60+
196
+ - Safari 12+
197
+ - Edge 79+
198
+
199
+ ## Dependencies
200
+
201
+ - **livekit-client**: Real-time communication infrastructure
202
+ - **events**: EventEmitter for browser compatibility