@anam-ai/agent-widget 0.3.1 → 0.4.0-alpha.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
@@ -126,6 +126,9 @@ The widget dispatches custom DOM events on the `<anam-agent>` element:
126
126
  | `anam-agent:error` | `{ code, message }` | Error occurred |
127
127
  | `anam-agent:mic-muted` | `{}` | Microphone muted |
128
128
  | `anam-agent:mic-unmuted` | `{}` | Microphone unmuted |
129
+ | `anam-agent:tool-call-started` | `{ toolName, toolCallId, toolType, toolSubtype?, arguments }` | Agent invoked a tool |
130
+ | `anam-agent:tool-call-completed` | `{ toolName, toolCallId, toolType, toolSubtype?, result, executionTime, documentsAccessed? }` | Tool call finished (`executionTime` in ms; `documentsAccessed` is RAG-only) |
131
+ | `anam-agent:tool-call-failed` | `{ toolName, toolCallId, toolType, toolSubtype?, errorMessage, executionTime }` | Tool call failed (`executionTime` in ms) |
129
132
 
130
133
  ```javascript
131
134
  document.querySelector('anam-agent').addEventListener('anam-agent:session-started', (e) => {
@@ -133,6 +136,23 @@ document.querySelector('anam-agent').addEventListener('anam-agent:session-starte
133
136
  });
134
137
  ```
135
138
 
139
+ ### Reacting to tool calls
140
+
141
+ When your agent invokes a client-side tool (e.g. `redirect`, `add_to_cart`), the
142
+ widget surfaces it as a DOM event so your page can act on it — no SDK wiring
143
+ required. The `toolType` field distinguishes client-side tools from server-side
144
+ ones, so you can react only to the ones meant for the browser:
145
+
146
+ ```javascript
147
+ document.querySelector('anam-agent').addEventListener('anam-agent:tool-call-started', (e) => {
148
+ const { toolName, toolType, arguments: args } = e.detail;
149
+ if (toolType !== 'client') return; // server-side tools run on Anam's side
150
+ if (toolName === 'redirect') {
151
+ window.location.href = args.url;
152
+ }
153
+ });
154
+ ```
155
+
136
156
  ## Development
137
157
 
138
158
  ### Prerequisites