@telnyx/ai-agent-widget 0.33.6 → 0.33.8-beta.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 +62 -9
- package/dist/bundle.min.js +32 -31
- package/package.json +6 -3
package/README.md
CHANGED
|
@@ -168,15 +168,68 @@ The widget emits DOM CustomEvents that you can listen to for tracking analytics,
|
|
|
168
168
|
|
|
169
169
|
### Available Events
|
|
170
170
|
|
|
171
|
-
| Event | Description
|
|
172
|
-
| -------------------------- |
|
|
173
|
-
| `agent.connected` | Agent connected to platform
|
|
174
|
-
| `agent.disconnected` | Agent disconnected from platform
|
|
175
|
-
| `agent.error` | Error occurred
|
|
176
|
-
| `transcript.item` | Transcript message received
|
|
177
|
-
| `conversation.update` | Conversation state updated
|
|
178
|
-
| `conversation.agent.state` | Agent state changed (listening/speaking/thinking)
|
|
179
|
-
| `agent.audio.mute` | Agent audio muted/unmuted
|
|
171
|
+
| Event | Description | Detail |
|
|
172
|
+
| -------------------------- | ---------------------------------------------------- | -------------------------------------------------------- |
|
|
173
|
+
| `agent.connected` | Agent connected to platform | - |
|
|
174
|
+
| `agent.disconnected` | Agent disconnected from platform | - |
|
|
175
|
+
| `agent.error` | Error occurred | `{ message, name }` |
|
|
176
|
+
| `transcript.item` | Transcript message received | `{ id, role, content, timestamp, attachments? }` |
|
|
177
|
+
| `conversation.update` | Conversation state updated | `{ type, callState }` |
|
|
178
|
+
| `conversation.agent.state` | Agent state changed (listening/speaking/thinking) | `{ state, userPerceivedLatencyMs?, thinkingStartedAt? }` |
|
|
179
|
+
| `agent.audio.mute` | Agent audio muted/unmuted | `{ muted }` |
|
|
180
|
+
| `client.tool.invoked` | A client-side tool was invoked by the agent | `{ callId, toolName }` |
|
|
181
|
+
| `client.tool.completed` | A client-side tool produced an output for the agent | `{ callId, toolName, isError }` |
|
|
182
|
+
| `client.tool.error` | A client-side tool failed; a safe error was returned | `{ callId, toolName, reason }` |
|
|
183
|
+
|
|
184
|
+
## Client-side Tools
|
|
185
|
+
|
|
186
|
+
The widget can execute **client-side tools** requested by the AI agent (for
|
|
187
|
+
example, looking something up in the page, reading local state, or triggering a
|
|
188
|
+
UI action) and return the result to the agent. This implements the PR-531
|
|
189
|
+
`client_side_tool` flow on top of [`@telnyx/ai-agent-lib`](https://www.npmjs.com/package/@telnyx/ai-agent-lib).
|
|
190
|
+
|
|
191
|
+
Because tool handlers are JavaScript functions, they cannot be passed as HTML
|
|
192
|
+
attributes. Instead, register them **imperatively** on the widget element:
|
|
193
|
+
|
|
194
|
+
```html
|
|
195
|
+
<telnyx-ai-agent agent-id="assistant-xxx"></telnyx-ai-agent>
|
|
196
|
+
|
|
197
|
+
<script>
|
|
198
|
+
const widget = document.querySelector('telnyx-ai-agent');
|
|
199
|
+
|
|
200
|
+
// Register a handler. `args` is the parsed JSON arguments object the agent
|
|
201
|
+
// sent; return any JSON-serializable value (or a string) as the result.
|
|
202
|
+
widget.registerClientTool('get_cart_total', async (args, context) => {
|
|
203
|
+
// context = { callId, toolName, rawArguments }
|
|
204
|
+
return { total: 42.5, currency: 'USD' };
|
|
205
|
+
});
|
|
206
|
+
|
|
207
|
+
// Inspect or remove handlers later:
|
|
208
|
+
widget.getClientTools(); // ['get_cart_total']
|
|
209
|
+
widget.unregisterClientTool('get_cart_total'); // true
|
|
210
|
+
|
|
211
|
+
// Observe execution via DOM events (payloads never include raw
|
|
212
|
+
// arguments/outputs — only safe correlation fields):
|
|
213
|
+
widget.addEventListener('client.tool.invoked', (e) =>
|
|
214
|
+
console.log('tool invoked', e.detail),
|
|
215
|
+
);
|
|
216
|
+
widget.addEventListener('client.tool.completed', (e) =>
|
|
217
|
+
console.log('tool completed', e.detail),
|
|
218
|
+
);
|
|
219
|
+
widget.addEventListener('client.tool.error', (e) =>
|
|
220
|
+
console.warn('tool error', e.detail),
|
|
221
|
+
);
|
|
222
|
+
</script>
|
|
223
|
+
```
|
|
224
|
+
|
|
225
|
+
Notes:
|
|
226
|
+
|
|
227
|
+
- Register handlers as early as you like — registrations are durable and are
|
|
228
|
+
automatically re-applied across the widget's internal reconnects.
|
|
229
|
+
- The library always returns a `function_call_output` to the agent (a safe
|
|
230
|
+
error payload on unknown tool, invalid arguments, handler throw, or timeout),
|
|
231
|
+
so a missing or failing handler never hangs the conversation.
|
|
232
|
+
- Raw tool arguments and outputs are never logged.
|
|
180
233
|
|
|
181
234
|
## Development
|
|
182
235
|
|