Skip to content

Commit 1d88438

Browse files
authored
🎨 Incorrect rendering for examples in generated promt & chat interface. #688
2 parents 54d0ae0 + 177fb45 commit 1d88438

File tree

8 files changed

+808
-953
lines changed

8 files changed

+808
-953
lines changed

‎frontend/app/[locale]/layout.tsx‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ import { ThemeProvider as NextThemesProvider } from "next-themes";
88
import I18nProviderWrapper from "@/components/providers/I18nProviderWrapper";
99

1010
import "@/styles/globals.css";
11+
import "@/styles/react-markdown.css";
12+
import "github-markdown-css/github-markdown.css";
13+
import "katex/dist/katex.min.css";
1114
import log from "@/lib/logger";
1215

1316
const inter = Inter({ subsets: ["latin"] });

‎frontend/app/[locale]/setup/agents/components/PromptManager.tsx‎

Lines changed: 145 additions & 155 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,6 @@ import {
88
LoadingOutlined,
99
InfoCircleOutlined,
1010
} from "@ant-design/icons";
11-
import { MilkdownProvider, Milkdown, useEditor } from "@milkdown/react";
12-
import { defaultValueCtx, Editor, rootCtx } from "@milkdown/kit/core";
13-
import { commonmark } from "@milkdown/kit/preset/commonmark";
14-
import { nord } from "@milkdown/theme-nord";
15-
import { listener, listenerCtx } from "@milkdown/kit/plugin/listener";
1611

1712
import {
1813
SimplePromptEditorProps,
@@ -24,60 +19,42 @@ import { ModelOption } from "@/types/modelConfig";
2419

2520
import AgentConfigModal from "./agent/AgentConfigModal";
2621

27-
import "@/styles/milkdown-nord.css";
2822
import log from "@/lib/logger";
2923

3024
export function SimplePromptEditor({
3125
value,
3226
onChange,
33-
height = "100%",
27+
height,
28+
bordered = false,
3429
}: SimplePromptEditorProps) {
3530
const [internalValue, setInternalValue] = useState(value);
36-
const [editorKey, setEditorKey] = useState(0);
3731
const isInternalChange = useRef(false);
3832

39-
// Update editor when external value changes
4033
useEffect(() => {
41-
if (value !== internalValue) {
42-
// Only force update editor when change comes from external source
43-
if (!isInternalChange.current) {
44-
setInternalValue(value);
45-
setEditorKey((prev) => prev + 1);
46-
}
34+
if (value !== internalValue && !isInternalChange.current) {
35+
setInternalValue(value);
4736
}
48-
49-
// Reset the flag after each value or internalValue change if marked as internal change.
50-
// This ensures that the next external change can be correctly identified after internal editing.
5137
if (isInternalChange.current) {
5238
isInternalChange.current = false;
5339
}
5440
}, [value, internalValue]);
5541

56-
const { get } = useEditor(
57-
(root) =>
58-
Editor.make()
59-
.config((ctx) => {
60-
ctx.set(rootCtx, root);
61-
ctx.set(defaultValueCtx, internalValue || "");
62-
})
63-
.config(nord)
64-
.use(commonmark)
65-
.use(listener)
66-
.config((ctx) => {
67-
const listenerManager = ctx.get(listenerCtx);
68-
listenerManager.markdownUpdated((ctx, markdown) => {
69-
isInternalChange.current = true;
70-
setInternalValue(markdown);
71-
onChange(markdown);
72-
});
73-
}),
74-
[editorKey]
75-
); // Only recreate when editorKey changes
76-
7742
return (
78-
<div className="milkdown-editor-container" style={{ height }}>
79-
<Milkdown key={editorKey} />
80-
</div>
43+
<Input.TextArea
44+
value={internalValue}
45+
onChange={(e) => {
46+
isInternalChange.current = true;
47+
setInternalValue(e.target.value);
48+
onChange(e.target.value);
49+
}}
50+
style={
51+
height
52+
? { height, resize: "none", overflow: "auto" }
53+
: { resize: "none", overflow: "hidden" }
54+
}
55+
autoSize={height ? false : { minRows: 8 }}
56+
bordered={bordered}
57+
/>
8158
);
8259
}
8360

@@ -164,15 +141,30 @@ function ExpandEditModal({
164141
}}
165142
>
166143
<div
167-
className="flex flex-col"
144+
className="flex flex-col expand-edit-gray-textarea"
168145
style={{ height: `${calculateModalHeight(editContent)}vh` }}
169146
>
170-
<div className="flex-1 border border-gray-200 rounded-md overflow-y-auto">
147+
<style jsx global>{`
148+
.expand-edit-gray-textarea .ant-input,
149+
.expand-edit-gray-textarea .ant-input:hover,
150+
.expand-edit-gray-textarea .ant-input:focus,
151+
.expand-edit-gray-textarea .ant-input-focused,
152+
.expand-edit-gray-textarea .ant-input-textarea,
153+
.expand-edit-gray-textarea .ant-input-textarea:hover,
154+
.expand-edit-gray-textarea .ant-input-textarea:focus,
155+
.expand-edit-gray-textarea .ant-input-textarea:focus-within {
156+
border-color: #d9d9d9 !important;
157+
box-shadow: none !important;
158+
}
159+
`}</style>
160+
<div className="flex-1 min-h-0">
171161
<SimplePromptEditor
172162
value={editContent}
173163
onChange={(newContent) => {
174164
setEditContent(newContent);
175165
}}
166+
bordered={true}
167+
height={"100%"}
176168
/>
177169
</div>
178170
</div>
@@ -268,7 +260,7 @@ export default function PromptManager({
268260
// Modal states
269261
const [expandModalOpen, setExpandModalOpen] = useState(false);
270262
const [expandIndex, setExpandIndex] = useState(0);
271-
263+
272264
// Model selection states
273265
const [availableModels, setAvailableModels] = useState<ModelOption[]>([]);
274266
const [loadingModels, setLoadingModels] = useState(false);
@@ -296,7 +288,7 @@ export default function PromptManager({
296288
const handleModelSelect = (model: ModelOption) => {
297289
onModelSelect?.(model);
298290
setShowModelDropdown(false);
299-
291+
300292
// Auto-trigger generation after model selection
301293
if (onGenerateAgent) {
302294
onGenerateAgent(model);
@@ -309,7 +301,7 @@ export default function PromptManager({
309301
message.warning(t("businessLogic.config.error.noAvailableModels"));
310302
return;
311303
}
312-
304+
313305
setShowModelDropdown(true);
314306
};
315307

@@ -381,55 +373,54 @@ export default function PromptManager({
381373
};
382374

383375
return (
384-
<MilkdownProvider>
385-
<div className="flex flex-col h-full relative">
386-
<style jsx global>{`
387-
@media (max-width: 768px) {
388-
.system-prompt-container {
389-
overflow-y: auto !important;
390-
max-height: none !important;
391-
}
392-
.system-prompt-content {
393-
min-height: auto !important;
394-
max-height: none !important;
395-
}
376+
<div className="flex flex-col h-full relative">
377+
<style jsx global>{`
378+
@media (max-width: 768px) {
379+
.system-prompt-container {
380+
overflow-y: auto !important;
381+
max-height: none !important;
396382
}
397-
@media (max-width: 1024px) {
398-
.system-prompt-business-logic {
399-
min-height: 100px !important;
400-
max-height: 150px !important;
401-
}
383+
.system-prompt-content {
384+
min-height: auto !important;
385+
max-height: none !important;
402386
}
403-
`}</style>
404-
405-
{/* Non-editing mode overlay */}
406-
{!isEditingMode && (
407-
<div className="absolute inset-0 bg-white bg-opacity-95 flex items-center justify-center z-50 transition-all duration-300 ease-out animate-in fade-in-0">
408-
<div className="text-center space-y-4 animate-in fade-in-50 duration-400 delay-50">
409-
<InfoCircleOutlined className="text-6xl text-gray-400 transition-all duration-300 animate-in zoom-in-75 delay-100" />
410-
<div className="animate-in slide-in-from-bottom-2 duration-300 delay-150">
411-
<h3 className="text-lg font-medium text-gray-700 mb-2 transition-all duration-300">
412-
{t("systemPrompt.nonEditing.title")}
413-
</h3>
414-
<p className="text-sm text-gray-500 transition-all duration-300">
415-
{t("systemPrompt.nonEditing.subtitle")}
416-
</p>
417-
</div>
387+
}
388+
@media (max-width: 1024px) {
389+
.system-prompt-business-logic {
390+
min-height: 100px !important;
391+
max-height: 150px !important;
392+
}
393+
}
394+
`}</style>
395+
396+
{/* Non-editing mode overlay */}
397+
{!isEditingMode && (
398+
<div className="absolute inset-0 bg-white bg-opacity-95 flex items-center justify-center z-50 transition-all duration-300 ease-out animate-in fade-in-0">
399+
<div className="text-center space-y-4 animate-in fade-in-50 duration-400 delay-50">
400+
<InfoCircleOutlined className="text-6xl text-gray-400 transition-all duration-300 animate-in zoom-in-75 delay-100" />
401+
<div className="animate-in slide-in-from-bottom-2 duration-300 delay-150">
402+
<h3 className="text-lg font-medium text-gray-700 mb-2 transition-all duration-300">
403+
{t("systemPrompt.nonEditing.title")}
404+
</h3>
405+
<p className="text-sm text-gray-500 transition-all duration-300">
406+
{t("systemPrompt.nonEditing.subtitle")}
407+
</p>
418408
</div>
419409
</div>
420-
)}
410+
</div>
411+
)}
421412

422-
{/* Main title */}
423-
<div className="flex justify-between items-center mb-2">
424-
<div className="flex items-center">
425-
<div className="flex items-center justify-center w-6 h-6 rounded-full bg-blue-500 text-white text-sm font-medium mr-2">
426-
3
427-
</div>
428-
<h2 className="text-lg font-medium">
429-
{t("guide.steps.describeBusinessLogic.title")}
430-
</h2>
413+
{/* Main title */}
414+
<div className="flex justify-between items-center mb-2">
415+
<div className="flex items-center">
416+
<div className="flex items-center justify-center w-6 h-6 rounded-full bg-blue-500 text-white text-sm font-medium mr-2">
417+
3
431418
</div>
419+
<h2 className="text-lg font-medium">
420+
{t("guide.steps.describeBusinessLogic.title")}
421+
</h2>
432422
</div>
423+
</div>
433424

434425
{/* Main content */}
435426
<div className="flex-1 flex flex-col border-t pt-2 system-prompt-container overflow-hidden">
@@ -497,72 +488,71 @@ export default function PromptManager({
497488
</div>
498489
</div>
499490

500-
{/* Agent configuration section */}
501-
<div className="flex-1 min-h-0 system-prompt-content">
502-
<AgentConfigModal
503-
agentId={agentId}
504-
dutyContent={dutyContent}
505-
constraintContent={constraintContent}
506-
fewShotsContent={fewShotsContent}
507-
onDutyContentChange={onDutyContentChange}
508-
onConstraintContentChange={onConstraintContentChange}
509-
onFewShotsContentChange={onFewShotsContentChange}
510-
agentName={agentName}
511-
agentDescription={agentDescription}
512-
onAgentNameChange={onAgentNameChange}
513-
onAgentDescriptionChange={onAgentDescriptionChange}
514-
agentDisplayName={agentDisplayName}
515-
onAgentDisplayNameChange={onAgentDisplayNameChange}
516-
isEditingMode={isEditingMode}
517-
mainAgentModel={mainAgentModel}
518-
mainAgentMaxStep={mainAgentMaxStep}
519-
onModelChange={onModelChange}
520-
onMaxStepChange={onMaxStepChange}
521-
onSavePrompt={handleSavePrompt}
522-
onExpandCard={handleExpandCard}
523-
isGeneratingAgent={isGeneratingAgent}
524-
onDebug={onDebug}
525-
onExportAgent={onExportAgent}
526-
onDeleteAgent={onDeleteAgent}
527-
onDeleteSuccess={onDeleteSuccess}
528-
onSaveAgent={onSaveAgent}
529-
isCreatingNewAgent={isCreatingNewAgent}
530-
editingAgent={editingAgent}
531-
canSaveAgent={canSaveAgent}
532-
getButtonTitle={getButtonTitle}
533-
/>
534-
</div>
491+
{/* Agent configuration section */}
492+
<div className="flex-1 min-h-0 system-prompt-content">
493+
<AgentConfigModal
494+
agentId={agentId}
495+
dutyContent={dutyContent}
496+
constraintContent={constraintContent}
497+
fewShotsContent={fewShotsContent}
498+
onDutyContentChange={onDutyContentChange}
499+
onConstraintContentChange={onConstraintContentChange}
500+
onFewShotsContentChange={onFewShotsContentChange}
501+
agentName={agentName}
502+
agentDescription={agentDescription}
503+
onAgentNameChange={onAgentNameChange}
504+
onAgentDescriptionChange={onAgentDescriptionChange}
505+
agentDisplayName={agentDisplayName}
506+
onAgentDisplayNameChange={onAgentDisplayNameChange}
507+
isEditingMode={isEditingMode}
508+
mainAgentModel={mainAgentModel}
509+
mainAgentMaxStep={mainAgentMaxStep}
510+
onModelChange={onModelChange}
511+
onMaxStepChange={onMaxStepChange}
512+
onSavePrompt={handleSavePrompt}
513+
onExpandCard={handleExpandCard}
514+
isGeneratingAgent={isGeneratingAgent}
515+
onDebug={onDebug}
516+
onExportAgent={onExportAgent}
517+
onDeleteAgent={onDeleteAgent}
518+
onDeleteSuccess={onDeleteSuccess}
519+
onSaveAgent={onSaveAgent}
520+
isCreatingNewAgent={isCreatingNewAgent}
521+
editingAgent={editingAgent}
522+
canSaveAgent={canSaveAgent}
523+
getButtonTitle={getButtonTitle}
524+
/>
535525
</div>
536-
537-
{/* Expand edit modal */}
538-
<ExpandEditModal
539-
key={`expand-modal-${expandIndex}-${
540-
expandModalOpen ? "open" : "closed"
541-
}`}
542-
title={
543-
expandIndex === 1
544-
? t("systemPrompt.expandEdit.backgroundInfo")
545-
: expandIndex === 2
546-
? t("systemPrompt.card.duty.title")
547-
: expandIndex === 3
548-
? t("systemPrompt.card.constraint.title")
549-
: t("systemPrompt.card.fewShots.title")
550-
}
551-
open={expandModalOpen}
552-
content={
553-
expandIndex === 1
554-
? businessLogic
555-
: expandIndex === 2
556-
? dutyContent
557-
: expandIndex === 3
558-
? constraintContent
559-
: fewShotsContent
560-
}
561-
index={expandIndex}
562-
onClose={() => setExpandModalOpen(false)}
563-
onSave={handleExpandSave}
564-
/>
565526
</div>
566-
</MilkdownProvider>
527+
528+
{/* Expand edit modal */}
529+
<ExpandEditModal
530+
key={`expand-modal-${expandIndex}-${
531+
expandModalOpen ? "open" : "closed"
532+
}`}
533+
title={
534+
expandIndex === 1
535+
? t("systemPrompt.expandEdit.backgroundInfo")
536+
: expandIndex === 2
537+
? t("systemPrompt.card.duty.title")
538+
: expandIndex === 3
539+
? t("systemPrompt.card.constraint.title")
540+
: t("systemPrompt.card.fewShots.title")
541+
}
542+
open={expandModalOpen}
543+
content={
544+
expandIndex === 1
545+
? businessLogic
546+
: expandIndex === 2
547+
? dutyContent
548+
: expandIndex === 3
549+
? constraintContent
550+
: fewShotsContent
551+
}
552+
index={expandIndex}
553+
onClose={() => setExpandModalOpen(false)}
554+
onSave={handleExpandSave}
555+
/>
556+
</div>
567557
);
568-
}
558+
}

0 commit comments

Comments
 (0)