Skip to content

armgit / E2B

Public Imported from GitHub
0

Open-source, secure environment with real-world tools for enterprise-grade agents.

Fix merge problems

Tomas Valenta9648d5be434f
diff --git a/components/AgentLogFilesList.tsx b/components/AgentLogFilesList.tsx
index e39e7a02b..067546dd7 100644
--- a/components/AgentLogFilesList.tsx
+++ b/components/AgentLogFilesList.tsx
@@ -9,18 +9,18 @@ import {
import clsx from 'clsx'
import { useRouter } from 'next/router'
-import { Log, RawFileLog } from 'utils/agentLogs'
import { useUploadLogs } from 'hooks/useUploadLogs'
import { useDeleteLogs } from 'hooks/useRemoveLogs'
+import { LiteLogUpload } from 'pages'
export interface Props {
- logs: Log[]
+ logUploads: LiteLogUpload[]
initialSelectedLogFileID?: string
defaultProjectID: string
}
function AgentLogFilesList({
- logs,
+ logUploads,
initialSelectedLogFileID,
defaultProjectID,
}: Props) {
@@ -37,12 +37,14 @@ function AgentLogFilesList({
}
async function handleUpload(files: FileList) {
- const logFiles: RawFileLog[] = []
+ const logFiles: [] = []
for (let i = 0; i < files.length; i++) {
const file = files[i]
const content = await file.text()
+
+
logFiles.push({
filename: file.name,
content,
@@ -121,7 +123,7 @@ function AgentLogFilesList({
</button>
</header>
- {logs.length === 0 && (
+ {logUploads.length === 0 && (
<div
className="flex flex-col space-y-4 p-4 sm:p-6 lg:px-8"
onDrop={handleDrop}
@@ -140,11 +142,11 @@ function AgentLogFilesList({
</div>
)}
- {logs.length > 0 && (
+ {logUploads.length > 0 && (
<div className="flex flex-col space-y-4 p-4 sm:p-6 lg:px-8 overflow-auto">
- {logs.map((log, i) => (
+ {logUploads.map((logUpload, i) => (
<div
- key={log.id}
+ key={logUpload.id}
>
<div
className={clsx(
@@ -155,16 +157,16 @@ function AgentLogFilesList({
className={clsx(
'text-sm',
'font-semibold',
- selectedLogFileID === log.id && 'font-semibold',
+ selectedLogFileID === logUpload.id && 'font-semibold',
)}
>
- {log.id}
+ {logUpload.id}
</span>
<div
className="cursor-pointer"
onClick={async () => {
try {
- const res = await deleteLogs(log.id)
+ const res = await deleteLogs(logUpload.id)
console.log(res)
router.reload()
} catch (err) {
@@ -175,15 +177,15 @@ function AgentLogFilesList({
Delete
</div>
</div>
- {log.files.map((f, i) =>
+ {logUpload.log_files.map((f, i) =>
<div
key={i}
className={clsx(
'flex items-center space-x-2 p-2 cursor-pointer hover:bg-gray-700 transition-all rounded-md',
- selectedLogFileID === log.id && 'bg-gray-700',
- selectedLogFileID !== log.id && 'bg-gray-800',
+ selectedLogFileID === f.id && 'bg-gray-700',
+ selectedLogFileID !== f.id && 'bg-gray-800',
)}
- onClick={() => toggleSelectedLogFileID(log.id, f.name)}
+ onClick={() => toggleSelectedLogFileID(f.id, f.filename)}
>
<File size={14} className="text-gray-500" />
<span
@@ -191,10 +193,10 @@ function AgentLogFilesList({
'text-sm',
'cursor-pointer',
'font-semibold',
- selectedLogFileID === log.id && 'font-semibold',
+ selectedLogFileID === f.id && 'font-semibold',
)}
>
- {f.name}
+ {f.filename}
</span>
</div>
)
diff --git a/components/DashboardHome.tsx b/components/DashboardHome.tsx
index acbd952a9..36fc13dcc 100644
--- a/components/DashboardHome.tsx
+++ b/components/DashboardHome.tsx
@@ -5,10 +5,11 @@ import { useSupabaseClient } from '@supabase/auth-helpers-react'
import AgentList from 'components/AgentList'
import AgentRunsList from 'components/AgentRunsList'
import AgentLogFilesList from 'components/AgentLogFilesList'
-import { ProjectWithLogFiles } from 'pages'
+import { LiteLogUpload } from 'pages'
+import { deployments, projects } from 'db/prisma'
export interface Props {
- projects: ProjectWithLogFiles[]
+ projects: (projects & { log_uploads: LiteLogUpload[], deployments: deployments[] })[]
defaultProjectID: string
}
@@ -36,8 +37,6 @@ function DashboardHome({
router.push(`/?view=runs&projectID=${projectID}`, undefined, { shallow: true })
}
- const logs = projects.flatMap(p => p.logs)
-
const projectsWithDeployments = projects
.filter(p => {
if (p.deployments.length !== 1) return false
@@ -66,7 +65,7 @@ function DashboardHome({
/>
) : view === 'logs' ? (
<AgentLogFilesList
- logs={logs}
+ logUploads={projects.flatMap(p => p.log_uploads)}
defaultProjectID={defaultProjectID}
initialSelectedLogFileID={selectedLogFileID}
/>
diff --git a/pages/index.tsx b/pages/index.tsx
index 1d4606a78..83a498c96 100644
--- a/pages/index.tsx
+++ b/pages/index.tsx
@@ -2,24 +2,18 @@ import type { GetServerSideProps } from 'next'
import { createServerSupabaseClient } from '@supabase/auth-helpers-nextjs'
import { nanoid } from 'nanoid'
-import { deployments, prisma, projects } from 'db/prisma'
+import { prisma, projects, log_files, log_uploads, deployments } from 'db/prisma'
import { serverCreds } from 'db/credentials'
import DashboardHome from 'components/DashboardHome'
-import { RawFileLog, Log } from 'utils/agentLogs'
-
-export type ProjectWithLogFiles = projects & {
- deployments: deployments[]
- logs: Log[]
-}
export const getServerSideProps: GetServerSideProps<Props> = async (ctx) => {
// Select the 'deployed' view by default.
const view = ctx.query['view'] as string
- const joinTeamID = ctx.query['team'] as string | undefined
+ const defaultNewTeamID = process.env.DEFAULT_NEW_TEAM_ID as string | undefined
if (!view) {
return {
redirect: {
- destination: joinTeamID ? `/?view=logs&team=${joinTeamID}` : '/?view=logs',
+ destination: '/?view=logs',
permanent: false,
}
}
@@ -53,7 +47,11 @@ export const getServerSideProps: GetServerSideProps<Props> = async (ctx) => {
created_at: 'desc',
},
include: {
- logs: true,
+ log_uploads: {
+ include: {
+ log_files: true,
+ },
+ },
},
},
},
@@ -74,16 +72,16 @@ export const getServerSideProps: GetServerSideProps<Props> = async (ctx) => {
const defaultTeam =
user?.users_teams.flatMap(u => u.teams)?.find(t => t.is_default) ||
- (joinTeamID && await prisma.teams.update({
+ (defaultNewTeamID && await prisma.teams.update({
where: {
- id: joinTeamID,
+ id: defaultNewTeamID,
},
data: {
users_teams: {
connectOrCreate: {
where: {
user_id_team_id: {
- team_id: joinTeamID,
+ team_id: defaultNewTeamID,
user_id: session.user.id,
},
},
@@ -96,7 +94,11 @@ export const getServerSideProps: GetServerSideProps<Props> = async (ctx) => {
include: {
projects: {
include: {
- logs: true,
+ log_uploads: {
+ include: {
+ log_files: true,
+ },
+ },
},
},
},
@@ -105,9 +107,13 @@ export const getServerSideProps: GetServerSideProps<Props> = async (ctx) => {
include: {
projects: {
include: {
- logs: true,
- }
- }
+ log_uploads: {
+ include: {
+ log_files: true,
+ },
+ },
+ },
+ },
},
data: {
id: nanoid(),
@@ -146,7 +152,11 @@ export const getServerSideProps: GetServerSideProps<Props> = async (ctx) => {
},
},
include: {
- logs: true,
+ log_uploads: {
+ include: {
+ log_files: true,
+ },
+ },
},
})
@@ -154,31 +164,30 @@ export const getServerSideProps: GetServerSideProps<Props> = async (ctx) => {
props: {
defaultProjectID: defaultProject.id,
projects: [defaultProject]
- .map<ProjectWithLogFiles>(p => {
- return {
- ...p,
- // Don't send any deployments to the client.
- deployments: [],
- logs: p
- .logs
- .filter(l => l.data !== null)
- .map(l => {
- return {
- id: l.id,
- files: (l.data as unknown as RawFileLog[]).map(f => ({
- name: f.filename,
- relativePath: f.metadata.relativePath,
- }))
- }
- })
- }
- })
+ .map(p => ({
+ ...p,
+ // Don't send any deployments to the client but keep the props structure so we don't have to change the component now.
+ deployments: [],
+ logs_uploads: p
+ .log_uploads
+ .map<LiteLogUpload>(u => ({
+ ...u,
+ log_files: u.log_files.map(f => ({
+ ...f,
+ content: undefined,
+ })),
+ }))
+ }))
},
}
}
+export interface LiteLogUpload extends Omit<log_uploads, 'log_files'> {
+ log_files: Omit<log_files, 'content'>[]
+}
+
export interface Props {
- projects: ProjectWithLogFiles[]
+ projects: (projects & { log_uploads: LiteLogUpload[], deployments: deployments[] })[]
defaultProjectID: string
}
diff --git a/pages/log/[logFileID].tsx b/pages/log/[logFileID].tsx
index 4258a134e..7e060ed7d 100644
--- a/pages/log/[logFileID].tsx
+++ b/pages/log/[logFileID].tsx
@@ -1,5 +1,5 @@
import { useState } from 'react'
-import { AgentPromptLogs, AgentNextActionLog, LogFile, RawFileLog } from 'utils/agentLogs'
+import { AgentPromptLogs, AgentNextActionLog, } from 'utils/agentLogs'
import type { GetServerSideProps } from 'next'
import { createServerSupabaseClient } from '@supabase/auth-helpers-nextjs'
import type { ParsedUrlQuery } from 'querystring'
@@ -7,7 +7,7 @@ import clsx from 'clsx'
import Splitter from '@devbookhq/splitter'
import Link from 'next/link'
-import { prisma } from 'db/prisma'
+import { log_files, prisma } from 'db/prisma'
import { serverCreds } from 'db/credentials'
import {
SystemPromptLog,
@@ -16,16 +16,16 @@ import {
} from 'utils/agentLogs'
import AgentPrompLogDetail from 'components/AgentPromptLogDetail'
import AgentPromptLogsList from 'components/AgentPromptLogsList'
+import { alwaysTrue } from 'utils/positive'
interface PathProps extends ParsedUrlQuery {
logFileID: string
}
export interface Props {
- logFile: LogFile & { content: AgentPromptLogs | AgentNextActionLog }
+ logFile: log_files & { content: AgentPromptLogs | AgentNextActionLog }
}
-
export const getServerSideProps: GetServerSideProps<Props, PathProps> = async (ctx) => {
const logFileID = ctx.params?.logFileID
if (!logFileID) {
@@ -36,13 +36,6 @@ export const getServerSideProps: GetServerSideProps<Props, PathProps> = async (c
}
}
}
- const logFileName = ctx.query['filename'] as string | undefined
- if (!logFileName) {
- console.log('no file specified in the "filename" query string', logFileName)
- return {
- notFound: true,
- }
- }
const supabase = createServerSupabaseClient(ctx, serverCreds)
const {
@@ -68,16 +61,13 @@ export const getServerSideProps: GetServerSideProps<Props, PathProps> = async (c
teams: {
include: {
projects: {
- where: {
- logs: {
- some: {
+ include: {
+ log_files: {
+ where: {
id: logFileID,
},
},
},
- include: {
- logs: true,
- },
},
},
},
@@ -86,53 +76,28 @@ export const getServerSideProps: GetServerSideProps<Props, PathProps> = async (c
},
})
- const log = user
+ const logFile = user
?.users_teams
- .flatMap((ut) => ut.teams)
- .flatMap((t) => t.projects)
- .flatMap((p) => p.logs)
- .find((l) => l.id === logFileID)
+ .flatMap(ut => ut.teams)
+ .flatMap(t => t.projects)
+ .flatMap(p => p.log_files)
+ .find(alwaysTrue)
- if (!log) {
+ if (!logFile) {
return {
notFound: true,
}
}
- const files = log.data
-
- if (!files) {
- console.log('no files')
- return {
- notFound: true,
- }
- }
-
- if (!log.data || log.data.length === 0) {
- console.log('no files')
- return {
- notFound: true,
- }
- }
-
- const file = (log.data as unknown as RawFileLog[])
- .find((f) => f.filename === logFileName)
-
- if (!file) {
- console.log('file not found', logFileName)
- return {
- notFound: true,
- }
- }
+ const parsedFileContent = JSON.parse(logFile.content)
// Specific to AutoGPT
- if (file.filename.includes('next_action')) {
+ if (logFile.filename.includes('next_action')) {
return {
props: {
logFile: {
- name: file.filename,
- content: JSON.parse(file.content),
- relativePath: file.metadata.relativePath,
+ ...logFile,
+ content: parsedFileContent as AgentNextActionLog,
}
}
}
@@ -141,13 +106,14 @@ export const getServerSideProps: GetServerSideProps<Props, PathProps> = async (c
return {
props: {
logFile: {
- name: file.filename,
+ ...logFile,
content: {
- logs: JSON.parse(file.content),
- },
- relativePath: file.metadata.relativePath,
- }
- }
+ ...parsedFileContent,
+ logs: parsedFileContent?.context || [],
+ context: undefined,
+ } as AgentPromptLogs,
+ },
+ },
}
}
@@ -166,7 +132,7 @@ function LogFile({ logFile }: Props) {
<h1 className="text-2xl font-semibold leading-7 text-[#6366F1]">Log Files</h1>
</Link>
<h1 className="text-2xl font-semibold leading-7 text-[#6366F1]">/</h1>
- <h1 className="text-2xl font-semibold leading-7 text-white font-mono">{logFile.name}</h1>
+ <h1 className="text-2xl font-semibold leading-7 text-white font-mono">{logFile.filename}</h1>
</header>
<div className="flex-1 flex items-start justify-start space-x-2 sm:p-6 lg:px-8 overflow-hidden">
@@ -187,7 +153,7 @@ function LogFile({ logFile }: Props) {
}}
initialSizes={sizes}
>
- {logFile.name.includes('full_message_history') || logFile.name.includes('current_context') ? (
+ {logFile.filename.includes('full_message_history') || logFile.filename.includes('current_context') ? (
<>
<AgentPromptLogsList
logs={(logFile.content as AgentPromptLogs).logs}
@@ -197,7 +163,7 @@ function LogFile({ logFile }: Props) {
log={selectedLog}
/>
</>
- ) : logFile.name.includes('next_action') ? (
+ ) : logFile.filename.includes('next_action') ? (
<div />
) : (
<div>
diff --git a/prisma/schema.prisma b/prisma/schema.prisma
index 8b9c34119..3c0103dec 100644
--- a/prisma/schema.prisma
+++ b/prisma/schema.prisma
@@ -282,6 +282,8 @@ model projects {
development_logs Json[]
is_default Boolean @default(false)
deployments deployments[]
+ log_files log_files[]
+ log_uploads log_uploads[]
logs logs[]
teams teams @relation(fields: [team_id], references: [id], onDelete: Cascade, onUpdate: NoAction)
@@ -331,6 +333,34 @@ model feedback {
@@schema("public")
}
+/// This model contains row level security and requires additional setup for migrations. Visit https://pris.ly/d/row-level-security for more info.
+model log_files {
+ id String @id @db.Uuid
+ created_at DateTime? @default(now()) @db.Timestamptz(6)
+ content String @default("")
+ filename String
+ size BigInt
+ relativePath String
+ last_modified DateTime @db.Timestamptz(6)
+ project_id String
+ log_upload_id String? @db.Uuid
+ log_upload log_uploads? @relation(fields: [log_upload_id], references: [id], onDelete: Cascade, onUpdate: NoAction)
+ projects projects @relation(fields: [project_id], references: [id], onDelete: Cascade, onUpdate: NoAction)
+
+ @@schema("public")
+}
+
+/// This model contains row level security and requires additional setup for migrations. Visit https://pris.ly/d/row-level-security for more info.
+model log_uploads {
+ id String @id @default(dbgenerated("gen_random_uuid()")) @db.Uuid
+ created_at DateTime? @default(now()) @db.Timestamptz(6)
+ project_id String?
+ log_files log_files[]
+ projects projects? @relation(fields: [project_id], references: [id], onDelete: Cascade, onUpdate: NoAction)
+
+ @@schema("public")
+}
+
enum aal_level {
aal1
aal2
diff --git a/utils/agentLogs.ts b/utils/agentLogs.ts
index e40a77f27..c8d87d781 100644
--- a/utils/agentLogs.ts
+++ b/utils/agentLogs.ts
@@ -1,29 +1,3 @@
-export interface RawFileLog {
- filename: string
- content: string
- metadata: {
- size: number,
- type: string,
- timestamp: number,
- relativePath: string,
- }
-}
-
-export interface Log {
- id: string;
- files: LogFile[]
-}
-
-export interface LogsMetadata {
-
-}
-
-export interface LogFile {
- name: string
- relativePath: string
-}
-
-
export interface AgentPromptLogs {
logs: (SystemPromptLog | UserPromptLog | AssistantPromptLog)[]
functions?: AgentFunction[]
diff --git a/utils/positive.ts b/utils/positive.ts
new file mode 100644
index 000000000..d7e0bb5b8
--- /dev/null
+++ b/utils/positive.ts
@@ -0,0 +1,3 @@
+export function alwaysTrue() {
+ return true
+}