diff --git a/web/components/shared/markdownEditor.tsx b/web/components/shared/markdownEditor.tsx index fa95ad556..b15177307 100644 --- a/web/components/shared/markdownEditor.tsx +++ b/web/components/shared/markdownEditor.tsx @@ -1,3 +1,11 @@ +import { highlight, languages } from "prismjs"; +import "prismjs/components/prism-clike"; +import "prismjs/components/prism-javascript"; +import "prismjs/components/prism-json"; +import "prismjs/components/prism-markdown"; +import "prismjs/components/prism-markup-templating"; +import "prismjs/themes/prism.css"; +import Editor from "react-simple-code-editor"; import { Editor as MonacoEditor } from "@monaco-editor/react"; import { editor } from "monaco-editor"; import { useTheme } from "next-themes"; @@ -13,7 +21,7 @@ interface MarkdownEditorProps { } const MAX_EDITOR_HEIGHT = 500; -const MarkdownEditor = (props: MarkdownEditorProps) => { +const MonacoMarkdownEditor = (props: MarkdownEditorProps) => { const { text, setText, @@ -35,27 +43,94 @@ const MarkdownEditor = (props: MarkdownEditorProps) => { ); return ( - + setText(value || "")} + language={language} + theme={currentTheme === "dark" ? "vs-dark" : "vs-light"} + onMount={(editor) => + editor.onDidContentSizeChange(() => updateHeight(editor)) + } + options={{ + minimap: { enabled: false }, + fontSize: 12, + fontFamily: '"Fira Code", "Fira Mono", monospace', + readOnly: disabled, + wordWrap: "on", + lineNumbers: "off", + language: "markdown", + scrollBeyondLastLine: false, // Prevents extra space at bottom + automaticLayout: true, // Enables auto-resizing + }} + className={className} + height={height} + /> + + Helicone: Large text detected, falling back to large text editor + + + ); +}; + +interface MarkdownEditorProps { + text: string; + setText: (text: string) => void; + language: "json" | "markdown"; + disabled?: boolean; + className?: string; + textareaClassName?: string; +} + +const LARGE_TEXT_THRESHOLD = 50; + +const MarkdownEditor = (props: MarkdownEditorProps) => { + const { + text, + setText, + language, + disabled = false, + className, + textareaClassName, + } = props; + + const languageMap = { + json: { + lang: languages.json, + ref: "json", + }, + markdown: { + lang: languages.markdown, + ref: "markdown", + }, + }; + + const { lang, ref } = languageMap[language]; + if (text.split("\n").length > LARGE_TEXT_THRESHOLD) { + return ; + } + + return ( + setText(value || "")} - language={language} - theme={currentTheme === "dark" ? "vs-dark" : "vs-light"} - onMount={(editor) => - editor.onDidContentSizeChange(() => updateHeight(editor)) + onValueChange={setText} + highlight={(code) => { + if (!code) return ""; + if (typeof code !== "string") return ""; + return highlight(code, lang, ref); + }} + padding={16} + className={ + className ?? + `text-sm text-black dark:text-white border border-gray-300 dark:border-gray-700 rounded-lg whitespace-pre-wrap ` } - options={{ - minimap: { enabled: false }, - fontSize: 12, + textareaClassName={textareaClassName ?? ""} + // mono font + style={{ fontFamily: '"Fira Code", "Fira Mono", monospace', - readOnly: disabled, - wordWrap: "on", - lineNumbers: "off", - language: "markdown", - scrollBeyondLastLine: false, // Prevents extra space at bottom - automaticLayout: true, // Enables auto-resizing + fontSize: 12, }} - className={className} - height={height} + disabled={disabled} /> ); }; diff --git a/web/components/templates/prompts/experiments/table/AddColumnDialog.tsx b/web/components/templates/prompts/experiments/table/AddColumnDialog.tsx index bff93b72f..8f25ce77b 100644 --- a/web/components/templates/prompts/experiments/table/AddColumnDialog.tsx +++ b/web/components/templates/prompts/experiments/table/AddColumnDialog.tsx @@ -106,7 +106,7 @@ const AddColumnDialog = ({ : onOpenChange } > - +
diff --git a/web/components/templates/prompts/experiments/table/components/tableElementsRenderer.tsx b/web/components/templates/prompts/experiments/table/components/tableElementsRenderer.tsx index ba5e290bb..f79fbc78f 100644 --- a/web/components/templates/prompts/experiments/table/components/tableElementsRenderer.tsx +++ b/web/components/templates/prompts/experiments/table/components/tableElementsRenderer.tsx @@ -245,7 +245,7 @@ const ExperimentTableHeader = (props: ExperimentHeaderProps) => { />
- +
@@ -265,14 +265,14 @@ const ExperimentTableHeader = (props: ExperimentHeaderProps) => {
- + {!isOriginal && ( Preview Diff )} - + { className="border rounded-md border-slate-200 dark:border-slate-700" /> - + - Auto input {index}:{" "} + Message {index}:{" "} {JSON.stringify(input)} ))} diff --git a/web/components/templates/prompts/id/MessageRendererComponent.tsx b/web/components/templates/prompts/id/MessageRendererComponent.tsx index e2a18c8e5..631c20645 100644 --- a/web/components/templates/prompts/id/MessageRendererComponent.tsx +++ b/web/components/templates/prompts/id/MessageRendererComponent.tsx @@ -29,6 +29,16 @@ interface MessageRendererComponentProps { requestMessages: any; responseMessage: any; } +// +function getAutoPromptIndex(api: string) { + const autoPromptIndex = api.match( + // + ); + if (autoPromptIndex) { + return parseInt(autoPromptIndex[1]); + } + return -1; +} const MessageRendererComponent: React.FC = ({ messages, @@ -56,7 +66,11 @@ const MessageRendererComponent: React.FC = ({ {messages.map((message, index) => typeof message === "string" ? ( message.startsWith("Auto Prompt Input +
+ + Message {getAutoPromptIndex(message)} + +
) : ( "bye" ) diff --git a/web/components/templates/prompts/id/promptPlayground.tsx b/web/components/templates/prompts/id/promptPlayground.tsx index 4c97327a2..4731faf11 100644 --- a/web/components/templates/prompts/id/promptPlayground.tsx +++ b/web/components/templates/prompts/id/promptPlayground.tsx @@ -106,13 +106,6 @@ const PromptPlayground: React.FC = ({ ); }; - // Helper function to check if a message is a Helicone auto-prompt input - const isHeliconeAutoPromptInput = (msg: any): boolean => { - return ( - typeof msg === "string" && msg.startsWith("("Pretty"); const [isEditMode, setIsEditMode] = useState(defaultEditMode); const [currentChat, setCurrentChat] = useState(() => @@ -270,7 +263,7 @@ const PromptPlayground: React.FC = ({ isEditMode={isEditMode} setIsEditMode={setIsEditMode} /> -
+