Open-source, secure environment with real-world tools for enterprise-grade agents.
Python agentaiai-agentai-agentscode-interpretercopilotdevelopmentdevtoolsgptgpt-4javascriptllmnextjsopenaipythonreactsoftwaretypescript
Fix deployments logs list handling [WIP]
Tomas Valentae490092214cd
diff --git a/components/AgentDeploymentLogList.tsx b/components/AgentDeploymentLogList.tsxindex 4e9ee49fe..dbc374010 100644--- a/components/AgentDeploymentLogList.tsx+++ b/components/AgentDeploymentLogList.tsx@@ -27,19 +27,6 @@ function AgentDeploymentLogList({if (a.created_at > b.created_at) return -1if (a.created_at < b.created_at) return 1return 0- })- // Sort the log_files inside logUploads alphabtetical by relativePath- .map(d => {- const sortedLogs = d.log_files.sort((a, b) => {- if (a.relativePath > b.relativePath) return 1- if (a.relativePath < b.relativePath) return -1- return 0- })-- return {- ...d,- log_files: sortedLogs,- }}), [deployments])function toggleDeployments(logUploadID: string) {@@ -57,7 +44,7 @@ function AgentDeploymentLogList({}return (- <main className="overflow-hidden flex flex-col max-h-full flex-1">+ <main className="overflow-hidden flex flex-col max-h-full flex-1 border-white/5 border rounded-md"><header className="flex items-center justify-between p-4 sm:p-6 lg:px-8 min-h-[88px]"><h1 className="text-2xl font-semibold text-white">Agent Deployments</h1></header>diff --git a/components/AgentLogFilesList.tsx b/components/AgentLogFilesList.tsxindex 11a7b18e3..631ca9b47 100644--- a/components/AgentLogFilesList.tsx+++ b/components/AgentLogFilesList.tsx@@ -161,7 +161,7 @@ function AgentLogFilesList({}return (- <main className="rounded-md border-white/5 overflow-hidden flex flex-col max-h-full flex-1">+ <main className="rounded-md border-white/5 border overflow-hidden flex flex-col max-h-full flex-1"><inputtype="file"style={{ display: 'none' }}diff --git a/components/AgentRunLogContent.tsx b/components/AgentRunLogContent.tsxnew file mode 100644index 000000000..158b543fb--- /dev/null+++ b/components/AgentRunLogContent.tsx@@ -0,0 +1,65 @@+import {+ useCallback,+ useState,+} from 'react'+import Splitter from '@devbookhq/splitter'+import clsx from 'clsx'++import {+ SystemPromptLog,+ UserPromptLog,+ AssistantPromptLog,+ LiteDeploymentLog,+} from 'utils/agentLogs'+import AgentPrompLogDetail from 'components/AgentPromptLogDetail'+import AgentPromptLogsList from 'components/AgentPromptLogsList'+import { useLocalStorage } from 'hooks/useLocalStorage'++export interface Props {+ log: LiteDeploymentLog+}++function AgentRunLogContent({+ log,+}: Props) {+ const [selectedLog, setSelectedLog] = useState<SystemPromptLog | UserPromptLog | AssistantPromptLog>()+ const [splitterSizes, setSplitterSizes] = useLocalStorage('log-content-splitter', [40, 60])++ const setSizes = useCallback((pairIdx: number, sizes: number[]) => {+ setSplitterSizes(sizes)+ }, [setSplitterSizes])++ if (!log) return null++ return (+ <main className="overflow-hidden flex flex-col max-h-full flex-1">+ <header className="flex items-center justify-between p-4 sm:p-6 lg:px-8 min-h-[88px]">+ <h1 className="text-2xl font-semibold text-white">Agent run logs</h1>+ </header>+ <div className="flex-1 flex space-x-2 items-start justify-start overflow-hidden">+ <Splitter+ gutterClassName={clsx(+ 'bg-gray-900 hover:bg-[#6366F1] transition-all delay-75 duration-[400ms] px-0.5 rounded-sm group',+ )}+ draggerClassName={clsx(+ 'bg-gray-700 group-hover:bg-[#6366F1] transition-all delay-75 duration-[400ms] w-0.5 h-full',+ )}+ classes={['pr-2 overflow-auto', 'bg-gray-900 pl-2']}+ initialSizes={splitterSizes}+ onResizeFinished={setSizes}+ minWidths={[120, 120]}+ >+ <AgentPromptLogsList+ logs={log.content as any}+ onSelected={setSelectedLog}+ />+ <AgentPrompLogDetail+ log={selectedLog}+ />+ </Splitter>+ </div>+ </main>+ )+}++export default AgentRunLogContentdiff --git a/components/DashboardHome.tsx b/components/DashboardHome.tsxindex df47a38b1..3c4c8757b 100644--- a/components/DashboardHome.tsx+++ b/components/DashboardHome.tsx@@ -19,7 +19,7 @@ function DashboardHome({const router = useRouter()const showView = router.query['view'] === 'logs' ? 'logs' : view- const projectsWithDeployments = useMemo(() => projects+ const deployments = useMemo(() => projects.filter(p => {if (p.deployments.length !== 1) return false@@ -28,16 +28,14 @@ function DashboardHome({if (!auth) return falsereturn true})- .map(p => ({- project: p,- deployment: p.deployments[0],- })), [projects])+ .flatMap(p => p.deployments)+ , [projects])return (<>{showView === 'deployments' &&<AgentDeploymentLogList- deployments={projectsWithDeployments.flatMap(p => p.deployment)}+ deployments={deployments}/>}{showView === 'logs' &&diff --git a/pages/index.tsx b/pages/index.tsxindex c3348eba8..f9394d197 100644--- a/pages/index.tsx+++ b/pages/index.tsx@@ -109,12 +109,18 @@ export const getServerSideProps: GetServerSideProps<Props> = async (ctx) => {},deployments: {include: {+ log_files: {+ select: {+ id: true,+ created_at: true,+ log_upload_id: true,+ },+ },projects: {select: {name: true,},},- log_files: true,},},},@@ -153,12 +159,18 @@ export const getServerSideProps: GetServerSideProps<Props> = async (ctx) => {},deployments: {include: {+ log_files: {+ select: {+ id: true,+ created_at: true,+ log_upload_id: true,+ },+ },projects: {select: {name: true,},},- log_files: true,},},},@@ -176,12 +188,18 @@ export const getServerSideProps: GetServerSideProps<Props> = async (ctx) => {},deployments: {include: {+ log_files: {+ select: {+ id: true,+ created_at: true,+ log_upload_id: true,+ },+ },projects: {select: {name: true,},},- log_files: true,},},},@@ -231,12 +249,18 @@ export const getServerSideProps: GetServerSideProps<Props> = async (ctx) => {},deployments: {include: {+ log_files: {+ select: {+ id: true,+ created_at: true,+ log_upload_id: true,+ },+ },projects: {select: {name: true,},},- log_files: true,},},},diff --git a/pages/deployed/[projectID]/run/[runID].tsx b/pages/logs/[logID].tsxsimilarity index 57%rename from pages/deployed/[projectID]/run/[runID].tsxrename to pages/logs/[logID].tsxindex 34f1268f6..2c44119a1 100644--- a/pages/deployed/[projectID]/run/[runID].tsx+++ b/pages/logs/[logID].tsx@@ -2,19 +2,18 @@ import type { GetServerSideProps } from 'next'import { createServerSupabaseClient } from '@supabase/auth-helpers-nextjs'import type { ParsedUrlQuery } from 'querystring'-import { prisma, projects } from 'db/prisma'+import { prisma } from 'db/prisma'import { serverCreds } from 'db/credentials'-import AgentRun from 'components/AgentRun'+import { LiteDeploymentLog } from 'utils/agentLogs'+import AgentRunLogContent from 'components/AgentRunLogContent'interface PathProps extends ParsedUrlQuery {- runID: string- projectID: string+ logID: string}export const getServerSideProps: GetServerSideProps<Props, PathProps> = async (ctx) => {- const projectID = ctx.params?.projectIDconst logID = ctx.params?.logID- if (!projectID) {+ if (!logID) {return {redirect: {destination: '/',@@ -37,22 +36,25 @@ export const getServerSideProps: GetServerSideProps<Props, PathProps> = async (c}}- const user = await prisma.auth_users.findUnique({+ const log = await prisma.log_files.findFirst({where: {- id: session.user.id,+ id: logID,+ projects: {+ teams: {+ users_teams: {+ some: {+ user_id: session.user.id,+ },+ },+ },+ },},- select: {- users_teams: {- select: {- teams: {- include: {- projects: {- where: {- id: {- equals: projectID,- },- },- },+ include: {+ deployments: {+ include: {+ projects: {+ select: {+ name: true,},},},@@ -60,12 +62,8 @@ export const getServerSideProps: GetServerSideProps<Props, PathProps> = async (c},})- const project = user- ?.users_teams- .flatMap(t => t.teams.projects)- .find(p => p.id === projectID)- if (!project) {+ if (!log || !log.deployments) {return {notFound: true,}@@ -73,23 +71,24 @@ export const getServerSideProps: GetServerSideProps<Props, PathProps> = async (creturn {props: {- project,- logID,+ log: {+ ...log,+ content: JSON.parse(log.content),+ } as any,}}}interface Props {- project: projects- runID: string+ log: LiteDeploymentLog}function ProjectPage({- project,- runID,+ log,}: Props) {return (- <AgentRun+ <AgentRunLogContent+ log={log}/>)}diff --git a/utils/agentLogs.ts b/utils/agentLogs.tsindex 437fe9926..3af0a8b7b 100644--- a/utils/agentLogs.ts+++ b/utils/agentLogs.ts@@ -1,11 +1,12 @@import { deployments, log_files, log_uploads } from 'db/prisma'export interface LiteDeploymentLog extends Omit<log_files, 'content'> {- content: AgentPromptLogs | AgentNextActionLog | string+ content: any+ deployments: LiteDeployment}-export interface LiteDeployment extends Omit<deployments, 'log_files'> {- log_files: LiteDeploymentLog[]+export interface LiteDeployment extends deployments {+ log_files: Pick<log_files, 'id' | 'created_at' | 'log_upload_id'>[]projects: {name: string}