Cartesiandocs

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}>
tsx

Theme

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,
  },
};
tsx

Any CSS font family works. Load the font in your app as usual.

ColorDefaultUsed for
background#FEFAF1Chat and panel background
surface#FFFFFFComposer, cards, chips
surfaceMuted#F5F1E7Product image tiles
line / lineStrong#E9E5DC / #D6D2C9Borders
ink#000000Text, orb
inkMuted / inkSubtle / inkFaint#5E5E5E / #757575 / #9E9E9ESecondary text and icons
accent#004CFFHighlights, links, focus ring
primary / onPrimary#000000 / #FFFFFFButtons
sale#8C2B2BSale prices, errors
success / successSoft#2F6A4A / #EEF4F0In-cart state, cart updates
badge#8C2B2BWishlist 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
FeatureDefaultEffect
cartbuiltInAdd buttons, the header cart icon and cart update cards. host hands every action to your listener. off removes them.
wishlistbuiltInHearts, the saved count and the Wishlist tab.
suggestionsstartersAndFollowUpsWelcome-screen starters, plus follow-up chips after each answer. Follow-ups come from POST /api/threads/{id}/suggest.
suggestionPlacementaboveComposerOne 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.
voicetrueThe microphone button. It uses the browser's Web Speech API and is hidden in browsers without it.
feedbacktrueThumbs up and down, sent to POST /api/feedback.
newChattrueThe new-chat button in the header.
tracetrueThe live activity trace above each answer.
productTaptrueClicking 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(),
};
tsx

onAddToCart 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} …>
tsx

With 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"],
tsx

The 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:

SlotProps
headercontroller, onClose?
emptyState, loading, composer, footer, drawer, offline, connectionStatuscontroller
userMessagecontroller, message
assistantMessage, trace, assistantText, messageActionscontroller, message
productListcontroller, products
productCardcontroller, product
comparisoncontroller, comparison
cartUpdatecontroller, update
suggestionscontroller, 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 } };
tsx

White-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 });
tsx

The 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;
ts

Ask CogitX to include localhost and your preview hostnames if you want them white-labelled too.