| 1 | import { WarningMessage } from "core"; |
| 2 | import { ReactElement } from "react"; |
| 3 | import ExpendableBox from "./ExpendableBox"; |
| 4 | |
| 5 | function MessageBox({ |
| 6 | warningMessage, |
| 7 | actions, |
| 8 | }: { |
| 9 | warningMessage: WarningMessage; |
| 10 | actions?: (() => ReactElement)[]; |
| 11 | }) { |
| 12 | const warningMessageTextColor = |
| 13 | warningMessage.level === "fatal" ? "text-error" : "text-warning"; |
| 14 | const warningMessageBorderColor = |
| 15 | warningMessage.level === "fatal" ? "border-error" : "border-warning"; |
| 16 | return ( |
| 17 | <div |
| 18 | className={`relative m-2 flex flex-col rounded-md border border-solid ${warningMessageBorderColor} bg-transparent p-4`} |
| 19 | > |
| 20 | <p className={`thread-message ${warningMessageTextColor}`}> |
| 21 | <b>Warning: </b> |
| 22 | {`${warningMessage.message}`} |
| 23 | </p> |
| 24 | {actions && ( |
| 25 | <div> |
| 26 | <p>{`Recommended Action${actions.length > 1 ? "s" : ""}:`}</p> |
| 27 | <ul> |
| 28 | {actions.map((action, ind) => { |
| 29 | return <li key={`warning-action-${ind}`}>{action()}</li>; |
| 30 | })} |
| 31 | </ul> |
| 32 | </div> |
| 33 | )} |
| 34 | </div> |
| 35 | ); |
| 36 | } |
| 37 | |
| 38 | export default function WarningMessageBox({ |
| 39 | warningMessage, |
| 40 | actions, |
| 41 | }: { |
| 42 | warningMessage: WarningMessage; |
| 43 | actions?: (() => ReactElement)[]; |
| 44 | }) { |
| 45 | if (warningMessage.category === "exceeded-context-length") { |
| 46 | return ( |
| 47 | <ExpendableBox |
| 48 | children={ |
| 49 | <MessageBox warningMessage={warningMessage} actions={actions} /> |
| 50 | } |
| 51 | /> |
| 52 | ); |
| 53 | } |
| 54 | return <MessageBox warningMessage={warningMessage} actions={actions} />; |
| 55 | } |