import '@distri/react/styles.css';
import { useMemo } from 'react';
import { DistriProvider, Chat } from '@distri/react';
import type { DistriFnTool } from '@distri/core';
import { useCart } from './cart';
export function ShopAssistant() {
const cart = useCart();
const tools = useMemo<DistriFnTool[]>(() => [{
name: 'add_to_cart',
description: 'Add a product to the cart',
type: 'function',
parameters: {
type: 'object',
properties: {
sku: { type: 'string' },
qty: { type: 'number' },
},
required: ['sku'],
},
autoExecute: true,
handler: async ({ sku, qty = 1 }) => {
await cart.add(sku, qty);
return { ok: true, items: cart.count };
},
}], [cart]);
return (
<DistriProvider config={{
baseUrl: 'https://api.distri.dev/v1',
clientId: 'dpc_…',
workspaceId: '…',
}}>
<Chat agentId="shop_assistant" externalTools={tools} />
</DistriProvider>
);
}