Passa al contenuto principale

Ricerca Prodotti & Product Cards

Ricerca semantica, recupero dettagli dallo store WooCommerce e generazione di card HTML.

Ricerca semantica prodotti (RAG)

/main/src/agentTools/semanticProductSearchTool.ts
export const semanticProductSearchTool = tool(async ({ textQuery, sku }, runnable_config) => {
const configurable = runnable_config.configurable as CustomConfigurable
const collectionName = configurable?.collection_name
const ragResults = await performRagSearch({ textQuery, collectionName })
return ragResults
}, { name: 'productSemanticSearch', /* schema ... */ })

Recupero prodotti + card HTML

/main/src/agentTools/productWebSearchTool.ts
export const productWebSearchTool = tool(async ({ productIds, min_price, max_price, on_sale, return_type }, runnable_config) => {
const configurable = runnable_config.configurable as CustomConfigurable
const woocommerceRestApi = await createWooCommerceRestApi(configurable?.laravelAppUrl, configurable?.websiteUrl, configurable.agent_id)
const wooProducts = (await woocommerceRestApi.get('products', { queryParams: { per_page: 5, include: productIds, status: 'publish', /* filters */ } })) ?? []
// ...adattamento e generazione card
return products
}, { name: 'productWebSearch', /* schema ... */ })

Generazione HTML delle card

/main/src/agentTools/productWebSearchTool.ts
const productCardTemplate = `
<div class="product-card">
<!-- immagine, titolo, prezzi, varianti, azioni -->
</div>
`.toString().replaceAll('\n','').replaceAll('\r','').replaceAll('\t','')