diff --git a/fern/tools/client-side-websdk.mdx b/fern/tools/client-side-websdk.mdx index 354de9a12..377fc21ab 100644 --- a/fern/tools/client-side-websdk.mdx +++ b/fern/tools/client-side-websdk.mdx @@ -12,7 +12,7 @@ Use the Web SDK to handle tool-calls entirely on the client. This lets your assi **In this guide, you'll learn to:** - Define a client-side tool with the Web SDK - Receive and handle `tool-calls` events on the client -- Inject extra context during a call with `addMessage` +- Inject extra context during a call with an `add-message` message Client-side tools cannot send a tool "result" back to the model. If the model must use the output of a tool to continue reasoning, implement a server-based tool instead. See: Server-based Function tools. @@ -32,7 +32,7 @@ npm install @vapi-ai/web 2. Start a call with your tool defined in the model.tools array and subscribe to clientMessages: ['tool-calls']. 3. Listen for message.type === 'tool-calls' and perform the desired UI update. No response is sent back to the model. -4. (Optional) Inject context mid-call using vapi.addMessage(...). +4. (Optional) Inject context mid-call using `vapi.send({ type: 'add-message', ... })`. ## Complete example (React + Web SDK) @@ -264,19 +264,25 @@ export default App; ## Inject data during the call -Use addMessage to provide extra context mid-call. This does not return results for a tool; it adds messages the model can see. +Send an add-message message with vapi.send to provide extra context mid-call. This does not return results for a tool; it adds messages the model can see. By default triggerResponseEnabled is set to true and the assistant should respond to the new message right away. ```ts // Inject system-level context -vapi.addMessage({ - role: 'system', - content: 'Context: userId=123, plan=premium, theme=dark', +vapi.send({ + type: 'add-message', + message: { + role: 'system', + content: 'Context: userId=123, plan=premium, theme=dark', + }, }); // Inject a user message -vapi.addMessage({ - role: 'user', - content: 'FYI: I switched to the settings tab.', +vapi.send({ + type: 'add-message', + message: { + role: 'user', + content: 'FYI: I switched to the settings tab.', + }, }); ``` @@ -289,7 +295,7 @@ If you need the model to consume tool outputs (e.g., fetch data and conti - **Client-only execution**: Omit the server URL to run tools on the client. - **One-way side effects**: Client tools do not send results back to the model. - **Subscribe to events**: Use clientMessages: ['tool-calls'] and handle message.type === 'tool-calls'. -- **Add context**: Use vapi.addMessage to inject data mid-call. +- **Add context**: Use vapi.send with an add-message message to inject data mid-call. ## Next steps