summaryrefslogtreecommitdiff
path: root/Omni
diff options
context:
space:
mode:
Diffstat (limited to 'Omni')
-rw-r--r--Omni/Jr/Web.hs27
1 files changed, 24 insertions, 3 deletions
diff --git a/Omni/Jr/Web.hs b/Omni/Jr/Web.hs
index d191454..aa8d4de 100644
--- a/Omni/Jr/Web.hs
+++ b/Omni/Jr/Web.hs
@@ -19,6 +19,7 @@ where
import Alpha
import qualified Control.Concurrent as Concurrent
import qualified Data.Aeson as Aeson
+import qualified Data.Aeson.KeyMap as KeyMap
import qualified Data.ByteString.Lazy as LBS
import qualified Data.List as List
import qualified Data.Text as Text
@@ -2469,7 +2470,7 @@ renderAssistantEvent content timestamp now =
Lucid.div_ [Lucid.class_ "event-content event-bubble"] <| do
let truncated = Text.take 2000 content
isTruncated = Text.length content > 2000
- Lucid.toHtml truncated
+ renderTextWithNewlines truncated
when isTruncated <| Lucid.span_ [Lucid.class_ "event-truncated"] "..."
renderToolCallEvent :: (Monad m) => Text -> UTCTime -> UTCTime -> Lucid.HtmlT m ()
@@ -2498,8 +2499,8 @@ renderToolResultEvent content timestamp now =
then
Lucid.details_ [Lucid.class_ "result-collapsible"] <| do
Lucid.summary_ "Show output"
- Lucid.pre_ [Lucid.class_ "event-content tool-output"] (Lucid.toHtml content)
- else Lucid.pre_ [Lucid.class_ "event-content tool-output"] (Lucid.toHtml content)
+ Lucid.pre_ [Lucid.class_ "event-content tool-output"] (renderDecodedToolResult content)
+ else Lucid.pre_ [Lucid.class_ "event-content tool-output"] (renderDecodedToolResult content)
renderCostEvent :: (Monad m) => Text -> Lucid.HtmlT m ()
renderCostEvent content =
@@ -2540,6 +2541,26 @@ renderCollapsibleOutput content =
Lucid.pre_ [Lucid.class_ "tool-output-pre"] (Lucid.toHtml content)
else Lucid.pre_ [Lucid.class_ "tool-output-pre"] (Lucid.toHtml content)
+-- | Render text with literal \n replaced by <br> tags
+renderTextWithNewlines :: (Monad m) => Text -> Lucid.HtmlT m ()
+renderTextWithNewlines txt =
+ let parts = Text.splitOn "\\n" txt
+ in traverse_ renderPart (zip [0 ..] parts)
+ where
+ renderPart (idx, part) = do
+ Lucid.toHtml part
+ when (idx < length parts - 1) <| Lucid.br_ []
+
+-- | Decode JSON tool result and render in a user-friendly way
+renderDecodedToolResult :: (Monad m) => Text -> Lucid.HtmlT m ()
+renderDecodedToolResult content =
+ case Aeson.decode (LBS.fromStrict (str content)) of
+ Just (Aeson.Object obj) ->
+ case KeyMap.lookup "output" obj of
+ Just (Aeson.String output) -> Lucid.toHtml output
+ _ -> Lucid.toHtml content -- Fallback to raw if no output field
+ _ -> Lucid.toHtml content -- Fallback to raw if not JSON
+
agentLogScrollScript :: (Monad m) => Lucid.HtmlT m ()
agentLogScrollScript =
Lucid.script_