| | |
| | | |
| | | const DRAWER_WIDTH = 720; |
| | | const SESSION_WIDTH = 220; |
| | | const DIAGNOSIS_MESSAGE = '请对当前WMS系统进行一次巡检诊断,结合库存、任务、设备站点数据识别异常并给出处理建议。'; |
| | | |
| | | const parseSseChunk = (chunk, onEvent) => { |
| | | const blocks = chunk.split('\n\n'); |
| | |
| | | } |
| | | }; |
| | | |
| | | const handleSend = async () => { |
| | | if (!draft.trim() || !activeSessionId || sending) { |
| | | const streamChat = async ({ userContent, endpoint, sceneCode }) => { |
| | | if (!userContent || !activeSessionId || sending) { |
| | | return; |
| | | } |
| | | const userContent = draft.trim(); |
| | | const sessionId = activeSessionId; |
| | | const modelCode = activeSession?.modelCode || models[0]?.code; |
| | | setDraft(''); |
| | | setError(''); |
| | | setSending(true); |
| | | setMessagesBySession((prev) => { |
| | |
| | | let receivedDelta = false; |
| | | |
| | | try { |
| | | const response = await fetch(`${PREFIX_BASE_URL}ai/chat/stream`, { |
| | | const response = await fetch(`${PREFIX_BASE_URL}${endpoint}`, { |
| | | method: 'POST', |
| | | headers: { |
| | | 'Content-Type': 'application/json', |
| | |
| | | body: JSON.stringify({ |
| | | sessionId, |
| | | message: userContent, |
| | | modelCode |
| | | modelCode, |
| | | sceneCode |
| | | }), |
| | | signal: controller.signal |
| | | }); |
| | |
| | | setSending(false); |
| | | streamControllerRef.current = null; |
| | | } |
| | | }; |
| | | |
| | | const handleSend = async () => { |
| | | if (!draft.trim() || !activeSessionId || sending) { |
| | | return; |
| | | } |
| | | const userContent = draft.trim(); |
| | | setDraft(''); |
| | | await streamChat({ |
| | | userContent, |
| | | endpoint: 'ai/chat/stream', |
| | | sceneCode: 'general_chat' |
| | | }); |
| | | }; |
| | | |
| | | const handleDiagnose = async () => { |
| | | if (!activeSessionId || sending) { |
| | | return; |
| | | } |
| | | await streamChat({ |
| | | userContent: DIAGNOSIS_MESSAGE, |
| | | endpoint: 'ai/diagnose/stream', |
| | | sceneCode: 'system_diagnose' |
| | | }); |
| | | }; |
| | | |
| | | const assistantReplyText = (messageList) => { |
| | |
| | | </MenuItem> |
| | | ))} |
| | | </Select> |
| | | <Button |
| | | variant="outlined" |
| | | size="small" |
| | | disabled={sending || !activeSessionId} |
| | | onClick={handleDiagnose} |
| | | sx={{ borderRadius: 2, whiteSpace: 'nowrap' }} |
| | | > |
| | | 一键诊断 |
| | | </Button> |
| | | </Stack> |
| | | <Divider /> |
| | | <Box |
| | |
| | | 开始新的智能对话 |
| | | </Typography> |
| | | <Typography variant="body2"> |
| | | 可以直接提问仓储业务问题,或切换模型开始新的会话。 |
| | | 可以直接提问仓储业务问题,或点击一键诊断快速巡检当前WMS状态。 |
| | | </Typography> |
| | | <Button variant="outlined" onClick={handleDiagnose} disabled={sending || !activeSessionId}> |
| | | 一键诊断 |
| | | </Button> |
| | | </Stack> |
| | | ) : ( |
| | | <Stack spacing={2}> |
| | |
| | | label={activeSession?.modelCode || '未选择模型'} |
| | | sx={{ bgcolor: 'rgba(25,118,210,0.08)', color: 'primary.main' }} |
| | | /> |
| | | <Button |
| | | variant="text" |
| | | size="small" |
| | | disabled={sending || !activeSessionId} |
| | | onClick={handleDiagnose} |
| | | sx={{ minWidth: 'auto', px: 1 }} |
| | | > |
| | | 一键诊断 |
| | | </Button> |
| | | <Typography variant="caption" color="text.secondary"> |
| | | `Enter` 发送,`Shift + Enter` 换行 |
| | | </Typography> |
| | |
| | | maxRows={6} |
| | | value={draft} |
| | | onChange={(event) => setDraft(event.target.value)} |
| | | placeholder="输入问题,支持多会话和模型切换" |
| | | placeholder="输入问题,支持多会话、多模型和一键诊断" |
| | | onKeyDown={(event) => { |
| | | if (event.key === 'Enter' && !event.shiftKey) { |
| | | event.preventDefault(); |