Files
DeepTutor/web/components/common/AssistantResponse.tsx
Bingxi Zhao (Frank) 4b7d24d33e release: v1.2.3 — document attachments, thinking blocks, provider core refactor
- Chat document attachments (PDF/DOCX/XLSX/PPTX) with text extraction
- Reasoning model <think> block display as collapsible cards
- Tri-state send_dimensions toggle for embeddings (#368)
- LLM provider_core module refactor + context_window detection
- Soul template editor (PR #373), Co-Writer save-to-notebook
- Knowledge Base drag-and-drop upload, delete resilience (#370),
  progress persistence, supported-file-types endpoint
- Question generation language fidelity via shared prompt directives
- Settings tour redesign, CLI notebook add-md/replace-md
- Bug fixes: CJK bot name slug, I18nProvider init, Skills default off,
  Moonshot base URL, version badge
- Provider registry: custom_anthropic, thinking_style, alias expansion
- +1900 test lines across 15 new/expanded test files

Made-with: Cursor
2026-04-24 22:36:32 +08:00

66 lines
1.9 KiB
TypeScript

"use client";
import { Fragment, useMemo } from "react";
import MarkdownRenderer from "@/components/common/MarkdownRenderer";
import ModelThinkingCard from "@/components/common/ModelThinkingCard";
import { hasVisibleMarkdownContent } from "@/lib/markdown-display";
import { parseModelThinkingSegments } from "@/lib/think-segments";
interface AssistantResponseProps {
content: string;
className?: string;
}
export default function AssistantResponse({
content,
className = "text-[14px] leading-[1.75]",
}: AssistantResponseProps) {
const segments = useMemo(
() => parseModelThinkingSegments(content),
[content],
);
// Decide whether the message has anything worth rendering. We consider both
// ordinary markdown segments and model-thinking blocks: a turn that only
// ever produced a <think> scratchpad should still render the collapsed card
// instead of dropping the assistant bubble entirely.
const hasRenderableSegment = useMemo(() => {
return segments.some((segment) => {
if (segment.kind === "think") return segment.content.trim().length > 0;
return hasVisibleMarkdownContent(segment.content);
});
}, [segments]);
if (!hasRenderableSegment) return null;
return (
<div className={className}>
{segments.map((segment, index) => {
if (segment.kind === "think") {
return (
<ModelThinkingCard
key={`think-${index}`}
content={segment.content}
closed={segment.closed}
/>
);
}
if (!hasVisibleMarkdownContent(segment.content)) {
return <Fragment key={`text-${index}`} />;
}
return (
<MarkdownRenderer
key={`text-${index}`}
content={segment.content}
variant="prose"
className="text-[var(--foreground)]"
/>
);
})}
</div>
);
}