Commit 04ad1eef authored by JzoNg's avatar JzoNg

workflow logs

parent 2b475b79
import React from 'react' import React from 'react'
import Main from '@/app/components/app/log-annotation' import Main from '@/app/components/app/log-annotation'
import { PageType } from '@/app/components/app/configuration/toolbox/annotation/type' import { PageType } from '@/app/components/app/configuration/toolbox/annotation/type'
import type { AppMode } from '@/types/app'
export type IProps = { export type IProps = {
params: { appId: string } params: { appId: string }
appMode: AppMode
} }
const Logs = async ({ const Logs = async ({
params: { appId }, params: { appId },
appMode,
}: IProps) => { }: IProps) => {
return ( return (
<Main appMode={appMode} pageType={PageType.log} appId={appId} /> <Main pageType={PageType.log} appId={appId} />
) )
} }
......
...@@ -7,32 +7,40 @@ import { useRouter } from 'next/navigation' ...@@ -7,32 +7,40 @@ import { useRouter } from 'next/navigation'
import Log from '@/app/components/app/log' import Log from '@/app/components/app/log'
import WorkflowLog from '@/app/components/app/workflow-log' import WorkflowLog from '@/app/components/app/workflow-log'
import Annotation from '@/app/components/app/annotation' import Annotation from '@/app/components/app/annotation'
import Loading from '@/app/components/base/loading'
import { PageType } from '@/app/components/app/configuration/toolbox/annotation/type' import { PageType } from '@/app/components/app/configuration/toolbox/annotation/type'
import TabSlider from '@/app/components/base/tab-slider-plain' import TabSlider from '@/app/components/base/tab-slider-plain'
import type { AppMode } from '@/types/app' import { useStore as useAppStore } from '@/app/components/app/store'
type Props = { type Props = {
pageType: PageType pageType: PageType
appId: string appId: string
appMode: AppMode
} }
const LogAnnotation: FC<Props> = ({ const LogAnnotation: FC<Props> = ({
pageType, pageType,
appId, appId,
appMode,
}) => { }) => {
const { t } = useTranslation() const { t } = useTranslation()
const router = useRouter() const router = useRouter()
const { appDetail } = useAppStore()
const options = [ const options = [
{ value: PageType.log, text: t('appLog.title') }, { value: PageType.log, text: t('appLog.title') },
{ value: PageType.annotation, text: t('appAnnotation.title') }, { value: PageType.annotation, text: t('appAnnotation.title') },
] ]
if (!appDetail) {
return (
<div className='flex h-full items-center justify-center bg-white'>
<Loading />
</div>
)
}
return ( return (
<div className='pt-4 px-6 h-full flex flex-col'> <div className='pt-4 px-6 h-full flex flex-col'>
{appMode !== 'workflow' && ( {appDetail.mode !== 'workflow' && (
<TabSlider <TabSlider
className='shrink-0' className='shrink-0'
value={pageType} value={pageType}
...@@ -42,10 +50,10 @@ const LogAnnotation: FC<Props> = ({ ...@@ -42,10 +50,10 @@ const LogAnnotation: FC<Props> = ({
options={options} options={options}
/> />
)} )}
<div className={cn('grow', appMode !== 'workflow' && 'mt-3')}> <div className={cn('grow', appDetail.mode !== 'workflow' && 'mt-3')}>
{pageType === PageType.log && appMode !== 'workflow' && (<Log appId={appId} />)} {pageType === PageType.log && appDetail.mode !== 'workflow' && (<Log appId={appId} />)}
{pageType === PageType.annotation && (<Annotation appId={appId} />)} {pageType === PageType.annotation && (<Annotation appId={appId} />)}
{pageType === PageType.log && appMode === 'workflow' && (<WorkflowLog appId={appId} />)} {pageType === PageType.log && appDetail.mode === 'workflow' && (<WorkflowLog appDetail={appDetail} />)}
</div> </div>
</div> </div>
) )
......
...@@ -6,7 +6,7 @@ import Run from '@/app/components/workflow/run' ...@@ -6,7 +6,7 @@ import Run from '@/app/components/workflow/run'
import { XClose } from '@/app/components/base/icons/src/vender/line/general' import { XClose } from '@/app/components/base/icons/src/vender/line/general'
type ILogDetail = { type ILogDetail = {
appDetail?: App appDetail: App
onClose: () => void onClose: () => void
} }
...@@ -19,7 +19,7 @@ const DetailPanel: FC<ILogDetail> = ({ appDetail, onClose }) => { ...@@ -19,7 +19,7 @@ const DetailPanel: FC<ILogDetail> = ({ appDetail, onClose }) => {
<XClose className='w-4 h-4 text-gray-500' /> <XClose className='w-4 h-4 text-gray-500' />
</span> </span>
<h1 className='shrink-0 px-4 py-1 text-md font-semibold text-gray-900'>{t('appLog.runDetail.workflowTitle')}</h1> <h1 className='shrink-0 px-4 py-1 text-md font-semibold text-gray-900'>{t('appLog.runDetail.workflowTitle')}</h1>
<Run activeTab='TRACING' appId={appDetail?.id || ''}></Run> <Run activeTab='TRACING' appId={appDetail.id}></Run>
</div> </div>
) )
} }
......
...@@ -20,7 +20,7 @@ const Filter: FC<IFilterProps> = ({ queryParams, setQueryParams }: IFilterProps) ...@@ -20,7 +20,7 @@ const Filter: FC<IFilterProps> = ({ queryParams, setQueryParams }: IFilterProps)
<div className="relative rounded-md"> <div className="relative rounded-md">
<SimpleSelect <SimpleSelect
defaultValue={'all'} defaultValue={'all'}
className='!w-[100px]' className='!min-w-[100px]'
onSelect={ onSelect={
(item) => { (item) => {
setQueryParams({ ...queryParams, status: item.value as string }) setQueryParams({ ...queryParams, status: item.value as string })
......
...@@ -13,13 +13,12 @@ import DetailPanel from './detail' ...@@ -13,13 +13,12 @@ import DetailPanel from './detail'
import s from './style.module.css' import s from './style.module.css'
import Loading from '@/app/components/base/loading' import Loading from '@/app/components/base/loading'
import { fetchWorkflowLogs } from '@/service/log' import { fetchWorkflowLogs } from '@/service/log'
import { fetchAppDetail } from '@/service/apps'
import { APP_PAGE_LIMIT } from '@/config' import { APP_PAGE_LIMIT } from '@/config'
import type { AppMode } from '@/types/app' import type { App, AppMode } from '@/types/app'
import Drawer from '@/app/components/base/drawer' import Drawer from '@/app/components/base/drawer'
export type ILogsProps = { export type ILogsProps = {
appId: string appDetail: App
} }
export type QueryParam = { export type QueryParam = {
...@@ -32,7 +31,6 @@ const ThreeDotsIcon = ({ className }: SVGProps<SVGElement>) => { ...@@ -32,7 +31,6 @@ const ThreeDotsIcon = ({ className }: SVGProps<SVGElement>) => {
<path d="M5 6.5V5M8.93934 7.56066L10 6.5M10.0103 11.5H11.5103" stroke="#374151" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round" /> <path d="M5 6.5V5M8.93934 7.56066L10 6.5M10.0103 11.5H11.5103" stroke="#374151" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round" />
</svg> </svg>
} }
const EmptyElement: FC<{ appUrl: string }> = ({ appUrl }) => { const EmptyElement: FC<{ appUrl: string }> = ({ appUrl }) => {
const { t } = useTranslation() const { t } = useTranslation()
const pathname = usePathname() const pathname = usePathname()
...@@ -51,7 +49,8 @@ const EmptyElement: FC<{ appUrl: string }> = ({ appUrl }) => { ...@@ -51,7 +49,8 @@ const EmptyElement: FC<{ appUrl: string }> = ({ appUrl }) => {
</div> </div>
} }
const Logs: FC<ILogsProps> = ({ appId }) => { const Logs: FC<ILogsProps> = ({ appDetail }) => {
// ###TODO###
const [showDrawer, setShowDrawer] = useState<boolean>(true) const [showDrawer, setShowDrawer] = useState<boolean>(true)
const onCloseDrawer = () => { const onCloseDrawer = () => {
setShowDrawer(false) setShowDrawer(false)
...@@ -64,22 +63,18 @@ const Logs: FC<ILogsProps> = ({ appId }) => { ...@@ -64,22 +63,18 @@ const Logs: FC<ILogsProps> = ({ appId }) => {
const query = { const query = {
page: currPage + 1, page: currPage + 1,
limit: APP_PAGE_LIMIT, limit: APP_PAGE_LIMIT,
...queryParams, ...(queryParams.status !== 'all' ? { status: queryParams.status } : {}),
...(queryParams.keyword ? { keyword: queryParams.keyword } : {}),
} }
// Get the app type first const getWebAppType = (appType: AppMode) => {
const { data: appDetail } = useSWR({ url: '/apps', id: appId }, fetchAppDetail)
const getWebAppType = (appType?: AppMode) => {
if (!appType)
return ''
if (appType === 'completion' || appType === 'workflow') if (appType === 'completion' || appType === 'workflow')
return 'completion' return 'completion'
return 'chat' return 'chat'
} }
const { data: workflowLogs, mutate } = useSWR({ const { data: workflowLogs, mutate } = useSWR({
url: `/apps/${appId}/workflow-app-logs`, url: `/apps/${appDetail.id}/workflow-app-logs`,
params: query, params: query,
}, fetchWorkflowLogs) }, fetchWorkflowLogs)
const total = workflowLogs?.total const total = workflowLogs?.total
...@@ -98,7 +93,7 @@ const Logs: FC<ILogsProps> = ({ appId }) => { ...@@ -98,7 +93,7 @@ const Logs: FC<ILogsProps> = ({ appId }) => {
? <Loading type='app' /> ? <Loading type='app' />
: total > 0 : total > 0
? <List logs={workflowLogs} appDetail={appDetail} onRefresh={mutate} /> ? <List logs={workflowLogs} appDetail={appDetail} onRefresh={mutate} />
: <EmptyElement appUrl={`${appDetail?.site.app_base_url}/${getWebAppType(appDetail?.mode)}/${appDetail?.site.access_token}`} /> : <EmptyElement appUrl={`${appDetail.site.app_base_url}/${getWebAppType(appDetail.mode)}/${appDetail.site.access_token}`} />
} }
{/* Show Pagination only if the total is more than the limit */} {/* Show Pagination only if the total is more than the limit */}
{(total && total > APP_PAGE_LIMIT) {(total && total > APP_PAGE_LIMIT)
......
...@@ -50,7 +50,7 @@ const WorkflowAppLogList: FC<ILogs> = ({ logs, appDetail, onRefresh }) => { ...@@ -50,7 +50,7 @@ const WorkflowAppLogList: FC<ILogs> = ({ logs, appDetail, onRefresh }) => {
if (status === 'stopped') { if (status === 'stopped') {
return ( return (
<div className='inline-flex items-center gap-1'> <div className='inline-flex items-center gap-1'>
<Indicator color={'gray'} /> <Indicator color={'yellow'} />
<span>Stop</span> <span>Stop</span>
</div> </div>
) )
...@@ -71,7 +71,7 @@ const WorkflowAppLogList: FC<ILogs> = ({ logs, appDetail, onRefresh }) => { ...@@ -71,7 +71,7 @@ const WorkflowAppLogList: FC<ILogs> = ({ logs, appDetail, onRefresh }) => {
setCurrentLog(undefined) setCurrentLog(undefined)
} }
if (!logs) if (!logs || !appDetail)
return <Loading /> return <Loading />
return ( return (
...@@ -104,7 +104,6 @@ const WorkflowAppLogList: FC<ILogs> = ({ logs, appDetail, onRefresh }) => { ...@@ -104,7 +104,6 @@ const WorkflowAppLogList: FC<ILogs> = ({ logs, appDetail, onRefresh }) => {
<td> <td>
<div className={cn( <div className={cn(
log.workflow_run.elapsed_time === 0 && 'text-gray-400', log.workflow_run.elapsed_time === 0 && 'text-gray-400',
log.workflow_run.elapsed_time > 10 && 'text-orange-400',
)}>{`${log.workflow_run.elapsed_time}s`}</div> )}>{`${log.workflow_run.elapsed_time}s`}</div>
</td> </td>
<td>{log.workflow_run.total_tokens}</td> <td>{log.workflow_run.total_tokens}</td>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment