Skip to content

armgit / E2B

Public Imported from GitHub
0

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

Add user input file handling

Tomas Valenta45c1ec914f7f
diff --git a/components/AgentLogFileContent.tsx b/components/AgentLogFileContent.tsx
index 096811393..86ddc90f8 100644
--- a/components/AgentLogFileContent.tsx
+++ b/components/AgentLogFileContent.tsx
@@ -1,7 +1,6 @@
import {
useState,
} from 'react'
-import { useRouter } from 'next/router'
import Splitter from '@devbookhq/splitter'
import clsx from 'clsx'
@@ -24,21 +23,7 @@ export interface Props {
function AgentLogFileContent({
logFile,
}: Props) {
- const router = useRouter()
const [selectedLog, setSelectedLog] = useState<SystemPromptLog | UserPromptLog | AssistantPromptLog>()
-
- // return (
- // <>
- // <AgentPromptLogsList
- // logs={!!logFile ? (logFile.content as AgentPromptLogs)?.logs : []}
- // onSelected={setSelectedLog}
- // />
- // <AgentPrompLogDetail
- // log={selectedLog}
- // />
- // </>
- // )
-
if (!logFile) return null
return (
@@ -65,6 +50,17 @@ function AgentLogFileContent({
<AgentNextActionLogDetail
log={logFile.content as AgentNextActionLog}
/>
+ ) : logFile.filename.includes('user_input') ? (
+ <div className="overflow-auto p-2 h-full bg-[#1F2437] rounded-md flex flex-col space-y-4 w-full border border-gray-800">
+ <div className="flex flex-col space-y-1 w-full">
+ <span className="text-sm font-medium text-gray-500">User Input</span>
+ <span
+ className="text-sm text-gray-200 w-full prose whitespace-pre-wrap max-w-full"
+ >
+ {logFile.content as string}
+ </span>
+ </div>
+ </div>
) : (
<div>
Unexpected JSON format. Please reach out to the e2b team.
diff --git a/components/DashboardHome.tsx b/components/DashboardHome.tsx
index 6b50e01e0..0453b6ddd 100644
--- a/components/DashboardHome.tsx
+++ b/components/DashboardHome.tsx
@@ -23,7 +23,6 @@ function DashboardHome({
const view = router.query.view as string | undefined
const selectedAgentInstanceID = router.query.projectID as string | undefined
- const selectedLogFileID = router.query.fileID as string | undefined
async function signOut() {
await supabaseClient.auth.signOut()
diff --git a/pages/index.tsx b/pages/index.tsx
index f2135e43c..3762f68c2 100644
--- a/pages/index.tsx
+++ b/pages/index.tsx
@@ -19,9 +19,17 @@ function getLastTwoDirsAndFile(fullPath: string): string {
}
function formatLogFileContent(logFile: Omit<log_files, 'project_id' | 'type' | 'size' | 'last_modified'>) {
- const parsedFileContent = JSON.parse(logFile.content)
const relativePath = getLastTwoDirsAndFile(logFile.relativePath)
+ if (logFile.filename.includes('user_input')) {
+ return {
+ ...logFile,
+ relativePath,
+ content: logFile.content as string,
+ }
+ }
+ const parsedFileContent = JSON.parse(logFile.content)
+
// Specific to AutoGPT
if (logFile.filename.includes('next_action')) {
return {
diff --git a/pages/log/[logFileID].tsx b/pages/log/[logFileID].tsx
deleted file mode 100644
index 816ea45fb..000000000
--- a/pages/log/[logFileID].tsx
+++ /dev/null
@@ -1,179 +0,0 @@
-import { useState } from 'react'
-import type { GetServerSideProps } from 'next'
-import { createServerSupabaseClient } from '@supabase/auth-helpers-nextjs'
-import type { ParsedUrlQuery } from 'querystring'
-import clsx from 'clsx'
-import Splitter from '@devbookhq/splitter'
-import Link from 'next/link'
-
-import { prisma } from 'db/prisma'
-import { serverCreds } from 'db/credentials'
-import {
- SystemPromptLog,
- UserPromptLog,
- AssistantPromptLog,
- AgentPromptLogs,
- AgentNextActionLog,
- LiteLogFile,
-} from 'utils/agentLogs'
-import AgentPrompLogDetail from 'components/AgentPromptLogDetail'
-import AgentPromptLogsList from 'components/AgentPromptLogsList'
-import AgentNextActionLogDetail from 'components/AgentNextActionLogDetail'
-import { alwaysTrue } from 'utils/positive'
-
-interface PathProps extends ParsedUrlQuery {
- logFileID: string
-}
-
-export interface Props {
- logFile: LiteLogFile
-}
-
-export const getServerSideProps: GetServerSideProps<Props, PathProps> = async (ctx) => {
- const logFileID = ctx.params?.logFileID
- if (!logFileID) {
- return {
- redirect: {
- destination: '/?view=logs',
- permanent: false,
- }
- }
- }
-
- const supabase = createServerSupabaseClient(ctx, serverCreds)
- const {
- data: { session },
- } = await supabase.auth.getSession()
-
- if (!session) {
- return {
- redirect: {
- destination: '/sign',
- permanent: false,
- },
- }
- }
-
- const logFiles = await prisma.log_files.findMany({
- where: {
- id: logFileID,
- projects: {
- teams: {
- users_teams: {
- some: {
- user_id: session.user.id,
- },
- },
- },
- },
- },
- })
-
- const logFile = logFiles.find(alwaysTrue)
-
- if (!logFile) {
- return {
- notFound: true,
- }
- }
-
- const parsedFileContent = JSON.parse(logFile.content)
-
- // Specific to AutoGPT
- if (logFile.filename.includes('next_action')) {
- return {
- props: {
- logFile: {
- ...logFile,
- content: parsedFileContent as AgentNextActionLog,
- }
- }
- }
- }
-
- if (logFile.filename.includes('full_message_history') || logFile.filename.includes('current_context')) {
- return {
- props: {
- logFile: {
- ...logFile,
- content: {
- logs: parsedFileContent as AgentPromptLogs,
- },
- },
- },
- }
- }
-
- return {
- props: {
- logFile: {
- ...logFile,
- content: {
- ...parsedFileContent,
- logs: parsedFileContent?.context || [],
- context: undefined,
- },
- } as any,
- },
- }
-}
-
-function LogFile({ logFile }: Props) {
- const [isResizing, setIsResizing] = useState(false)
- const [sizes, setSizes] = useState([60, 40])
- const [selectedLog, setSelectedLog] = useState<SystemPromptLog | UserPromptLog | AssistantPromptLog>()
-
- return (
- <main className="overflow-hidden flex flex-col flex-1">
- <header className="flex items-center space-x-2 px-4 py-5 sm:px-6 sm:py-7 lg:px-8">
- <Link
- href="/?view=logs"
- >
- <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.filename}</h1>
- </header>
-
- <div className="flex-1 flex items-start justify-start space-x-2 sm:p-6 lg:px-8 overflow-hidden">
- {logFile.filename.includes('full_message_history') || logFile.filename.includes('current_context') ? (
- <Splitter
- draggerClassName={clsx(
- 'bg-gray-700 group-hover:bg-[#6366F1] transition-all delay-75 duration-[400ms] w-0.5 h-full',
- isResizing && 'bg-[#6366F1]',
- )}
- gutterClassName={clsx(
- 'mx-2 bg-transparent hover:bg-[#6366F1] transition-all delay-75 duration-[400ms] px-0.5 rounded-sm group',
- isResizing && 'bg-[#6366F1]',
- )}
- classes={['flex', 'flex']}
- onResizeStarted={() => setIsResizing(true)}
- onResizeFinished={(_, newSizes) => {
- setIsResizing(false)
- setSizes(newSizes)
- }}
- initialSizes={sizes}
- >
- <AgentPromptLogsList
- logs={(logFile.content as AgentPromptLogs).logs}
- onSelected={setSelectedLog}
- />
- <AgentPrompLogDetail
- log={selectedLog}
- />
- </Splitter>
- ) : logFile.filename.includes('next_action') ? (
- <AgentNextActionLogDetail
- log={logFile.content as AgentNextActionLog}
- />
- ) : (
- <div>
- Unexpected JSON format. Please reach out to the e2b team.
- </div>
- )}
- </div>
- </main >
- )
-}
-
-export default LogFile
diff --git a/utils/agentLogs.ts b/utils/agentLogs.ts
index 29274084c..a8ef8d3db 100644
--- a/utils/agentLogs.ts
+++ b/utils/agentLogs.ts
@@ -1,7 +1,7 @@
import { log_files, log_uploads } from 'db/prisma'
export interface LiteLogFile extends Omit<log_files, 'project_id' | 'type' | 'size' | 'content' | 'last_modified'> {
- content: AgentPromptLogs | AgentNextActionLog
+ content: AgentPromptLogs | AgentNextActionLog | string
}
export interface LiteLogUpload extends Omit<log_uploads, 'log_files' | 'project_id'> {