Open-source, secure environment with real-world tools for enterprise-grade agents.
Python agentaiai-agentai-agentscode-interpretercopilotdevelopmentdevtoolsgptgpt-4javascriptllmnextjsopenaipythonreactsoftwaretypescript
tags [wip]
Vasek Mlejnsky65545332e731
diff --git a/components/AgentChallengeTag.tsx b/components/AgentChallengeTag.tsxnew file mode 100644index 000000000..abbf2ccaf--- /dev/null+++ b/components/AgentChallengeTag.tsx@@ -0,0 +1,25 @@+import clsx from 'clsx'+import { AgentChallengeTag as AgentChallengeTagType } from 'utils/agentLogs'++export interface Props {+ tag: AgentChallengeTagType+}++function AgentChallengeTag({+ tag,+}: Props) {+ return (+ <span+ className={clsx(+ 'flex items-center justify-center h-6 px-2 rounded-md text-xs border',+ tag.severity === 'Success' && 'bg-green-500/10 border-green-500/20 text-green-500',+ tag.severity === 'Warning' && 'bg-orange-500/10 border-orange-500/20 text-orange-500',+ tag.severity === 'Error' && 'bg-red-500/10 border-red-500/20 text-red-500',+ )}+ >+ {tag.text}+ </span>+ )+}++export default AgentChallengeTag\ No newline at end of filediff --git a/components/AgentChallengeTagButton.tsx b/components/AgentChallengeTagButton.tsxnew file mode 100644index 000000000..add98bf1e--- /dev/null+++ b/components/AgentChallengeTagButton.tsx@@ -0,0 +1,54 @@+import {+ useState,+} from 'react'+import {+ Plus,+} from 'lucide-react'+import AgentChallengeTagModal, { Severity } from 'components/AgentChallengeTagModal'++export interface Props {+ newTagName: string+ onNewTagNameChange: (e: any) => void+ onSeveritySelect: (s: Severity) => void+}++function AgentChallengeTagButton({+ newTagName,+ onNewTagNameChange,+ onSeveritySelect,+}: Props) {+ const [isModalOpen, setIsModalOpen] = useState(false)++ function handleButtonClick() {+ setIsModalOpen(val => !val)+ }++ function handleModalClickOutside() {+ setIsModalOpen(false)+ }++ return (+ <div className="relative">+ <button+ className="flex items-center justify-center text-xs shrink-0 text-gray-400 bg-[#1F2437] hover:bg-[#272D44] h-6 w-6 rounded-md"+ onClick={handleButtonClick}+ >+ <Plus size={14} />+ </button>++ {isModalOpen && (+ <>+ <div className="fixed inset-0 bg-transparent z-40" />+ <AgentChallengeTagModal+ value={newTagName}+ onChange={onNewTagNameChange}+ onClickOutside={handleModalClickOutside}+ onSeveritySelect={onSeveritySelect}+ />+ </>+ )}+ </div>+ )+}++export default AgentChallengeTagButton\ No newline at end of filediff --git a/components/AgentChallengeTagModal.tsx b/components/AgentChallengeTagModal.tsxnew file mode 100644index 000000000..954fc9200--- /dev/null+++ b/components/AgentChallengeTagModal.tsx@@ -0,0 +1,105 @@+import {+ useRef,+} from 'react'+import useOnClickOutside from 'hooks/useOnClickOutside'++export type Severity = 'Success' | 'Warning' | 'Error'++export interface Props {+ value: string+ onChange: (e: any) => void+ onClickOutside: (e: any) => void+ onSeveritySelect: (s: Severity) => void+}++function AgentChallengeTagModal({+ value,+ onChange,+ onClickOutside,+ onSeveritySelect,+}: Props) {+ const ref = useRef<HTMLDivElement>(null)++ function handleClickOutside(e: any) {+ onClickOutside(e)+ }++ useOnClickOutside(ref, handleClickOutside)++ return (+ <div+ ref={ref}+ className="+ absolute+ left-1/2+ top-1/2+ w-[200px]+ py-2+ border+ border-[#6366F1]/50+ shadow-lg+ bg-[#1F2437]+ z-50+ rounded-lg+ ">+ <input+ className="+ w-full+ bg-transparent+ px-2+ pb-4+ text-sm+ outline-none+ border-b+ border-b-white/5+ placeholder:text-gray-600+ "+ value={value}+ onChange={onChange}+ placeholder="Tag name"+ autoFocus+ />+ <span className="p-2 text-xs text-gray-500">Select Severity</span>+ <div className="+ p-2+ flex+ flex-col+ space-y-2+ items-start+ justify-start+ ">+ <button+ className="w-full rounded p-2 flex items-center justify-start space-x-2 hover:bg-[#31374F]"+ onClick={() => onSeveritySelect('Success')}+ >+ <div className="w-4 h-4 flex items-center justify-center bg-green-500/10 border border-green-500/20 rounded-full">+ <div className="w-2 h-2 rounded-full bg-green-500" />+ </div>+ <span className="text-sm text-gray-300">Success</span>+ </button>++ <button+ className="w-full rounded p-2 flex items-center justify-start space-x-2 hover:bg-[#31374F]"+ onClick={() => onSeveritySelect('Warning')}+ >+ <div className="w-4 h-4 flex items-center justify-center bg-orange-500/10 border border-orange-500/20 rounded-full">+ <div className="w-2 h-2 rounded-full bg-orange-500" />+ </div>+ <span className="text-sm text-gray-300">Warning</span>+ </button>++ <button+ className="w-full rounded p-2 flex items-center justify-start space-x-2 hover:bg-[#31374F]"+ onClick={() => onSeveritySelect('Error')}+ >+ <div className="w-4 h-4 flex items-center justify-center bg-red-500/10 border border-red-500/20 rounded-full">+ <div className="w-2 h-2 rounded-full bg-red-500" />+ </div>+ <span className="text-sm text-gray-300">Error</span>+ </button>+ </div>+ </div>+ )+}++export default AgentChallengeTagModal\ No newline at end of filediff --git a/components/Filesystem/Dir.tsx b/components/Filesystem/Dir.tsxindex 1665336d6..98e8fef66 100644--- a/components/Filesystem/Dir.tsx+++ b/components/Filesystem/Dir.tsx@@ -1,13 +1,35 @@import {- ChevronDown as ChevronDownIcon,- ChevronRight as ChevronRightIcon,+ useState,+} from 'react'+import {+ ChevronDown,+ ChevronRight,+ X,} from 'lucide-react'import clsx from 'clsx'+import {+ useMetadata,+} from 'hooks/filesystem'+import { AgentChallengeTag as AgentChallengeTagType } from 'utils/agentLogs'+import AgentChallengeTagButton from 'components/AgentChallengeTagButton'+import { Severity } from 'components/AgentChallengeTagModal'+import AgentChallengeTag from 'components/AgentChallengeTag'import {DirProps,NodeType,-} from '../../filesystem'+} from 'filesystem'+++++// export interface CustomProps {+// tags: [{+// type: string+// challenge: string+// }]+// }+// export type Props = DirProps & CustomPropsfunction Dir({name,@@ -19,6 +41,19 @@ function Dir({isExpanded,isSelected,}: DirProps) {+ const [node] = useState(fs.find(path))+ const [newTagName, setNewTagName] = useState('')+ const [, setMetadata] = useMetadata<AgentChallengeTagType[]>(fs, path, 'tags', true)+ const tags = metadata?.tags || [] as AgentChallengeTagType[]+ // console.log('metadata', metadata)++ // useEffect(() => {+ // if (path === '/20230616_054339_memory_challenge_a_level_3') {+ // setMetadata([{ challengeDir: '20230616_054339_memory_challenge_a_level_3', text: 'challenge', color: 'red' }])+ // }+ // }, [path])++function handleOnClick(e: any) {fs.setIsDirExpanded(path, !isExpanded)@@ -38,13 +73,30 @@ function Dir({})}+ function addNewTag(s: Severity) {+ if (!newTagName) return+ // TODO: Add tag in DB to all files that has this challenge dir as an ancestor+ const newTag: AgentChallengeTagType = {+ path,+ text: newTagName,+ severity: s,+ }+ console.log('New tag', newTag)+ setNewTagName('')+ setMetadata([newTag])+ }++ function removeTag() {+ setMetadata([])+ }+const icon = isExpanded ? (- <ChevronDownIcon+ <ChevronDownclassName="text-white/60 shrink-0"size={16}/>) : (- <ChevronRightIcon+ <ChevronRightclassName="text-white/60 shrink-0"size={16}/>@@ -52,31 +104,55 @@ function Dir({return (<div className="flex flex-col rounded w-full">- <div- className={clsx(- 'px-1',- 'py-2',- 'flex',- 'items-center',- 'w-full',- 'rounded-md',- 'space-x-1',- 'cursor-pointer',- 'border-gray-800',- 'hover:bg-[#1F2437]',- { 'bg-transparent': !isSelected },+ <div className="flex items-center justify-start w-full space-x-1">+ {tags.map((tag: AgentChallengeTagType, i: number) => (+ <div className="flex items-center space-x-1" key={i}>+ <AgentChallengeTag+ tag={tag}+ />+ <button+ className="text-gray-400 hover:text-gray-400"+ onClick={removeTag}+ >+ <X size={12} />+ </button>+ </div>+ ))}++ {/* AutoGPT wants to add tags only for challenges - challenges are the first "dirs" -> very heuristic and works only for AutoGPT */}+ {tags.length === 0 && node?.level === 0 && (+ <AgentChallengeTagButton+ newTagName={newTagName}+ onNewTagNameChange={e => setNewTagName(e.target.value)}+ onSeveritySelect={addNewTag}+ />)}- onClick={handleOnClick}- >- {icon}- <span- className="- text-sm- text-gray-200- whitespace-nowrap- ">- {name}- </span>+ <div+ className={clsx(+ 'px-1',+ 'py-2',+ 'flex',+ 'items-center',+ 'w-full',+ 'rounded-md',+ 'space-x-1',+ 'cursor-pointer',+ 'border-gray-800',+ 'hover:bg-[#1F2437]',+ { 'bg-transparent': !isSelected },+ )}+ onClick={handleOnClick}+ >+ {icon}+ <span+ className="+ text-sm+ text-gray-200+ whitespace-nowrap+ ">+ {name}+ </span>+ </div></div>{isExpanded && (diff --git a/components/Filesystem/index.tsx b/components/Filesystem/index.tsxindex 8cfd804ad..d6487aa5a 100644--- a/components/Filesystem/index.tsx+++ b/components/Filesystem/index.tsx@@ -15,10 +15,12 @@ import FilesystemPrimitive, {import Dir from './Dir'import File from './File'+import { AgentChallengeTag } from 'utils/agentLogs'export interface FileInfo {isDir: booleanname: string+ tags: AgentChallengeTag[]}export interface Props {@@ -56,6 +58,9 @@ function Filesystem({}})))fs.add(dirpath, ns, ignore)+ files.forEach(f => {+ fs.setMetadata<AgentChallengeTag[]>(path.join(dirpath, f.name), { key: 'tags', value: f.tags })+ })}, [fs,fetchContent,diff --git a/components/UploadFiletree.tsx b/components/UploadFiletree.tsxindex 6d4e863a8..b280e71da 100644--- a/components/UploadFiletree.tsx+++ b/components/UploadFiletree.tsx@@ -2,7 +2,7 @@ import { useCallback } from 'react'import path from 'path-browserify'import Filesystem, { FileInfo } from 'components/Filesystem'-import { LiteDeployment, LiteLogFile, LiteLogUpload } from 'utils/agentLogs'+import { AgentChallengeTag, LiteDeployment, LiteLogFile, LiteLogUpload } from 'utils/agentLogs'import { FiletreeProvider } from 'hooks/useFiletree'export interface Props {@@ -15,6 +15,11 @@ function UploadTree({selectedLogFile,}: Props) {const fetchLogDirContent = useCallback<(dirpath: string) => (FileInfo & { id?: string })[]>(dirpath => {+ let tags: AgentChallengeTag[] = []+ if ((logUpload as any)['tags']) {+ tags = (logUpload as LiteLogUpload)['tags']+ }+const currentDir = dirpath.slice(1)const childFiles = logUpload.log_files@@ -47,10 +52,13 @@ function UploadTree({name: f.filename,isDir: false,id: f.id,+ tags: [],})),...Array.from(childDirs).map(dir => ({name: dir,isDir: true,+ // Filter out tags that don't belong to this dir.+ tags: tags.filter(t => t.path === dir),})),]return contentdiff --git a/hooks/useOnClickOutside.ts b/hooks/useOnClickOutside.tsnew file mode 100644index 000000000..26b150c0b--- /dev/null+++ b/hooks/useOnClickOutside.ts@@ -0,0 +1,20 @@+import {+ useEffect,+ RefObject,+ DependencyList,+} from 'react'++function useOnClickOutside(ref: RefObject<HTMLElement>, cb: (e: MouseEvent) => any, deps: DependencyList = []) {+ useEffect(function listenToMouseDownEvent() {+ function handleMouseDown(e: MouseEvent) {+ if (e.target && !ref.current?.contains(e.target as Node)) {+ cb(e)+ }+ }++ document.addEventListener('mousedown', handleMouseDown, true)+ return () => document.removeEventListener('mousedown', handleMouseDown, true)+ }, [ref, cb, ...deps])+}++export default useOnClickOutside\ No newline at end of filediff --git a/prisma/schema.prisma b/prisma/schema.prismaindex 108984f2b..14dd43f58 100644--- a/prisma/schema.prisma+++ b/prisma/schema.prisma@@ -347,6 +347,7 @@ model log_uploads {created_at DateTime @default(now()) @db.Timestamptz(6)project_id String?display_name String? @default("")+ tags Json @default("[]")log_files log_files[]projects projects? @relation(fields: [project_id], references: [id], onDelete: Cascade, onUpdate: NoAction)diff --git a/utils/agentLogs.ts b/utils/agentLogs.tsindex 79adf3431..c94e1c5a2 100644--- a/utils/agentLogs.ts+++ b/utils/agentLogs.ts@@ -12,12 +12,20 @@ export interface LiteDeployment extends deployments {}}+// This is very specific ot AutoGPT logs.+export interface AgentChallengeTag {+ path: string+ text: string+ severity: string+}+export interface LiteLogFile extends Omit<log_files, 'content'> {content: AgentPromptLogs | AgentNextActionLog | string}-export interface LiteLogUpload extends Omit<log_uploads, 'log_files'> {+export interface LiteLogUpload extends Omit<log_uploads, 'log_files' | 'tags'> {log_files: LiteLogFile[]+ tags: AgentChallengeTag[]}export interface AgentPromptLogs {