Foco: matar repetición y adaptar respuestas. Los handlers tenían ~30 strings hardcodeadas (3-7 lugares cada una). Aliases hacían substring exacto. - pg_trgm + GIN indexes en product_aliases / alias_product_mappings. Captura plurales, diminutivos, typos sin reglas. catalogRetrieval re-busca el snapshot con normalized_alias cuando el query original no rinde (vasio→vacio→Vacío). - reply_templates table + replyTemplates.js. 20 keys, 2-3 variantes c/u con DEFAULTS hardcodeados como fallback. pickVariant excluye las usadas en context.recent_replies (FIFO cap 8). Wired en idle/cart/cartHelpers/ shipping/payment/waiting. - failed_searches counter en context. count>=3 escala via humanFallback. Reset en cada add_to_cart exitoso. - storeContext.js: vars derivadas de getStoreConfig (delivery_zones, hours, zonas) listas para inyectar en templates cuando los datos se carguen. - replyRewriter.js: LLM call opcional (REPLY_REWRITER=1) que adapta el template al hilo conversacional. 1.5s timeout, fallback al template puro. Sólo activo en 8 slots semánticamente importantes. - 12 unit tests para replyTemplates (rotation, recency, FIFO, vars). 208 tests totales pasando. Plan completo: ~/.claude/plans/ok-creo-que-tiene-humming-sutton.md Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
25 lines
896 B
SQL
25 lines
896 B
SQL
-- migrate:up
|
|
-- Templates de respuestas con variantes para evitar repetición.
|
|
-- Filosofía: cada slot semántico (ej. cart.ask_more) tiene N variantes;
|
|
-- el código rota entre ellas excluyendo las recientemente usadas.
|
|
CREATE TABLE reply_templates (
|
|
id SERIAL PRIMARY KEY,
|
|
tenant_id UUID NOT NULL REFERENCES tenants(id) ON DELETE CASCADE,
|
|
template_key VARCHAR(80) NOT NULL,
|
|
variant INTEGER NOT NULL DEFAULT 1,
|
|
content TEXT NOT NULL,
|
|
weight INTEGER NOT NULL DEFAULT 1,
|
|
is_active BOOLEAN NOT NULL DEFAULT true,
|
|
created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
|
|
updated_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
|
|
CONSTRAINT uq_reply_variant UNIQUE(tenant_id, template_key, variant)
|
|
);
|
|
|
|
CREATE INDEX idx_reply_active
|
|
ON reply_templates(tenant_id, template_key)
|
|
WHERE is_active = true;
|
|
|
|
-- migrate:down
|
|
DROP INDEX IF EXISTS idx_reply_active;
|
|
DROP TABLE IF EXISTS reply_templates;
|