-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
checkpoint: output debug logs in chat transcript
- Loading branch information
Showing
13 changed files
with
641 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
import React, { useState } from "react"; | ||
import Markdown from "react-markdown"; | ||
import { DEBUG_SPEAKER } from "../constants"; | ||
import { ChatMessage } from "../types"; | ||
|
||
interface IProps { | ||
message: ChatMessage; | ||
showDebugLog: boolean; | ||
} | ||
|
||
export const ChatTranscriptMessage = ({message, showDebugLog}: IProps) => { | ||
const { speaker, messageContent, timestamp } = message; | ||
const [showMessage, setShowMessage] = useState(false); | ||
|
||
if (speaker === DEBUG_SPEAKER && !showDebugLog) { | ||
return null; | ||
} | ||
|
||
const renderDebugPreview = () => { | ||
const expandedClass = showMessage ? "expanded" : "collapsed"; | ||
return ( | ||
<div className={`debug-message-wrapper ${expandedClass}`}> | ||
<div className="header"> | ||
<button | ||
onClick={() => setShowMessage(!showMessage)} | ||
> | ||
<span>{showMessage ? "Collapse content" : "Expand content"}</span> | ||
</button> | ||
<h4>{messageContent.description}:</h4> | ||
</div> | ||
<pre | ||
aria-expanded={showMessage} | ||
> | ||
{messageContent.content} | ||
</pre> | ||
</div> | ||
); | ||
}; | ||
|
||
const speakerClass = speaker === DEBUG_SPEAKER ? "debug" : speaker.toLowerCase(); | ||
|
||
return ( | ||
<section | ||
aria-label={`${speaker} at ${timestamp}`} | ||
className={`chat-transcript__message ${speakerClass}`} | ||
data-testid="chat-message" | ||
role="listitem" | ||
> | ||
<h3 aria-label="speaker" data-testid="chat-message-speaker"> | ||
{speaker} | ||
</h3> | ||
<div | ||
aria-label="message" | ||
className={`chat-message-content ${speakerClass}`} | ||
data-testid="chat-message-content" | ||
> | ||
{speaker === DEBUG_SPEAKER ? | ||
renderDebugPreview() : | ||
<Markdown>{messageContent.content}</Markdown> | ||
} | ||
</div> | ||
</section> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
export const DEBUG_SPEAKER = "Debug Log"; | ||
export const DAVAI_SPEAKER = "DAVAI"; | ||
export const USER_SPEAKER = "User"; |
Oops, something went wrong.