Class: AdminSuite::Renderers::LegacyGleania::MessagesPreviewRenderer
- Inherits:
-
AdminSuite::Renderer
- Object
- AdminSuite::Renderer
- AdminSuite::Renderers::LegacyGleania::MessagesPreviewRenderer
- Defined in:
- lib/admin_suite/renderers/legacy_gleania.rb
Overview
Verbatim from BaseHelper#render_messages_preview.
Instance Attribute Summary
Attributes inherited from AdminSuite::Renderer
Instance Method Summary collapse
Methods inherited from AdminSuite::Renderer
Constructor Details
This class inherits a constructor from AdminSuite::Renderer
Instance Method Details
#render ⇒ Object
85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 |
# File 'lib/admin_suite/renderers/legacy_gleania.rb', line 85 def render LegacyGleania.warn_once(:messages_preview) = record.respond_to?(:messages) ? record. : [] if .respond_to?(:chronological) = .chronological end = .limit(50) if .respond_to?(:limit) = Array.wrap() return content_tag(:p, "No messages", class: "text-slate-500 italic") if .blank? content_tag(:div, class: "space-y-4 max-h-[600px] overflow-y-auto -mx-6 -mb-6 p-6 pt-0") do .each_with_index do |msg, idx| if msg.respond_to?(:role) role = msg.role content = msg.content created_at = msg.respond_to?(:created_at) ? msg.created_at : nil else role = msg["role"] || msg[:role] || "unknown" content = msg["content"] || msg[:content] || "" created_at = msg["created_at"] || msg[:created_at] end role_class = case role.to_s when "user" then "bg-blue-50 border-blue-200" when "assistant" then "bg-emerald-50 border-emerald-200" when "tool" then "bg-amber-50 border-amber-200" when "system" then "bg-slate-50 border-slate-200" else "bg-slate-50 border-slate-200" end role_icon = case role.to_s when "user" '<svg class="w-4 h-4 text-blue-500" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M16 7a4 4 0 11-8 0 4 4 0 018 0zM12 14a7 7 0 00-7 7h14a7 7 0 00-7-7z"/></svg>'.html_safe when "assistant" '<svg class="w-4 h-4 text-emerald-500" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 3v2m6-2v2M9 19v2m6-2v2M5 9H3m2 6H3m18-6h-2m2 6h-2M7 19h10a2 2 0 002-2V7a2 2 0 00-2-2H7a2 2 0 00-2 2v10a2 2 0 002 2zM9 9h6v6H9V9z"/></svg>'.html_safe when "tool" '<svg class="w-4 h-4 text-amber-500" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M10.325 4.317c.426-1.756 2.924-1.756 3.35 0a1.724 1.724 0 002.573 1.066c1.543-.94 3.31.826 2.37 2.37a1.724 1.724 0 001.065 2.572c1.756.426 1.756 2.924 0 3.35a1.724 1.724 0 00-1.066 2.573c.94 1.543-.826 3.31-2.37 2.37a1.724 1.724 0 00-2.572 1.065c-.426 1.756-2.924 1.756-3.35 0a1.724 1.724 0 00-2.573-1.066c-1.543.94-3.31-.826-2.37-2.37a1.724 1.724 0 00-1.065-2.572c-1.756-.426-1.756-2.924 0-3.35a1.724 1.724 0 001.066-2.573c-.94-1.543.826-3.31 2.37-2.37.996.608 2.296.07 2.572-1.065z"/></svg>'.html_safe else '<svg class="w-4 h-4 text-slate-400" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M8 12h.01M12 12h.01M16 12h.01M21 12c0 4.418-4.03 8-9 8a9.863 9.863 0 01-4.255-.949L3 20l1.395-3.72C3.512 15.042 3 13.574 3 12c0-4.418 4.03-8 9-8s9 3.582 9 8z"/></svg>'.html_safe end view.concat(content_tag(:div, class: "rounded-lg border p-4 #{role_class}") do view.concat(content_tag(:div, class: "flex items-center justify-between mb-3") do view.concat(content_tag(:div, class: "flex items-center gap-2") do view.concat(role_icon) view.concat(content_tag(:span, role.to_s.capitalize, class: "text-sm font-medium text-slate-700")) end) view.concat(content_tag(:div, class: "flex items-center gap-2 text-xs text-slate-400") do view.concat(content_tag(:span, created_at.strftime("%H:%M:%S"))) if created_at.respond_to?(:strftime) view.concat(content_tag(:span, "##{idx + 1}")) end) end) content_str = content.to_s if role.to_s == "tool" && content_str.start_with?("{", "[") begin parsed = JSON.parse(content_str) view.concat(view.render_json_block(parsed)) rescue JSON::ParserError view.concat(content_tag(:div, view.simple_format(h(content_str)), class: "prose prose-sm max-w-none")) end else view.concat(content_tag(:div, view.simple_format(h(content_str)), class: "prose prose-sm max-w-none")) end end) end end end |