Skip to content

armgit / dify

Public Imported from GitHub
0

Build Agentic workflows, RAG pipelines, with rich AI model and tool support on one collaborative workspace. Deploy on cloud, VPC, or self-hosted, so teams move from prototype to production without rebuilding the stack.

fix: frontend for <think> tags conflicting with original <details> tags (#14039)

Junjie.Md96c368660a0
diff --git a/web/app/components/base/markdown-blocks/think-block.tsx b/web/app/components/base/markdown-blocks/think-block.tsx
index b68aff293de..3398502cfdc 100644
--- a/web/app/components/base/markdown-blocks/think-block.tsx
+++ b/web/app/components/base/markdown-blocks/think-block.tsx
@@ -68,6 +68,9 @@ export const ThinkBlock = ({ children, ...props }: any) => {
const displayContent = removeEndThink(children)
const { t } = useTranslation()
+ if (!(props['data-think'] ?? false))
+ return (<details {...props}>{children}</details>)
+
return (
<details {...(!isComplete && { open: true })} className="group">
<summary className="text-gray-500 font-bold list-none pl-2 flex items-center cursor-pointer select-none whitespace-nowrap">
diff --git a/web/app/components/base/markdown.tsx b/web/app/components/base/markdown.tsx
index 8689d44a1c4..51c54b7d7d5 100644
--- a/web/app/components/base/markdown.tsx
+++ b/web/app/components/base/markdown.tsx
@@ -68,13 +68,9 @@ const preprocessLaTeX = (content: string) => {
}
const preprocessThinkTag = (content: string) => {
- if (!(content.trim().startsWith('<think>\n') || content.trim().startsWith('<details style=')))
- return content
-
return flow([
- (str: string) => str.replaceAll('<think>\n', '<details>\n'),
- (str: string) => str.replaceAll('\n</think>', '\n[ENDTHINKFLAG]</details>'),
- (str: string) => str.replaceAll('\n</details>', '\n[ENDTHINKFLAG]</details>'),
+ (str: string) => str.replace('<think>\n', '<details data-think=true>\n'),
+ (str: string) => str.replace('\n</think>', '\n[ENDTHINKFLAG]</details>'),
])(content)
}