25576b0be6
Checks (magui2.0) / python-lint (push) Failing after 1s
Checks (magui2.0) / python-test (push) Failing after 0s
Checks (magui2.0) / frontend-lint (push) Failing after 0s
CodeQL Advanced / Analyze (actions) (push) Failing after 1s
Checks (magui2.0) / python-format (push) Failing after 1s
CodeQL Advanced / Analyze (python) (push) Failing after 0s
Checks (magui2.0) / python-pyright (push) Failing after 1s
Checks (magui2.0) / frontend-format (push) Failing after 1s
Checks (magui2.0) / frontend-typecheck (push) Failing after 0s
Checks (magui2.0) / frontend-test (push) Failing after 2s
CodeQL Advanced / Analyze (javascript-typescript) (push) Failing after 1s
61 lines
2.0 KiB
TypeScript
61 lines
2.0 KiB
TypeScript
/**
|
|
* Final Answer Message
|
|
*
|
|
* Displays the agent's final answer with a "Final Answer" headline
|
|
* and formatted content below.
|
|
*/
|
|
|
|
import { Markdown } from '@/components/common'
|
|
import { HeaderedMessage } from './HeaderedMessage'
|
|
|
|
// =============================================================================
|
|
// Types
|
|
// =============================================================================
|
|
|
|
export interface FinalAnswerMessageProps {
|
|
/** Pre-extracted content from ParsedFinalAnswerMessage */
|
|
content: string
|
|
}
|
|
|
|
// =============================================================================
|
|
// Constants
|
|
// =============================================================================
|
|
|
|
/** Prefix to strip from content (backend includes this in the message) */
|
|
const FINAL_ANSWER_PREFIX = 'Final Answer:'
|
|
|
|
// =============================================================================
|
|
// Component
|
|
// =============================================================================
|
|
|
|
/**
|
|
* Renders final answer with styled headline and body content.
|
|
*
|
|
* Backend format: "Final Answer: <actual content>"
|
|
* UI format:
|
|
* Final Answer (headline)
|
|
* <actual content> (body)
|
|
*/
|
|
export function FinalAnswerMessage({ content }: FinalAnswerMessageProps) {
|
|
const bodyContent = extractBodyContent(content)
|
|
|
|
return (
|
|
<HeaderedMessage header="Final Answer" headerClassName="text-status-completed">
|
|
<Markdown>{bodyContent}</Markdown>
|
|
</HeaderedMessage>
|
|
)
|
|
}
|
|
|
|
// =============================================================================
|
|
// Helpers
|
|
// =============================================================================
|
|
|
|
/**
|
|
* Extract the body content by removing the "Final Answer: " prefix if present.
|
|
*/
|
|
function extractBodyContent(content: string): string {
|
|
// Remove "Final Answer: " prefix if present (case-insensitive, with optional whitespace)
|
|
const prefixRegex = new RegExp(`^${FINAL_ANSWER_PREFIX}\\s*`, 'i')
|
|
return content.replace(prefixRegex, '').trim()
|
|
}
|