Interactive cart sync demo — see events firing in real-time between the widget and this simulated host cart.
Waiting for events... Open the widget and interact with the chat.
Cart is empty. Add sample items below or ask the AI to add products via the chat widget.
Test cross-tab sync: add, remove, update, or empty the cart via full chat and watch events appear here via Socket.IO cart-updated push.
Open Full Chat (new tab) →// Waiting for cart events...
The widget and your host page communicate via DOM events on window. Your adapter bridges these events to your store's cart API. Cart requests are always served from the server (not local cache).
Host adapter mounts → fires xinfer:cart:ready → widget fires xinfer:cart:request → host responds with xinfer:cart:response → widget stores host cart in memory → init merge: aligns both carts
Either side fires xinfer:cart:request → other side responds with its cart → widget fetches from GET /api/embed/cart → host responds from in-memory state
AI calls shopping_cart tool (add/remove/update) → widget DB updated server-side → widget fires xinfer:cart:action → host adapter applies the mutation
AI mutates cart from full chat tab → server emits cart-updated to user room → widget tab receives via Socket.IO → dispatches DOM events to host adapter → works for add, remove, update, empty
AI calls shopping_cart "submit" → order created, cart emptied → widget fires xinfer:cart:action (empty) → host adapter empties its cart
User checks out on host site → adapter detects cart went empty → fires xinfer:cart:action (empty) → widget calls DELETE /api/embed/cart
| Event | Direction | Payload |
|---|---|---|
xinfer:cart:ready | Host → Widget | {} |
xinfer:cart:request | Either → Either | { source } |
xinfer:cart:response | Either → Either | { source, items: XinferCartItem[] } |
xinfer:cart:action | Either → Either | { source, action, item?, items? } |
| Action | Description |
|---|---|
add | Add item to cart. Resolved via id, sku, url, or title. |
remove | Remove item by id |
update | Update item quantity |
empty | Clear all items (checkout or manual clear) |
sync | Replace cart with provided items array (full sync) |
All events are CustomEvents on window. Each includes a source field ("host" or "widget") to prevent loops — only handle events from the other side.
The chat widget is embedded on this page with cartSync: true. Open the chat and ask the AI to add an item to your cart — watch the events fire above.