React SDK
Customize
Theme, features, cart and wishlist hand-off, slots, strings and white-label for the React SDK.
Everything is passed to CartesianProvider as options and listener. They can change at any time. Keep them in useMemo or outside your component so they are not rebuilt on every render.
<CartesianProvider client={cartesian} options={options} listener={listener} host={host}>tsxTheme
const options = {
title: "FreshMart",
theme: {
colors: { accent: "#1F6F43", primary: "#1F6F43", background: "#FFFFFF" },
fontFamily: "Inter, system-ui, sans-serif",
displayFontFamily: "Fraunces, serif",
emphasisFontFamily: "Fraunces, serif",
cornerRadius: 16,
showOrb: true,
},
};tsxAny CSS font family works. Load the font in your app as usual.
| Color | Default | Used for |
|---|---|---|
background | #FEFAF1 | Chat and panel background |
surface | #FFFFFF | Composer, cards, chips |
surfaceMuted | #F5F1E7 | Product image tiles |
line / lineStrong | #E9E5DC / #D6D2C9 | Borders |
ink | #000000 | Text, orb |
inkMuted / inkSubtle / inkFaint | #5E5E5E / #757575 / #9E9E9E | Secondary text and icons |
accent | #004CFF | Highlights, links, focus ring |
primary / onPrimary | #000000 / #FFFFFF | Buttons |
sale | #8C2B2B | Sale prices, errors |
success / successSoft | #2F6A4A / #EEF4F0 | In-cart state, cart updates |
badge | #8C2B2B | Wishlist count, saved hearts |
Each value becomes a CSS variable on the .cartesian-root element (--cx-accent, --cx-ink, --cx-font and so on), so you can also override them from your own CSS. cornerRadius sets the radius of cards (--cx-radius).
Features
features: {
cart: "host", // "builtIn" | "host" | "off"
wishlist: "off",
suggestions: "startersAndFollowUps", // "off" | "starters" | "startersAndFollowUps"
suggestionPlacement: "aboveComposer", // or "inline"
voice: true,
feedback: true,
newChat: true,
trace: true,
productTap: true,
}tsx| Feature | Default | Effect |
|---|---|---|
cart | builtIn | Add buttons, the header cart icon and cart update cards. host hands every action to your listener. off removes them. |
wishlist | builtIn | Hearts, the saved count and the Wishlist tab. |
suggestions | startersAndFollowUps | Welcome-screen starters, plus follow-up chips after each answer. Follow-ups come from POST /api/threads/{id}/suggest. |
suggestionPlacement | aboveComposer | One horizontal row of chips above the composer, hidden while an answer is running or the shopper is typing. inline shows up to three below the latest answer instead. |
voice | true | The microphone button. It uses the browser's Web Speech API and is hidden in browsers without it. |
feedback | true | Thumbs up and down, sent to POST /api/feedback. |
newChat | true | The new-chat button in the header. |
trace | true | The live activity trace above each answer. |
productTap | true | Clicking a product calls onProductSelected. |
Your own cart and wishlist
Set cart (and wishlist) to "host" and handle the actions:
const listener: CartesianListener = {
onAddToCart: (product, quantity) => myCart.add(product.sku ?? product.id, quantity),
onOpenCart: () => navigate("/cart"),
onToggleSaved: (product, saved) => myWishlist.set(product.id, saved),
onOpenWishlist: () => navigate("/saved"),
onProductSelected: (product) => navigate(`/p/${product.id}`),
onCheckout: (cart) => { navigate("/checkout"); return true; },
onEvent: (event) => analytics.track(event.type),
onSignInRequired: () => refreshCartesianToken(),
};tsxonAddToCart is called when the shopper clicks Add and also when the assistant adds items while it answers. The answer case is detected from the backend's cart updates, so an item that was already in the backend cart may not trigger it.
Keep the cards and header counts in sync with your cart through a CartesianHostState:
const host = useMemo(() => new CartesianHostState(), []);
useEffect(() => host.setCart({ [id]: quantity, /* … */ }), [myCartLines]);
useEffect(() => host.setSaved(mySavedIds), [mySavedIds]);
<CartesianProvider client={cartesian} host={host} …>tsxWith the built-in cart, the drawer's Checkout button calls onCheckout. Return true when you have taken over. Otherwise the shopper sees "Checkout isn't connected in this app yet."
Strings
strings: {
heading: { before: "What can I ", emphasis: "find", after: " for you?" },
subtitle: "Groceries, recipes and deals.",
placeholder: "Ask FreshMart",
disclaimer: "FreshMart's assistant can make mistakes.",
cartName: "basket",
signedOut: "Sign in to FreshMart to use the assistant.",
},
starters: ["Find eggs", "Plan dinner for two"],tsxThe emphasis part of the heading uses emphasisFontFamily.
Slots
Every part of the chat can be replaced with your own React component. A slot receives the controller (the same object useCartesian() returns) and its item:
| Slot | Props |
|---|---|
header | controller, onClose? |
emptyState, loading, composer, footer, drawer, offline, connectionStatus | controller |
userMessage | controller, message |
assistantMessage, trace, assistantText, messageActions | controller, message |
productList | controller, products |
productCard | controller, product |
comparison | controller, comparison |
cartUpdate | controller, update |
suggestions | controller, suggestions |
The default for each slot is exported in CartesianComponents, so a slot can wrap it:
import { CartesianComponents, type ProductSlotProps } from "@cogitx/cartesian-react";
function ProductCard({ product, controller }: ProductSlotProps) {
return (
<div className="with-ribbon">
{product.isOnSale ? <span className="ribbon">Deal</span> : null}
<CartesianComponents.ProductCard product={product} controller={controller} />
</div>
);
}
const options = { slots: { productCard: ProductCard } };tsxWhite-label
By default a small Powered by CogitX Cartesian line is shown under the composer. A white-label licence removes it:
new CartesianClient({ vertical: "grocery", baseUrl, licenseKey: import.meta.env.VITE_CARTESIAN_LICENSE });tsxThe licence is an ES256-signed token checked offline in the browser with WebCrypto and CogitX's public key. No network call is made. Its apps claim lists the hostnames it is valid for (shop.freshmart.com, or *.freshmart.com for subdomains); it is checked against location.hostname, or against appId if you set one. An expired, tampered or foreign licence keeps the SDK working and keeps the attribution.
import { verifyLicense } from "@cogitx/cartesian-react";
const licence = await verifyLicense(key, { appId: "shop.freshmart.com" });
licence.isValid; // false → licence.problem says why
licence.whiteLabel;tsAsk CogitX to include localhost and your preview hostnames if you want them white-labelled too.