Open-source, secure environment with real-world tools for enterprise-grade agents.
Python agentaiai-agentai-agentscode-interpretercopilotdevelopmentdevtoolsgptgpt-4javascriptllmnextjsopenaipythonreactsoftwaretypescript
Fix upload by drag and dropping file
Tomas Valenta6df858a0a509
diff --git a/components/AgentLogFilesList.tsx b/components/AgentLogFilesList.tsxindex 3dbc3d82a..cc5cc83eb 100644--- a/components/AgentLogFilesList.tsx+++ b/components/AgentLogFilesList.tsx@@ -28,6 +28,7 @@ function AgentLogFilesList({const router = useRouter()const [selectedLogFileID, setSelectedLogFileID] = useState(initialSelectedLogFileID || '')const fileInput = useRef<any>(null)+ const [dragActive, setDragActive] = useState(false)const uploadFile = useUploadLog(defaultProjectID)@@ -36,10 +37,10 @@ function AgentLogFilesList({fileInput.current.click()}- async function handleFileChange(event: any) {- const file: BufferFile = event.target.files[0]+ async function handleUpload(file: BufferFile) {const text = await file.text()+ // console.log('text >>>>>>>>>', text)const log = await uploadFile({content: text,filename: file.name,@@ -54,6 +55,30 @@ function AgentLogFilesList({router.reload()}+ async function handleFileChange(event: any) {+ const file: BufferFile = event.target.files[0]+ await handleUpload(file)+ }++ const handleDrag = function (e: any) {+ e.preventDefault()+ e.stopPropagation()+ if (e.type === 'dragenter' || e.type === 'dragover') {+ setDragActive(true)+ } else if (e.type === 'dragleave') {+ setDragActive(false)+ }+ }++ async function handleDrop(e: any) {+ e.preventDefault()+ e.stopPropagation()+ setDragActive(false)+ if (e.dataTransfer.files && e.dataTransfer.files[0]) {+ await handleUpload(e.dataTransfer.files[0])+ }+ }+function toggleSelectedLogFileID(logFileID: string) {if (selectedLogFileID === logFileID) {setSelectedLogFileID('')@@ -66,14 +91,14 @@ function AgentLogFilesList({return (<main className="overflow-hidden flex flex-col max-h-full">+ <input+ type="file"+ style={{ display: 'none' }}+ ref={fileInput}+ onChange={handleFileChange}+ /><header className="flex items-center justify-between p-4 sm:p-6 lg:px-8"><h1 className="text-2xl font-semibold text-white">Log Files</h1>- <input- type="file"- style={{ display: 'none' }}- ref={fileInput}- onChange={handleFileChange}- /><buttonclassName="p-2 rounded-md bg-[#6366F1] flex items-center space-x-2"onClick={handleClick}@@ -84,9 +109,16 @@ function AgentLogFilesList({</header>{logFiles.length === 0 && (- <div className="flex flex-col space-y-4 p-4 sm:p-6 lg:px-8">+ <div+ className="flex flex-col space-y-4 p-4 sm:p-6 lg:px-8"+ onDrop={handleDrop}+ onDragEnter={handleDrag}+ onDragLeave={handleDrag}+ onDragOver={handleDrag}+ ><buttontype="button"+ onClick={handleClick}className="w-full flex flex-col items-center justify-center rounded-lg border-2 border-dashed border-gray-500 p-12 text-center hover:border-gray-400 transition-all focus:outline-none focus:ring-2 focus:ring-indigo-500 focus:ring-offset-2"><Upload size={48} className="text-gray-500" strokeWidth={1.5} />diff --git a/pages/index.tsx b/pages/index.tsxindex 8c3aa8355..eaffd3142 100644--- a/pages/index.tsx+++ b/pages/index.tsx@@ -5,8 +5,20 @@ import { deployments, prisma, projects } from 'db/prisma'import { serverCreds } from 'db/credentials'import DashboardHome from 'components/DashboardHome'import { LogFile, RawFileLog } from 'utils/agentLogs'+import { nanoid } from 'nanoid'export const getServerSideProps: GetServerSideProps<Props> = async (ctx) => {+ // Select the 'deployed' view by default.+ const view = ctx.query['view'] as string+ let redirect: Redirect | undefined+ if (!view) {+ redirect = {+ // destination: '/?view=deployed',+ destination: '/?view=logs',+ permanent: false,+ }+ }+const supabase = createServerSupabaseClient(ctx, serverCreds)const {data: { session },@@ -54,21 +66,9 @@ export const getServerSideProps: GetServerSideProps<Props> = async (ctx) => {}}- // Select the 'deployed' view by default.- const view = ctx.query['view'] as string- let redirect: Redirect | undefined- if (!view) {- redirect = {- // destination: '/?view=deployed',- destination: '/?view=logs',- permanent: false,- }- }-- const hasDefaultTeam = user?.users_teams.find(t => t.teams.is_default)- if (!hasDefaultTeam) {- // If user is without default team create default team.- const team = await prisma.teams.create({+ const defaultTeam =+ user?.users_teams.flatMap(u => u.teams)?.find(t => t.is_default) ||+ await prisma.teams.create({include: {projects: {include: {@@ -82,6 +82,7 @@ export const getServerSideProps: GetServerSideProps<Props> = async (ctx) => {projects: {create: {name: 'Default Project',+ is_default: true,},},users_teams: {@@ -96,39 +97,30 @@ export const getServerSideProps: GetServerSideProps<Props> = async (ctx) => {},})- return {- props: {- projects: team.projects- .map<projects & { logs: LogFile[], deployments: deployments[] }>(p => {- return {- ...p,- // Don't send any deployments to the client.- deployments: [],- logs: p- .logs- .filter(l => l.data !== null && l.data.length > 0)- .map<LogFile>(l => {- const log = l.data[0] as unknown as RawFileLog- return {- id: l.id,- name: log.filename,- }- })- }- }),- defaultProjectID: team.projects[0].id,+ const defaultProject =+ defaultTeam.projects.find(p => p.is_default) ||+ await prisma.projects.create({+ data: {+ id: nanoid(),+ is_default: true,+ name: 'Default Project',+ teams: {+ connect: {+ id: defaultTeam.id,+ },+ },},- }- }+ include: {+ logs: true,+ },+ })- // Show projects from all teams.- const projects = user- .users_teams- .flatMap(t => t.teams.projects)return {props: {- projects: projects+ defaultProjectID: defaultProject.id,+ projects: defaultTeam+ .projects.map<projects & { logs: LogFile[], deployments: deployments[] }>(p => {return {...p,@@ -145,8 +137,7 @@ export const getServerSideProps: GetServerSideProps<Props> = async (ctx) => {}})}- }),- defaultProjectID: projects[0].id,+ })},redirect,}diff --git a/prisma/schema.prisma b/prisma/schema.prismaindex 44f80267a..db7dab674 100644--- a/prisma/schema.prisma+++ b/prisma/schema.prisma@@ -279,6 +279,7 @@ model projects {team_id String @db.Uuidname String @default("")development_logs Json[]+ is_default Boolean @default(false)deployments deployments[]logs logs[]teams teams @relation(fields: [team_id], references: [id], onDelete: NoAction, onUpdate: NoAction)