MCPcopy Create free account
hub / github.com/Seanium/ChatMap / ChatInterface

Function ChatInterface

components/chat-interface.tsx:39–550  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

37}
38
39export default function ChatInterface() {
40 const [query, setQuery] = useState("")
41 const [messages, setMessages] = useState<Message[]>([])
42 const [isStreaming, setIsStreaming] = useState(false)
43 const { setMarkers, setTaskType } = useMapStore()
44 const { toast } = useToast()
45 const [hasModelSettings, setHasModelSettings] = useState(false)
46 const [isExtractingInfo, setIsExtractingInfo] = useState(false) // 提取信息状态
47 const [isUpdatingMap, setIsUpdatingMap] = useState(false) // 更新地图状态
48 const messagesEndRef = useRef<HTMLDivElement>(null)
49
50 // 添加AbortController引用
51 const abortControllerRef = useRef<AbortController | null>(null)
52
53 // 检查模型设置
54 useEffect(() => {
55 try {
56 // 检查是否有模型设置
57 const settingsStr = localStorage.getItem("model_settings")
58 if (settingsStr) {
59 setHasModelSettings(true)
60 } else {
61 // 检查旧版 API 密钥
62 const legacyApiKey = localStorage.getItem("openai_api_key")
63 setHasModelSettings(!!legacyApiKey)
64 }
65 } catch (error) {
66 console.error("检查模型设置时出错:", error)
67 }
68 }, [])
69
70 // 滚动到最新消息
71 useEffect(() => {
72 scrollToBottom()
73 }, [messages])
74
75 const scrollToBottom = () => {
76 messagesEndRef.current?.scrollIntoView({ behavior: "smooth" })
77 }
78
79 // 生成唯一ID
80 const generateId = () => {
81 return Date.now().toString(36) + Math.random().toString(36).substr(2)
82 }
83
84 // 调整文本域高度的函数
85 const adjustTextareaHeight = (e: React.ChangeEvent<HTMLTextAreaElement>) => {
86 const target = e.target
87 // 更新查询
88 setQuery(target.value)
89
90 // 如果内容为空,直接重置高度
91 if (!target.value.trim()) {
92 target.style.height = "38px"
93 return
94 }
95
96 // 重置高度,让scrollHeight计算正确

Callers

nothing calls this directly

Calls 3

useToastFunction · 0.90
cnFunction · 0.90
scrollToBottomFunction · 0.85

Tested by

no test coverage detected