Skip to content

armgit / E2B

Public Imported from GitHub
0

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

commit

Vasek Mlejnsky265ac1e76c5c
diff --git a/api-service/codegen/tools/human/tools.py b/api-service/codegen/tools/human/tools.py
index e2438ef08..d46df93b9 100644
--- a/api-service/codegen/tools/human/tools.py
+++ b/api-service/codegen/tools/human/tools.py
@@ -29,9 +29,14 @@ def create_human_tools(
print("+++ OPTIONS")
print(options)
print("--- OPTIONS")
- sleep(60)
- return "Spotify API"
- # output = await playground.let_human_choose(extract_code(options))
+
+ thread: Any = playground.api.wait_for_log_output(
+ run_id=run_id,
+ async_req=True,
+ )
+
+ response: ToolsLogOutput = thread.get()
+ return response.response
yield let_human_choose
diff --git a/api-service/playground/src/data/logOutput.ts b/api-service/playground/src/data/logOutput.ts
index c5d6bbb18..e67ac12b7 100644
--- a/api-service/playground/src/data/logOutput.ts
+++ b/api-service/playground/src/data/logOutput.ts
@@ -24,7 +24,11 @@ function checkForResponse(payloadList: any[]): string | null {
return null
}
- if (payload.type === 'tool' && payload.tool_name === 'AskHuman' && payload.tool_output) {
+ if (payload.type === 'tool' &&
+ payload.tool_name === 'AskHuman' &&
+ payload.tool_name === 'LetHumanChoose' &&
+ payload.tool_output
+ ) {
return payload.tool_output
}
return null
diff --git a/components/Editor/Sidebar/Logs/Thought.tsx b/components/Editor/Sidebar/Logs/Thought.tsx
index 1d1d8d173..cf98be321 100644
--- a/components/Editor/Sidebar/Logs/Thought.tsx
+++ b/components/Editor/Sidebar/Logs/Thought.tsx
@@ -12,6 +12,7 @@ function Thought({
const content = useMemo(() => {
return log.content
.replaceAll('\nAction:', '')
+ .replaceAll('Action:', '')
.replaceAll('Thought:', '')
.trim()
}, [log.content])
diff --git a/components/Editor/Sidebar/Logs/Tool/AskHuman.tsx b/components/Editor/Sidebar/Logs/Tool/AskHuman.tsx
index dbd091dda..8878a038a 100644
--- a/components/Editor/Sidebar/Logs/Tool/AskHuman.tsx
+++ b/components/Editor/Sidebar/Logs/Tool/AskHuman.tsx
@@ -36,7 +36,6 @@ function AskHuman({
if (log.tool_input.trim()) {
body = (
<div className="
- pt-2
flex
flex-col
items-stretch
diff --git a/components/Editor/Sidebar/Logs/Tool/LetHumanChoose.tsx b/components/Editor/Sidebar/Logs/Tool/LetHumanChoose.tsx
index e9cfb7bcd..64b62dd29 100644
--- a/components/Editor/Sidebar/Logs/Tool/LetHumanChoose.tsx
+++ b/components/Editor/Sidebar/Logs/Tool/LetHumanChoose.tsx
@@ -1,28 +1,112 @@
+import {
+ useState,
+ useEffect,
+ ReactNode,
+ Fragment,
+} from 'react'
import {
HelpCircle,
} from 'lucide-react'
-// import Text from 'components/Text'
+import Text from 'components/Text'
// import Input from 'components/Input'
// import Button from 'components/Button'
import { ToolName, ToolLog } from 'db/types'
import Base from './Base'
+
export interface Props {
log: ToolLog
+ onAnswer?: (logID: string, answer: string) => void
}
function LetHumanChoose({
log,
+ onAnswer,
}: Props) {
if (log.tool_name !== ToolName.LetHumanChoose) throw new Error(`'${log.tool_name}': This component supports only logs for '${ToolName.LetHumanChoose}' tool`)
- const body = (
- <div>
- {log.tool_input.trim()}
- </div>
- )
+ const [body, setBody] = useState<ReactNode>()
+
+ useEffect(function createBody() {
+ const xmlString = log.tool_input.trim()
+ if (!xmlString) {
+ console.error('LetHumanChoose: Tool input is empty')
+ console.log({ log })
+ return
+ }
+
+ try {
+ const parser = new DOMParser()
+ const xml = parser.parseFromString(`<root>${xmlString}</root>`, 'text/xml')
+ const question = xml.querySelector('question')
+ const options = xml.querySelectorAll('option')
+
+ if (!question) {
+ throw new Error('LetHumanChoose: No question found')
+ }
+
+ if (options.length === 0) {
+ throw new Error('LetHumanChoose: No options found')
+ }
+
+ console.log({ question })
+ const b = (
+ <div className="
+ flex
+ flex-col
+ items-stretch
+ space-y-2
+ ">
+ <Text
+ className="font-medium"
+ text={`AI: ${question.textContent}`}
+ />
+
+ <div
+ className="
+ flex
+ flex-col
+ space-y-1
+ items-stretch
+ "
+ >
+ {[...options].map((option, idx) => (
+ <Fragment
+ key={idx}
+ >
+ {(option.textContent !== null && option.textContent) ? (
+ <div
+ key={idx}
+ className="
+ border
+ hover:border-green-600
+ transition-all
+ rounded
+ p-2
+ cursor-pointer
+ "
+ onClick={() => onAnswer?.(log.id, option.textContent!)}
+ >
+ <Text
+ text={option.textContent}
+ size={Text.size.S2}
+ />
+ </div>
+ ) : null}
+ </Fragment>
+ ))}
+ </div>
+ </div>
+ )
+ setBody(b)
+ } catch (err) {
+ console.error('LetHumanChoose: Error parsing XML:', err)
+ console.log({ log })
+ return
+ }
+ }, [log])
return (
<Base
diff --git a/components/Editor/Sidebar/Logs/Tool/index.tsx b/components/Editor/Sidebar/Logs/Tool/index.tsx
index bb40f9fd3..a92b491e3 100644
--- a/components/Editor/Sidebar/Logs/Tool/index.tsx
+++ b/components/Editor/Sidebar/Logs/Tool/index.tsx
@@ -28,7 +28,7 @@ function Tool({
case ToolName.AskHuman:
return <AskHuman log={log} onAnswer={onAnswer} />
case ToolName.LetHumanChoose:
- return <LetHumanChoose log={log} />
+ return <LetHumanChoose log={log} onAnswer={onAnswer} />
default:
return <div>Cannot render frontend component - unknown tol {log.tool_name}</div>
}
diff --git a/components/Editor/Sidebar/Logs/index.tsx b/components/Editor/Sidebar/Logs/index.tsx
index 4cf9d6fc7..d76550ae7 100644
--- a/components/Editor/Sidebar/Logs/index.tsx
+++ b/components/Editor/Sidebar/Logs/index.tsx
@@ -1,4 +1,4 @@
-import { useCallback, useState } from 'react'
+import { useState } from 'react'
// import hljs from 'highlight.js'
import { deployments } from '@prisma/client'
@@ -46,21 +46,14 @@ function Logs({
// }, [logs, selectedTab])
async function saveAnswer(logID: string, answer: string) {
- console.log('BEFORE', { logID, answer })
if (!deployment) return
- console.log('SAVE ANSWER', { logID, answer })
-
const logs = produce(deployment.logs as unknown as Log[], ls => {
- console.log('LOGS', { logs: ls, logID, })
const log = ls.find(l => l.id === logID)
- console.log('FOUND LOG', { ...log })
if (log && log.type === LogType.Tool && log.tool_name === ToolName.AskHuman) {
- console.log('ANSWER', { log, answer })
log.tool_output = answer
}
})
- console.log('LOGS', logs)
await client.from(deploymentsTable).update({ logs: logs as unknown as Json[] }).eq('id', deployment.id).single()
}