Ctrl K
ComunidadGuías…

scripts/_widget-response-parser.cjs

Rama main · réplica de lectura del repositorio original.

Archivo original ↗Preguntar a KiBot
'use strict';

function parseWidgetAgentResponse(text, maxHtml) {
  const source = String(text ?? '');
  const htmlMatch = source.match(/<!--\s*widget-html\s*-->([\s\S]*?)<!--\s*\/widget-html\s*-->/);
  const titleMatch = source.match(/<!--\s*title:\s*([^\n]+?)\s*-->/);
  const html = (htmlMatch?.[1] ?? '').slice(0, maxHtml);

  return {
    html,
    title: titleMatch?.[1]?.trim() ?? 'Custom Widget',
    hasHtmlMarkers: Boolean(htmlMatch),
    isComplete: Boolean(htmlMatch && html.trim()),
  };
}

module.exports = { parseWidgetAgentResponse };