@hamsa-ai/voice-agents-sdk 0.6.0-beta.3 → 0.6.0-beta.4

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
@@ -95,6 +95,57 @@ To end a conversation, simply call the "end" function:
95
95
  agent.end();
96
96
  ```
97
97
 
98
+ ## Chat (Text) Conversations
99
+
100
+ The SDK supports text-only chat sessions in addition to voice. In chat mode the
101
+ SDK connects to the agent without requesting microphone access, sends the user's
102
+ typed messages to the agent, and surfaces the agent's replies (including the
103
+ greeting) as they stream in.
104
+
105
+ Start a chat-only session by passing `isChatOnly: true` to `start()`:
106
+
107
+ ```javascript
108
+ const agent = new HamsaVoiceAgent(API_KEY);
109
+
110
+ // Receive the agent's chat replies (streaming-aware)
111
+ agent.on('chatMessageReceived', (message) => {
112
+ // message: { id, role: 'user' | 'agent', text, isFinal, timestamp }
113
+ // The same `id` is reused across streaming updates of one message, so you can
114
+ // update the same bubble in place; `isFinal` is false for partials, true when complete.
115
+ renderMessage(message);
116
+ });
117
+
118
+ // Optional: typing indicator while the agent composes a reply
119
+ agent.on('agentStateChanged', (state) => {
120
+ setTyping(state === 'thinking' || state === 'speaking');
121
+ });
122
+
123
+ // Start the chat-only session
124
+ await agent.start({ agentId: 'YOUR_AGENT_ID', isChatOnly: true });
125
+
126
+ // Send the user's typed message (published on the chat channel)
127
+ await agent.sendMessage('Hello, I need help with my order.');
128
+
129
+ // End the session when done
130
+ agent.end();
131
+ ```
132
+
133
+ ### Chat surface
134
+
135
+ | API | Purpose |
136
+ | --- | --- |
137
+ | `start({ isChatOnly: true })` | Begin a text-only session (no microphone prompt). |
138
+ | `sendMessage(text)` | Send the user's message to the agent. Emits `messageSent`. |
139
+ | `chatMessageReceived` event | Agent chat replies + greeting, with `{ id, role, text, isFinal, timestamp }`. Fires **only** for chat — never for voice transcriptions. |
140
+ | `agentStateChanged` event | Drive a typing indicator (`thinking` / `speaking`). |
141
+ | `end()` | End the chat session. |
142
+
143
+ > **Note:** Use `chatMessageReceived` for chat UIs — it is dedicated to chat and
144
+ > deterministic. The generic `messageReceived` event also fires for chat, but it
145
+ > is dual-sourced (it additionally fires for voice transcriptions). In a
146
+ > chat-only session the voice events (`answerReceived`, `transcriptionReceived`)
147
+ > and audio events do not fire — the conversation lives entirely on the chat channel.
148
+
98
149
  ## Advanced Audio Controls
99
150
 
100
151
  The SDK provides comprehensive audio control features for professional voice applications:
@@ -534,6 +585,10 @@ agent.on("transcriptionReceived", (text) => {
534
585
  agent.on("answerReceived", (text) => {
535
586
  console.log("Agent answer received", text);
536
587
  });
588
+ // Chat-only sessions: dedicated chat event (see "Chat (Text) Conversations")
589
+ agent.on("chatMessageReceived", (message) => {
590
+ console.log("Chat message received", message); // { id, role, text, isFinal, timestamp }
591
+ });
537
592
  ```
538
593
 
539
594
  ### Error Events