fix: remove thinking tag on projects list message history

This commit is contained in:
Faisal Amir 2025-09-30 11:08:31 +07:00
parent 54d17c9c72
commit 1c9890649d
3 changed files with 18 additions and 22 deletions

View File

@ -3,6 +3,7 @@ import { create } from 'zustand'
import { RenderMarkdown } from './RenderMarkdown'
import { useAppState } from '@/hooks/useAppState'
import { useTranslation } from '@/i18n/react-i18next-compat'
import { extractThinkingContent } from '@/lib/utils'
interface Props {
text: string
@ -43,19 +44,6 @@ const ThinkingBlock = ({ id, text }: Props) => {
setThinkingState(id, newExpandedState)
}
// Extract thinking content from either format
const extractThinkingContent = (text: string) => {
return text
.replace(/<\/?think>/g, '')
.replace(/<\|channel\|>analysis<\|message\|>/g, '')
.replace(/<\|start\|>assistant<\|channel\|>final<\|message\|>/g, '')
.replace(/assistant<\|channel\|>final<\|message\|>/g, '')
.replace(/<\|channel\|>/g, '') // remove any remaining channel markers
.replace(/<\|message\|>/g, '') // remove any remaining message markers
.replace(/<\|start\|>/g, '') // remove any remaining start markers
.trim()
}
const thinkingContent = extractThinkingContent(text)
if (!thinkingContent) return null

View File

@ -23,7 +23,7 @@ import { useThreads } from '@/hooks/useThreads'
import { useThreadManagement } from '@/hooks/useThreadManagement'
import { useLeftPanel } from '@/hooks/useLeftPanel'
import { useMessages } from '@/hooks/useMessages'
import { cn } from '@/lib/utils'
import { cn, extractThinkingContent } from '@/lib/utils'
import { useSmallScreen } from '@/hooks/useMediaQuery'
import {
@ -167,14 +167,10 @@ const SortableItem = memo(
)}
>
<span>{thread.title || t('common:newThread')}</span>
{variant === 'project' && (
<>
{variant === 'project' && getLastMessageInfo?.content && (
<div className="text-sm text-main-view-fg/60 mt-0.5 line-clamp-2">
{getLastMessageInfo.content}
</div>
)}
</>
{variant === 'project' && getLastMessageInfo?.content && (
<span className="block text-sm text-main-view-fg/60 mt-0.5 truncate">
{extractThinkingContent(getLastMessageInfo.content)}
</span>
)}
</div>
<div className="flex items-center">

View File

@ -165,3 +165,15 @@ export function formatDuration(startTime: number, endTime?: number): string {
export function sanitizeModelId(modelId: string): string {
return modelId.replace(/[^a-zA-Z0-9/_\-.]/g, '').replace(/\./g, '_')
}
export const extractThinkingContent = (text: string) => {
return text
.replace(/<\/?think>/g, '')
.replace(/<\|channel\|>analysis<\|message\|>/g, '')
.replace(/<\|start\|>assistant<\|channel\|>final<\|message\|>/g, '')
.replace(/assistant<\|channel\|>final<\|message\|>/g, '')
.replace(/<\|channel\|>/g, '') // remove any remaining channel markers
.replace(/<\|message\|>/g, '') // remove any remaining message markers
.replace(/<\|start\|>/g, '') // remove any remaining start markers
.trim()
}