productos, equivalencias, cross-sell y cantidades

This commit is contained in:
Lucas Tettamanti
2026-01-18 18:28:28 -03:00
parent 8cc4744c49
commit c7c56ddbfc
32 changed files with 4083 additions and 2073 deletions

View File

@@ -170,14 +170,50 @@ class ConversationInspector extends HTMLElement {
if (!list.length) return "—";
return list
.map((it) => {
const label = it.label || it.name || `#${it.product_id}`;
const qty = it.quantity != null ? `${it.quantity}` : "?";
const label = it.label || it.name || `#${it.product_id || it.woo_id}`;
const qty = it.quantity ?? it.qty ?? "?";
const unit = it.unit || "";
return `${label} (${qty}${unit ? " " + unit : ""})`;
})
.join(" · ");
}
formatOrder(cart, pending, order) {
const parts = [];
// Cart items
const cartList = Array.isArray(cart) ? cart : [];
if (cartList.length > 0) {
const cartStr = cartList
.map((it) => {
const label = it.label || it.name || `#${it.product_id || it.woo_id}`;
const qty = it.quantity ?? it.qty ?? "?";
const unit = it.unit || "";
return `${label} (${qty}${unit ? " " + unit : ""})`;
})
.join(" · ");
parts.push(cartStr);
}
// Pending items
const pendingList = Array.isArray(pending) ? pending : [];
const activePending = pendingList.filter(p => p.status !== "READY");
if (activePending.length > 0) {
parts.push(`[${activePending.length} pendiente(s)]`);
}
// Checkout info
const checkoutInfo = [];
if (order?.is_delivery === true) checkoutInfo.push("🚚");
if (order?.is_delivery === false) checkoutInfo.push("🏪");
if (order?.payment_type === "cash") checkoutInfo.push("💵");
if (order?.payment_type === "link") checkoutInfo.push("💳");
if (order?.is_paid) checkoutInfo.push("✅");
if (checkoutInfo.length) parts.push(checkoutInfo.join(""));
return parts.length ? parts.join(" ") : "—";
}
toolSummary(tools = []) {
return tools.map((t) => ({
type: t.type || t.name || "tool",
@@ -218,7 +254,10 @@ class ConversationInspector extends HTMLElement {
const intent = run?.llm_output?.intent || "—";
const nextState = run?.llm_output?.next_state || "—";
const prevState = row.nextRun?.prev_state || "—";
const basket = run?.llm_output?.full_basket?.items || run?.llm_output?.basket_resolved?.items || [];
// Usar orden nueva si está disponible, sino fallback a formato viejo
const order = run?.order || {};
const basket = order.cart || run?.llm_output?.full_basket?.items || run?.llm_output?.basket_resolved?.items || [];
const pendingItems = order.pending || [];
const tools = this.toolSummary(run?.tools || []);
const llmMeta = run?.llm_output?._llm || null;
@@ -240,7 +279,7 @@ class ConversationInspector extends HTMLElement {
<div class="k">NLU</div>
<div class="v">${dir === "out" && llmMeta ? llmNote : "—"}</div>
</div>
<div class="cart"><strong>Carrito:</strong> ${dir === "out" ? this.formatCart(basket) : "—"}</div>
<div class="cart"><strong>Carrito:</strong> ${dir === "out" ? this.formatOrder(basket, pendingItems, order) : "—"}</div>
<div class="chips">
${tools
.map(