From 3b660f1698db6e1bc19433f75ebe846c3c109292 Mon Sep 17 00:00:00 2001 From: JzoNg Date: Sun, 17 Mar 2024 15:03:37 +0800 Subject: [PATCH] chat list api --- web/app/components/workflow/panel/record.tsx | 2 +- .../components/workflow/panel/run-history.tsx | 20 +++++++++++++------ web/app/components/workflow/store.ts | 4 ++++ web/service/workflow.ts | 5 +++++ web/types/workflow.ts | 6 ++++++ 5 files changed, 30 insertions(+), 7 deletions(-) diff --git a/web/app/components/workflow/panel/record.tsx b/web/app/components/workflow/panel/record.tsx index 22f1482a4c..abf6e854bd 100644 --- a/web/app/components/workflow/panel/record.tsx +++ b/web/app/components/workflow/panel/record.tsx @@ -15,7 +15,7 @@ const Record = () => { ${isChatMode ? 'w-[320px]' : 'w-[400px]'} `}>
- {`Test Run#${currentSequenceNumber}`} + {`Test ${isChatMode ? 'Chat' : 'Run'}#${currentSequenceNumber}`}
{ isChatMode diff --git a/web/app/components/workflow/panel/run-history.tsx b/web/app/components/workflow/panel/run-history.tsx index 1ea4a7fd8a..dd49411a06 100644 --- a/web/app/components/workflow/panel/run-history.tsx +++ b/web/app/components/workflow/panel/run-history.tsx @@ -4,6 +4,7 @@ import dayjs from 'dayjs' import { useTranslation } from 'react-i18next' import useSWR from 'swr' import { WorkflowRunningStatus } from '../types' +import { useIsChatMode } from '../hooks' import { CheckCircle, XClose } from '@/app/components/base/icons/src/vender/line/general' import { AlertCircle } from '@/app/components/base/icons/src/vender/line/alertsAndFeedback' import { @@ -11,15 +12,21 @@ import { useWorkflowStore, } from '@/app/components/workflow/store' import { useStore as useAppStore } from '@/app/components/app/store' -import { fetchWorkflowRunHistory } from '@/service/workflow' +import { fetcChatRunHistory, fetchWorkflowRunHistory } from '@/service/workflow' import Loading from '@/app/components/base/loading' const RunHistory = () => { const { t } = useTranslation() - const workflowStore = useWorkflowStore() + const isChatMode = useIsChatMode() const appDetail = useAppStore(state => state.appDetail) + const workflowStore = useWorkflowStore() const workflowRunId = useRunHistoryStore(state => state.workflowRunId) - const { data, isLoading } = useSWR(appDetail ? `/apps/${appDetail.id}/workflow-runs` : null, fetchWorkflowRunHistory) + const { data: runList, isLoading: runListLoading } = useSWR((appDetail && !isChatMode) ? `/apps/${appDetail.id}/workflow-runs` : null, fetchWorkflowRunHistory) + + const { data: chatList, isLoading: chatListLoading } = useSWR((appDetail && isChatMode) ? `/apps/${appDetail.id}/advanced-chat/workflow-runs` : null, fetcChatRunHistory) + + const data = isChatMode ? chatList : runList + const isLoading = isChatMode ? chatListLoading : runListLoading if (!appDetail) return null @@ -54,16 +61,17 @@ const RunHistory = () => { onClick={() => workflowStore.setState({ currentSequenceNumber: item.sequence_number, workflowRunId: item.id, + currentConversationID: item.conversation_id, runningStatus: item.status as WorkflowRunningStatus, })} > { - appDetail?.mode === 'workflow' && item.status === WorkflowRunningStatus.Failed && ( + !isChatMode && item.status === WorkflowRunningStatus.Failed && ( ) } { - appDetail?.mode === 'workflow' && item.status === WorkflowRunningStatus.Succeeded && ( + !isChatMode && item.status === WorkflowRunningStatus.Succeeded && ( ) } @@ -74,7 +82,7 @@ const RunHistory = () => { item.id === workflowRunId && 'text-primary-600', )} > - Test Run#{item.sequence_number} + {`Test ${isChatMode ? 'Chat' : 'Run'} Run#${item.sequence_number}`}
{item.created_by_account.name} ยท {dayjs((item.finished_at || item.created_at) * 1000).fromNow()} diff --git a/web/app/components/workflow/store.ts b/web/app/components/workflow/store.ts index 224d5343f2..c410bccd7d 100644 --- a/web/app/components/workflow/store.ts +++ b/web/app/components/workflow/store.ts @@ -24,6 +24,7 @@ type State = { taskId: string currentSequenceNumber: number workflowRunId: string + currentConversationID: string showRunHistory: boolean showFeaturesPanel: boolean helpLineHorizontal?: HelpLineHorizontalPosition @@ -49,6 +50,7 @@ type Action = { setTaskId: (taskId: string) => void setCurrentSequenceNumber: (currentSequenceNumber: number) => void setWorkflowRunId: (workflowRunId: string) => void + setCurrentConversationID: (currentConversationID: string) => void setShowRunHistory: (showRunHistory: boolean) => void setShowFeaturesPanel: (showFeaturesPanel: boolean) => void setHelpLineHorizontal: (helpLineHorizontal?: HelpLineHorizontalPosition) => void @@ -74,6 +76,8 @@ export const createWorkflowStore = () => { setCurrentSequenceNumber: currentSequenceNumber => set(() => ({ currentSequenceNumber })), workflowRunId: '', setWorkflowRunId: workflowRunId => set(() => ({ workflowRunId })), + currentConversationID: '', + setCurrentConversationID: currentConversationID => set(() => ({ currentConversationID })), showRunHistory: false, setShowRunHistory: showRunHistory => set(() => ({ showRunHistory })), showFeaturesPanel: false, diff --git a/web/service/workflow.ts b/web/service/workflow.ts index 503098ae33..48c915cf7d 100644 --- a/web/service/workflow.ts +++ b/web/service/workflow.ts @@ -2,6 +2,7 @@ import type { Fetcher } from 'swr' import { get, post } from './base' import type { CommonResponse } from '@/models/common' import type { + ChatRunHistoryResponse, FetchWorkflowDraftResponse, NodesDefaultConfigsResponse, WorkflowRunHistoryResponse, @@ -23,6 +24,10 @@ export const fetchWorkflowRunHistory: Fetcher(url) } +export const fetcChatRunHistory: Fetcher = (url) => { + return get(url) +} + export const singleNodeRun = (appId: string, nodeId: string, params: object) => { return post(`apps/${appId}/workflows/draft/nodes/${nodeId}/run`, { body: params }) } diff --git a/web/types/workflow.ts b/web/types/workflow.ts index bac3a7d2de..d5af8fd1ee 100644 --- a/web/types/workflow.ts +++ b/web/types/workflow.ts @@ -137,6 +137,8 @@ export type WorkflowRunHistory = { id: string sequence_number: number version: string + conversation_id?: string + message_id?: string graph: { nodes: Node[] edges: Edge[] @@ -161,6 +163,10 @@ export type WorkflowRunHistoryResponse = { data: WorkflowRunHistory[] } +export type ChatRunHistoryResponse = { + data: WorkflowRunHistory[] +} + export type NodesDefaultConfigsResponse = { type: string config: any