diff --git a/.devcontainer/README.MD b/.devcontainer/README.MD deleted file mode 100644 index 001c24beb49b..000000000000 --- a/.devcontainer/README.MD +++ /dev/null @@ -1 +0,0 @@ -The files in this directory configure a development container for GitHub Codespaces. diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json deleted file mode 100644 index 6c97e3bf5523..000000000000 --- a/.devcontainer/devcontainer.json +++ /dev/null @@ -1,15 +0,0 @@ -{ - "name": "OpenHands Codespaces", - "image": "mcr.microsoft.com/devcontainers/universal", - "customizations":{ - "vscode":{ - "extensions": [ - "ms-python.python" - ] - } - }, - "onCreateCommand": "sh ./.devcontainer/on_create.sh", - "postCreateCommand": "make build", - "postStartCommand": "USE_HOST_NETWORK=True nohup bash -c 'make run &'" - -} diff --git a/.devcontainer/on_create.sh b/.devcontainer/on_create.sh deleted file mode 100644 index 43da1023236b..000000000000 --- a/.devcontainer/on_create.sh +++ /dev/null @@ -1,6 +0,0 @@ -#!/usr/bin/env bash -sudo apt update -sudo apt install -y netcat -sudo add-apt-repository -y ppa:deadsnakes/ppa -sudo apt install -y python3.12 -curl -sSL https://install.python-poetry.org | python3.12 - diff --git a/.github/dependabot.yml b/.github/dependabot.yml index e7413f415f57..b4ce891d672f 100644 --- a/.github/dependabot.yml +++ b/.github/dependabot.yml @@ -18,7 +18,7 @@ updates: - "chromadb" browsergym: patterns: - - "browsergym" + - "browsergym*" security-all: applies-to: "security-updates" patterns: diff --git a/.github/workflows/fe-unit-tests.yml b/.github/workflows/fe-unit-tests.yml index b720bfe34c28..dd577b4b43c5 100644 --- a/.github/workflows/fe-unit-tests.yml +++ b/.github/workflows/fe-unit-tests.yml @@ -24,7 +24,8 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - node-version: [20] + node-version: [20, 22] + fail-fast: true steps: - name: Checkout uses: actions/checkout@v4 diff --git a/.github/workflows/openhands-resolver.yml b/.github/workflows/openhands-resolver.yml index 2719c3773607..c19ee472b7dc 100644 --- a/.github/workflows/openhands-resolver.yml +++ b/.github/workflows/openhands-resolver.yml @@ -16,6 +16,10 @@ on: type: string default: "main" description: "Target branch to pull and create PR against" + LLM_MODEL: + required: false + type: string + default: "anthropic/claude-3-5-sonnet-20241022" base_container_image: required: false type: string @@ -23,15 +27,15 @@ on: description: "Custom sandbox env" secrets: LLM_MODEL: - required: true + required: false LLM_API_KEY: required: true LLM_BASE_URL: required: false PAT_TOKEN: - required: true + required: false PAT_USERNAME: - required: true + required: false issues: types: [labeled] @@ -55,7 +59,6 @@ jobs: github.event_name == 'workflow_call' || github.event.label.name == 'fix-me' || github.event.label.name == 'fix-me-experimental' || - ( ((github.event_name == 'issue_comment' || github.event_name == 'pull_request_review_comment') && contains(github.event.comment.body, inputs.macro || '@openhands-agent') && @@ -106,13 +109,14 @@ jobs: - name: Check required environment variables env: - LLM_MODEL: ${{ secrets.LLM_MODEL }} + LLM_MODEL: ${{ secrets.LLM_MODEL || inputs.LLM_MODEL }} LLM_API_KEY: ${{ secrets.LLM_API_KEY }} LLM_BASE_URL: ${{ secrets.LLM_BASE_URL }} PAT_TOKEN: ${{ secrets.PAT_TOKEN }} PAT_USERNAME: ${{ secrets.PAT_USERNAME }} + GITHUB_TOKEN: ${{ github.token }} run: | - required_vars=("LLM_MODEL" "LLM_API_KEY" "PAT_TOKEN" "PAT_USERNAME") + required_vars=("LLM_MODEL" "LLM_API_KEY") for var in "${required_vars[@]}"; do if [ -z "${!var}" ]; then echo "Error: Required environment variable $var is not set." @@ -120,17 +124,34 @@ jobs: fi done + # Check optional variables and warn about fallbacks + if [ -z "$PAT_TOKEN" ]; then + echo "Warning: PAT_TOKEN is not set, falling back to GITHUB_TOKEN" + fi + + if [ -z "$LLM_BASE_URL" ]; then + echo "Warning: LLM_BASE_URL is not set, will use default API endpoint" + fi + + if [ -z "$PAT_USERNAME" ]; then + echo "Warning: PAT_USERNAME is not set, will use openhands-agent" + fi + - name: Set environment variables run: | - if [ -n "${{ github.event.review.body }}" ]; then + # Handle pull request events first + if [ -n "${{ github.event.pull_request.number }}" ]; then + echo "ISSUE_NUMBER=${{ github.event.pull_request.number }}" >> $GITHUB_ENV + echo "ISSUE_TYPE=pr" >> $GITHUB_ENV + # Handle pull request review events + elif [ -n "${{ github.event.review.body }}" ]; then echo "ISSUE_NUMBER=${{ github.event.pull_request.number }}" >> $GITHUB_ENV echo "ISSUE_TYPE=pr" >> $GITHUB_ENV + # Handle issue comment events that reference a PR elif [ -n "${{ github.event.issue.pull_request }}" ]; then echo "ISSUE_NUMBER=${{ github.event.issue.number }}" >> $GITHUB_ENV echo "ISSUE_TYPE=pr" >> $GITHUB_ENV - elif [ -n "${{ github.event.pull_request.number }}" ]; then - echo "ISSUE_NUMBER=${{ github.event.pull_request.number }}" >> $GITHUB_ENV - echo "ISSUE_TYPE=pr" >> $GITHUB_ENV + # Handle regular issue events else echo "ISSUE_NUMBER=${{ github.event.issue.number }}" >> $GITHUB_ENV echo "ISSUE_TYPE=issue" >> $GITHUB_ENV @@ -143,7 +164,7 @@ jobs: fi echo "MAX_ITERATIONS=${{ inputs.max_iterations || 50 }}" >> $GITHUB_ENV - echo "SANDBOX_ENV_GITHUB_TOKEN=${{ secrets.GITHUB_TOKEN }}" >> $GITHUB_ENV + echo "SANDBOX_ENV_GITHUB_TOKEN=${{ secrets.PAT_TOKEN || github.token }}" >> $GITHUB_ENV echo "SANDBOX_ENV_BASE_CONTAINER_IMAGE=${{ inputs.base_container_image }}" >> $GITHUB_ENV # Set branch variables @@ -152,7 +173,7 @@ jobs: - name: Comment on issue with start message uses: actions/github-script@v7 with: - github-token: ${{secrets.GITHUB_TOKEN}} + github-token: ${{ secrets.PAT_TOKEN || github.token }} script: | const issueType = process.env.ISSUE_TYPE; github.rest.issues.createComment({ @@ -177,9 +198,9 @@ jobs: - name: Attempt to resolve issue env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - GITHUB_USERNAME: ${{ secrets.PAT_USERNAME }} - LLM_MODEL: ${{ secrets.LLM_MODEL }} + GITHUB_TOKEN: ${{ secrets.PAT_TOKEN || github.token }} + GITHUB_USERNAME: ${{ secrets.PAT_USERNAME || 'openhands-agent' }} + LLM_MODEL: ${{ secrets.LLM_MODEL || inputs.LLM_MODEL }} LLM_API_KEY: ${{ secrets.LLM_API_KEY }} LLM_BASE_URL: ${{ secrets.LLM_BASE_URL }} PYTHONPATH: "" @@ -189,7 +210,7 @@ jobs: --issue-number ${{ env.ISSUE_NUMBER }} \ --issue-type ${{ env.ISSUE_TYPE }} \ --max-iterations ${{ env.MAX_ITERATIONS }} \ - --comment-id ${{ env.COMMENT_ID }} \ + --comment-id ${{ env.COMMENT_ID }} - name: Check resolution result id: check_result @@ -211,9 +232,9 @@ jobs: - name: Create draft PR or push branch if: always() # Create PR or branch even if the previous steps fail env: - GITHUB_TOKEN: ${{ secrets.PAT_TOKEN }} - GITHUB_USERNAME: ${{ secrets.PAT_USERNAME }} - LLM_MODEL: ${{ secrets.LLM_MODEL }} + GITHUB_TOKEN: ${{ secrets.PAT_TOKEN || github.token }} + GITHUB_USERNAME: ${{ secrets.PAT_USERNAME || 'openhands-agent' }} + LLM_MODEL: ${{ secrets.LLM_MODEL || inputs.LLM_MODEL }} LLM_API_KEY: ${{ secrets.LLM_API_KEY }} LLM_BASE_URL: ${{ secrets.LLM_BASE_URL }} PYTHONPATH: "" @@ -221,7 +242,8 @@ jobs: if [ "${{ steps.check_result.outputs.RESOLUTION_SUCCESS }}" == "true" ]; then cd /tmp && python -m openhands.resolver.send_pull_request \ --issue-number ${{ env.ISSUE_NUMBER }} \ - --pr-type draft | tee pr_result.txt && \ + --pr-type draft \ + --reviewer ${{ github.actor }} | tee pr_result.txt && \ grep "draft created" pr_result.txt | sed 's/.*\///g' > pr_number.txt else cd /tmp && python -m openhands.resolver.send_pull_request \ @@ -235,7 +257,7 @@ jobs: uses: actions/github-script@v7 if: always() # Comment on issue even if the previous steps fail with: - github-token: ${{secrets.GITHUB_TOKEN}} + github-token: ${{ secrets.PAT_TOKEN || github.token }} script: | const fs = require('fs'); const issueNumber = ${{ env.ISSUE_NUMBER }}; diff --git a/.github/workflows/py-unit-tests.yml b/.github/workflows/py-unit-tests.yml index 6e624904a82f..28a14095d7c1 100644 --- a/.github/workflows/py-unit-tests.yml +++ b/.github/workflows/py-unit-tests.yml @@ -42,7 +42,7 @@ jobs: - name: Build Environment run: make build - name: Run Tests - run: poetry run pytest --forked --cov=openhands --cov-report=xml -svv ./tests/unit --ignore=tests/unit/test_memory.py + run: poetry run pytest --forked -n auto --cov=openhands --cov-report=xml -svv ./tests/unit --ignore=tests/unit/test_memory.py - name: Upload coverage to Codecov uses: codecov/codecov-action@v4 env: diff --git a/README.md b/README.md index 7396099de859..141420021bac 100644 --- a/README.md +++ b/README.md @@ -29,6 +29,11 @@ call APIs, and yes—even copy code snippets from StackOverflow. Learn more at [docs.all-hands.dev](https://docs.all-hands.dev), or jump to the [Quick Start](#-quick-start). +> [!IMPORTANT] +> Using OpenHands for work? We'd love to chat! Fill out +> [this short form](https://docs.google.com/forms/d/e/1FAIpQLSet3VbGaz8z32gW9Wm-Grl4jpt5WgMXPgJ4EDPVmCETCBpJtQ/viewform) +> to join our Design Partner program, where you'll get early access to commercial features and the opportunity to provide input on our product roadmap. + ![App screenshot](./docs/static/img/screenshot.png) ## ⚡ Quick Start @@ -40,10 +45,11 @@ system requirements and more information. ```bash docker pull docker.all-hands.dev/all-hands-ai/runtime:0.15-nikolaik -docker run -it --pull=always \ +docker run -it --rm --pull=always \ -e SANDBOX_RUNTIME_CONTAINER_IMAGE=docker.all-hands.dev/all-hands-ai/runtime:0.15-nikolaik \ -e LOG_ALL_EVENTS=true \ -v /var/run/docker.sock:/var/run/docker.sock \ + -v ~/.openhands:/home/openhands/.openhands \ -p 3000:3000 \ --add-host host.docker.internal:host-gateway \ --name openhands-app \ diff --git a/config.template.toml b/config.template.toml index d19ff6085e3b..6f626e6bee90 100644 --- a/config.template.toml +++ b/config.template.toml @@ -95,10 +95,10 @@ workspace_base = "./workspace" # AWS secret access key #aws_secret_access_key = "" -# API key to use +# API key to use (For Headless / CLI only - In Web this is overridden by Session Init) api_key = "your-api-key" -# API base URL +# API base URL (For Headless / CLI only - In Web this is overridden by Session Init) #base_url = "" # API version @@ -131,7 +131,7 @@ embedding_model = "local" # Maximum number of output tokens #max_output_tokens = 0 -# Model to use +# Model to use. (For Headless / CLI only - In Web this is overridden by Session Init) model = "gpt-4o" # Number of retries to attempt when an operation fails with the LLM. @@ -217,6 +217,9 @@ llm_config = 'gpt3' # Use host network #use_host_network = false +# runtime extra build args +#runtime_extra_build_args = ["--network=host", "--add-host=host.docker.internal:host-gateway"] + # Enable auto linting after editing #enable_auto_lint = false @@ -237,10 +240,10 @@ llm_config = 'gpt3' ############################################################################## [security] -# Enable confirmation mode +# Enable confirmation mode (For Headless / CLI only - In Web this is overridden by Session Init) #confirmation_mode = false -# The security analyzer to use +# The security analyzer to use (For Headless / CLI only - In Web this is overridden by Session Init) #security_analyzer = "" #################################### Eval #################################### diff --git a/containers/app/Dockerfile b/containers/app/Dockerfile index 266a9d6b3e40..67753cbe2c2d 100644 --- a/containers/app/Dockerfile +++ b/containers/app/Dockerfile @@ -42,6 +42,8 @@ ENV USE_HOST_NETWORK=false ENV WORKSPACE_BASE=/opt/workspace_base ENV OPENHANDS_BUILD_VERSION=$OPENHANDS_BUILD_VERSION ENV SANDBOX_USER_ID=0 +ENV FILE_STORE=local +ENV FILE_STORE_PATH=~/.openhands RUN mkdir -p $WORKSPACE_BASE RUN apt-get update -y \ diff --git a/containers/dev/README.md b/containers/dev/README.md index ed45e0c3a5ed..0fb1bbc3b38d 100644 --- a/containers/dev/README.md +++ b/containers/dev/README.md @@ -1,5 +1,8 @@ # Develop in Docker +> [!WARNING] +> This is not officially supported and may not work. + Install [Docker](https://docs.docker.com/engine/install/) on your host machine and run: ```bash diff --git a/docs/i18n/fr/docusaurus-plugin-content-docs/current/usage/troubleshooting/troubleshooting.md b/docs/i18n/fr/docusaurus-plugin-content-docs/current/usage/troubleshooting/troubleshooting.md index 96e8bd58c09d..2731b1990483 100644 --- a/docs/i18n/fr/docusaurus-plugin-content-docs/current/usage/troubleshooting/troubleshooting.md +++ b/docs/i18n/fr/docusaurus-plugin-content-docs/current/usage/troubleshooting/troubleshooting.md @@ -9,7 +9,6 @@ Si vous trouvez plus d'informations ou une solution de contournement pour l'un d :::tip OpenHands ne prend en charge Windows que via [WSL](https://learn.microsoft.com/en-us/windows/wsl/install). Veuillez vous assurer d'exécuter toutes les commandes à l'intérieur de votre terminal WSL. -Consultez les [Notes pour les utilisateurs de WSL sur Windows](troubleshooting/windows) pour des guides de dépannage. ::: ## Problèmes courants diff --git a/docs/i18n/fr/docusaurus-plugin-content-docs/current/usage/troubleshooting/windows.md b/docs/i18n/fr/docusaurus-plugin-content-docs/current/usage/troubleshooting/windows.md deleted file mode 100644 index 467f9deb7624..000000000000 --- a/docs/i18n/fr/docusaurus-plugin-content-docs/current/usage/troubleshooting/windows.md +++ /dev/null @@ -1,66 +0,0 @@ - - -# Notes pour les utilisateurs de WSL sur Windows - -OpenHands ne prend en charge Windows que via [WSL](https://learn.microsoft.com/en-us/windows/wsl/install). -Veuillez vous assurer d'exécuter toutes les commandes dans votre terminal WSL. - -## Dépannage - -### Recommandation : Ne pas exécuter en tant qu'utilisateur root - -Pour des raisons de sécurité, il est fortement recommandé de ne pas exécuter OpenHands en tant qu'utilisateur root, mais en tant qu'utilisateur avec un UID non nul. - -Références : - -* [Pourquoi il est mauvais de se connecter en tant que root](https://askubuntu.com/questions/16178/why-is-it-bad-to-log-in-as-root) -* [Définir l'utilisateur par défaut dans WSL](https://www.tenforums.com/tutorials/128152-set-default-user-windows-subsystem-linux-distro-windows-10-a.html#option2) -Astuce concernant la 2ème référence : pour les utilisateurs d'Ubuntu, la commande pourrait en fait être "ubuntupreview" au lieu de "ubuntu". - ---- -### Erreur : 'docker' n'a pas pu être trouvé dans cette distribution WSL 2. - -Si vous utilisez Docker Desktop, assurez-vous de le démarrer avant d'appeler toute commande docker depuis WSL. -Docker doit également avoir l'option d'intégration WSL activée. - ---- -### Installation de Poetry - -* Si vous rencontrez des problèmes pour exécuter Poetry même après l'avoir installé pendant le processus de build, vous devrez peut-être ajouter son chemin binaire à votre environnement : - -```sh -export PATH="$HOME/.local/bin:$PATH" -``` - -* Si make build s'arrête sur une erreur comme celle-ci : - -```sh -ModuleNotFoundError: no module named -``` - -Cela pourrait être un problème avec le cache de Poetry. -Essayez d'exécuter ces 2 commandes l'une après l'autre : - -```sh -rm -r ~/.cache/pypoetry -make build -``` - ---- -### L'objet NoneType n'a pas d'attribut 'request' - -Si vous rencontrez des problèmes liés au réseau, tels que `NoneType object has no attribute 'request'` lors de l'exécution de `make run`, vous devrez peut-être configurer les paramètres réseau de WSL2. Suivez ces étapes : - -* Ouvrez ou créez le fichier `.wslconfig` situé à `C:\Users\%username%\.wslconfig` sur votre machine hôte Windows. -* Ajoutez la configuration suivante au fichier `.wslconfig` : - -```sh -[wsl2] -networkingMode=mirrored -localhostForwarding=true -``` - -* Enregistrez le fichier `.wslconfig`. -* Redémarrez complètement WSL2 en quittant toutes les instances WSL2 en cours d'exécution et en exécutant la commande `wsl --shutdown` dans votre invite de commande ou terminal. -* Après avoir redémarré WSL, essayez d'exécuter à nouveau `make run`. -Le problème de réseau devrait être résolu. diff --git a/docs/i18n/zh-Hans/docusaurus-plugin-content-docs/current/usage/troubleshooting/troubleshooting.md b/docs/i18n/zh-Hans/docusaurus-plugin-content-docs/current/usage/troubleshooting/troubleshooting.md index 30daa5e768de..21514a594e19 100644 --- a/docs/i18n/zh-Hans/docusaurus-plugin-content-docs/current/usage/troubleshooting/troubleshooting.md +++ b/docs/i18n/zh-Hans/docusaurus-plugin-content-docs/current/usage/troubleshooting/troubleshooting.md @@ -7,7 +7,6 @@ :::tip OpenHands 仅通过 [WSL](https://learn.microsoft.com/en-us/windows/wsl/install) 支持 Windows。 请确保在您的 WSL 终端内运行所有命令。 -查看 [Windows 用户的 WSL 注意事项](troubleshooting/windows) 以获取一些故障排除指南。 ::: ## 常见问题 diff --git a/docs/i18n/zh-Hans/docusaurus-plugin-content-docs/current/usage/troubleshooting/windows.md b/docs/i18n/zh-Hans/docusaurus-plugin-content-docs/current/usage/troubleshooting/windows.md deleted file mode 100644 index cb59ba2aee01..000000000000 --- a/docs/i18n/zh-Hans/docusaurus-plugin-content-docs/current/usage/troubleshooting/windows.md +++ /dev/null @@ -1,66 +0,0 @@ -以下是翻译后的内容: - -# 针对 Windows 上 WSL 用户的注意事项 - -OpenHands 仅通过 [WSL](https://learn.microsoft.com/en-us/windows/wsl/install) 支持 Windows。 -请确保在您的 WSL 终端内运行所有命令。 - -## 故障排除 - -### 建议: 不要以 root 用户身份运行 - -出于安全原因,强烈建议不要以 root 用户身份运行 OpenHands,而是以具有非零 UID 的用户身份运行。 - -参考: - -* [为什么以 root 身份登录不好](https://askubuntu.com/questions/16178/why-is-it-bad-to-log-in-as-root) -* [在 WSL 中设置默认用户](https://www.tenforums.com/tutorials/128152-set-default-user-windows-subsystem-linux-distro-windows-10-a.html#option2) -关于第二个参考的提示:对于 Ubuntu 用户,命令实际上可能是 "ubuntupreview" 而不是 "ubuntu"。 - ---- -### 错误: 在此 WSL 2 发行版中找不到 'docker'。 - -如果您正在使用 Docker Desktop,请确保在从 WSL 内部调用任何 docker 命令之前启动它。 -Docker 还需要激活 WSL 集成选项。 - ---- -### Poetry 安装 - -* 如果您在构建过程中安装 Poetry 后仍然面临运行 Poetry 的问题,您可能需要将其二进制路径添加到环境中: - -```sh -export PATH="$HOME/.local/bin:$PATH" -``` - -* 如果 make build 在如下错误上停止: - -```sh -ModuleNotFoundError: no module named -``` - -这可能是 Poetry 缓存的问题。 -尝试依次运行这两个命令: - -```sh -rm -r ~/.cache/pypoetry -make build -``` - ---- -### NoneType 对象没有属性 'request' - -如果您在执行 `make run` 时遇到与网络相关的问题,例如 `NoneType 对象没有属性 'request'`,您可能需要配置 WSL2 网络设置。请按照以下步骤操作: - -* 在 Windows 主机上打开或创建位于 `C:\Users\%username%\.wslconfig` 的 `.wslconfig` 文件。 -* 将以下配置添加到 `.wslconfig` 文件中: - -```sh -[wsl2] -networkingMode=mirrored -localhostForwarding=true -``` - -* 保存 `.wslconfig` 文件。 -* 通过退出任何正在运行的 WSL2 实例并在命令提示符或终端中执行 `wsl --shutdown` 命令来完全重启 WSL2。 -* 重新启动 WSL 后,再次尝试执行 `make run`。 -网络问题应该得到解决。 diff --git a/docs/modules/usage/how-to/gui-mode.md b/docs/modules/usage/how-to/gui-mode.md index df5a070c01e5..f32e1acfe679 100644 --- a/docs/modules/usage/how-to/gui-mode.md +++ b/docs/modules/usage/how-to/gui-mode.md @@ -23,10 +23,75 @@ OpenHands provides a user-friendly Graphical User Interface (GUI) mode for inter OpenHands automatically exports a `GITHUB_TOKEN` to the shell environment if it is available. This can happen in two ways: -1. Locally (OSS): The user directly inputs their GitHub token. -2. Online (SaaS): The token is obtained through GitHub OAuth authentication. - -When you reach the `/app` route, the app checks if a token is present. If it finds one, it sets it in the environment for the agent to use. +1. **Locally (OSS)**: The user directly inputs their GitHub token +2. **Online (SaaS)**: The token is obtained through GitHub OAuth authentication + +#### Setting Up a Local GitHub Token + +1. **Generate a Personal Access Token (PAT)**: + - Go to GitHub Settings > Developer Settings > Personal Access Tokens > Tokens (classic) + - Click "Generate new token (classic)" + - Required scopes: + - `repo` (Full control of private repositories) + - `workflow` (Update GitHub Action workflows) + - `read:org` (Read organization data) + +2. **Enter Token in OpenHands**: + - Click the Settings button (gear icon) in the top right + - Navigate to the "GitHub" section + - Paste your token in the "GitHub Token" field + - Click "Save" to apply the changes + +#### Organizational Token Policies + +If you're working with organizational repositories, additional setup may be required: + +1. **Check Organization Requirements**: + - Organization admins may enforce specific token policies + - Some organizations require tokens to be created with SSO enabled + - Review your organization's [token policy settings](https://docs.github.com/en/organizations/managing-programmatic-access-to-your-organization/setting-a-personal-access-token-policy-for-your-organization) + +2. **Verify Organization Access**: + - Go to your token settings on GitHub + - Look for the organization under "Organization access" + - If required, click "Enable SSO" next to your organization + - Complete the SSO authorization process + +#### OAuth Authentication (Online Mode) + +When using OpenHands in online mode, the GitHub OAuth flow: + +1. Requests the following permissions: + - Repository access (read/write) + - Workflow management + - Organization read access + +2. Authentication steps: + - Click "Sign in with GitHub" when prompted + - Review the requested permissions + - Authorize OpenHands to access your GitHub account + - If using an organization, authorize organization access if prompted + +#### Troubleshooting + +Common issues and solutions: + +1. **Token Not Recognized**: + - Ensure the token is properly saved in settings + - Check that the token hasn't expired + - Verify the token has the required scopes + - Try regenerating the token + +2. **Organization Access Denied**: + - Check if SSO is required but not enabled + - Verify organization membership + - Contact organization admin if token policies are blocking access + +3. **Verifying Token Works**: + - The app will show a green checkmark if the token is valid + - Try accessing a repository to confirm permissions + - Check the browser console for any error messages + - Use the "Test Connection" button in settings if available ### Advanced Settings diff --git a/docs/modules/usage/how-to/headless-mode.md b/docs/modules/usage/how-to/headless-mode.md index dfd4dd5e3e14..ff5e622de6a4 100644 --- a/docs/modules/usage/how-to/headless-mode.md +++ b/docs/modules/usage/how-to/headless-mode.md @@ -55,5 +55,5 @@ docker run -it \ --add-host host.docker.internal:host-gateway \ --name openhands-app-$(date +%Y%m%d%H%M%S) \ docker.all-hands.dev/all-hands-ai/openhands:0.15 \ - python -m openhands.core.main -t "write a bash script that prints hi" + python -m openhands.core.main -t "write a bash script that prints hi" --no-auto-continue ``` diff --git a/docs/modules/usage/how-to/persist-session-data.md b/docs/modules/usage/how-to/persist-session-data.md new file mode 100644 index 000000000000..f079531498fe --- /dev/null +++ b/docs/modules/usage/how-to/persist-session-data.md @@ -0,0 +1,16 @@ +# Persisting Session Data + +Using the standard installation, the session data is stored in memory. Currently, if OpenHands' service is restarted, +previous sessions become invalid (a new secret is generated) and thus not recoverable. + +## How to Persist Session Data + +### Development Workflow +In the `config.toml` file, specify the following: +``` +[core] +... +file_store="local" +file_store_path="/absolute/path/to/openhands/cache/directory" +jwt_secret="secretpass" +``` diff --git a/docs/modules/usage/micro-agents.md b/docs/modules/usage/micro-agents.md new file mode 100644 index 000000000000..4bdf69413698 --- /dev/null +++ b/docs/modules/usage/micro-agents.md @@ -0,0 +1,213 @@ +# Micro-Agents + +OpenHands uses specialized micro-agents to handle specific tasks and contexts efficiently. These micro-agents are small, focused components that provide specialized behavior and knowledge for particular scenarios. + +## Overview + +Micro-agents are defined in markdown files under the `openhands/agenthub/codeact_agent/micro/` directory. Each micro-agent is configured with: + +- A unique name +- The agent type (typically CodeActAgent) +- Trigger keywords that activate the agent +- Specific instructions and capabilities + +## Available Micro-Agents + +### GitHub Agent +**File**: `github.md` +**Triggers**: `github`, `git` + +The GitHub agent specializes in GitHub API interactions and repository management. It: +- Has access to a `GITHUB_TOKEN` for API authentication +- Follows strict guidelines for repository interactions +- Handles branch management and pull requests +- Uses the GitHub API instead of web browser interactions + +Key features: +- Branch protection (prevents direct pushes to main/master) +- Automated PR creation +- Git configuration management +- API-first approach for GitHub operations + +### NPM Agent +**File**: `npm.md` +**Triggers**: `npm` + +Specializes in handling npm package management with specific focus on: +- Non-interactive shell operations +- Automated confirmation handling using Unix 'yes' command +- Package installation automation + +### Custom Micro-Agents + +You can create your own micro-agents by adding new markdown files to the micro-agents directory. Each file should follow this structure: + +```markdown +--- +name: agent_name +agent: CodeActAgent +triggers: +- trigger_word1 +- trigger_word2 +--- + +Instructions and capabilities for the micro-agent... +``` + +## Best Practices + +When working with micro-agents: + +1. **Use Appropriate Triggers**: Ensure your commands include the relevant trigger words to activate the correct micro-agent +2. **Follow Agent Guidelines**: Each agent has specific instructions and limitations - respect these for optimal results +3. **API-First Approach**: When available, use API endpoints rather than web interfaces +4. **Automation Friendly**: Design commands that work well in non-interactive environments + +## Integration + +Micro-agents are automatically integrated into OpenHands' workflow. They: +- Monitor incoming commands for their trigger words +- Activate when relevant triggers are detected +- Apply their specialized knowledge and capabilities +- Follow their specific guidelines and restrictions + +## Example Usage + +```bash +# GitHub agent example +git checkout -b feature-branch +git commit -m "Add new feature" +git push origin feature-branch + +# NPM agent example +yes | npm install package-name +``` + +For more information about specific agents, refer to their individual documentation files in the micro-agents directory. + +## Contributing a Micro-Agent + +To contribute a new micro-agent to OpenHands, follow these guidelines: + +### 1. Planning Your Micro-Agent + +Before creating a micro-agent, consider: +- What specific problem or use case will it address? +- What unique capabilities or knowledge should it have? +- What trigger words make sense for activating it? +- What constraints or guidelines should it follow? + +### 2. File Structure + +Create a new markdown file in `openhands/agenthub/codeact_agent/micro/` with a descriptive name (e.g., `docker.md` for a Docker-focused agent). + +### 3. Required Components + +Your micro-agent file must include: + +1. **Front Matter**: YAML metadata at the start of the file: +```markdown +--- +name: your_agent_name +agent: CodeActAgent +triggers: +- trigger_word1 +- trigger_word2 +--- +``` + +2. **Instructions**: Clear, specific guidelines for the agent's behavior: +```markdown +You are responsible for [specific task/domain]. + +Key responsibilities: +1. [Responsibility 1] +2. [Responsibility 2] + +Guidelines: +- [Guideline 1] +- [Guideline 2] + +Examples of usage: +[Example 1] +[Example 2] +``` + +### 4. Best Practices for Micro-Agent Development + +1. **Clear Scope**: Keep the agent focused on a specific domain or task +2. **Explicit Instructions**: Provide clear, unambiguous guidelines +3. **Useful Examples**: Include practical examples of common use cases +4. **Safety First**: Include necessary warnings and constraints +5. **Integration Awareness**: Consider how the agent interacts with other components + +### 5. Testing Your Micro-Agent + +Before submitting: +1. Test the agent with various prompts +2. Verify trigger words activate the agent correctly +3. Ensure instructions are clear and comprehensive +4. Check for potential conflicts with existing agents + +### 6. Example Implementation + +Here's a template for a new micro-agent: + +```markdown +--- +name: docker +agent: CodeActAgent +triggers: +- docker +- container +--- + +You are responsible for Docker container management and Dockerfile creation. + +Key responsibilities: +1. Create and modify Dockerfiles +2. Manage container lifecycle +3. Handle Docker Compose configurations + +Guidelines: +- Always use official base images when possible +- Include necessary security considerations +- Follow Docker best practices for layer optimization + +Examples: +1. Creating a Dockerfile: + ```dockerfile + FROM node:18-alpine + WORKDIR /app + COPY package*.json ./ + RUN npm install + COPY . . + CMD ["npm", "start"] + ``` + +2. Docker Compose usage: + ```yaml + version: '3' + services: + web: + build: . + ports: + - "3000:3000" + ``` + +Remember to: +- Validate Dockerfile syntax +- Check for security vulnerabilities +- Optimize for build time and image size +``` + +### 7. Submission Process + +1. Create your micro-agent file in the correct directory +2. Test thoroughly +3. Submit a pull request with: + - The new micro-agent file + - Updated documentation if needed + - Description of the agent's purpose and capabilities + +Remember that micro-agents are a powerful way to extend OpenHands' capabilities in specific domains. Well-designed agents can significantly improve the system's ability to handle specialized tasks. diff --git a/docs/modules/usage/prompting-best-practices.md b/docs/modules/usage/prompting-best-practices.md index 9df608a7a2fa..0d89592165cb 100644 --- a/docs/modules/usage/prompting-best-practices.md +++ b/docs/modules/usage/prompting-best-practices.md @@ -2,6 +2,11 @@ When working with OpenHands AI software developer, it's crucial to provide clear and effective prompts. This guide outlines best practices for creating prompts that will yield the most accurate and useful responses. +## Table of Contents + +- [Characteristics of Good Prompts](#characteristics-of-good-prompts) +- [Customizing Prompts for your Project](#customizing-prompts-for-your-project) + ## Characteristics of Good Prompts Good prompts are: @@ -39,3 +44,63 @@ Good prompts are: Remember, the more precise and informative your prompt is, the better the AI can assist you in developing or modifying the OpenHands software. See [Getting Started with OpenHands](./getting-started) for more examples of helpful prompts. + +## Customizing Prompts for your Project + +OpenHands can be customized to work more effectively with specific repositories by providing repository-specific context and guidelines. This section explains how to optimize OpenHands for your project. + +### Repository Configuration + +You can customize OpenHands' behavior for your repository by creating a `.openhands_instructions` file in your repository's root directory. This file should contain: + +1. **Repository Overview**: A brief description of your project's purpose and architecture +2. **Directory Structure**: Key directories and their purposes +3. **Development Guidelines**: Project-specific coding standards and practices +4. **Testing Requirements**: How to run tests and what types of tests are required +5. **Setup Instructions**: Steps needed to build and run the project + +Example `.openhands_instructions` file: +``` +Repository: MyProject +Description: A web application for task management + +Directory Structure: +- src/: Main application code +- tests/: Test files +- docs/: Documentation + +Setup: +- Run `npm install` to install dependencies +- Use `npm run dev` for development +- Run `npm test` for testing + +Guidelines: +- Follow ESLint configuration +- Write tests for all new features +- Use TypeScript for new code +``` + +### Customizing Prompts + +When working with a customized repository: + +1. **Reference Project Standards**: Mention specific coding standards or patterns used in your project +2. **Include Context**: Reference relevant documentation or existing implementations +3. **Specify Testing Requirements**: Include project-specific testing requirements in your prompts + +Example customized prompt: +``` +Add a new task completion feature to src/components/TaskList.tsx following our existing component patterns. +Include unit tests in tests/components/ and update the documentation in docs/features/. +The component should use our shared styling from src/styles/components. +``` + +### Best Practices for Repository Customization + +1. **Keep Instructions Updated**: Regularly update your `.openhands_instructions` file as your project evolves +2. **Be Specific**: Include specific paths, patterns, and requirements unique to your project +3. **Document Dependencies**: List all tools and dependencies required for development +4. **Include Examples**: Provide examples of good code patterns from your project +5. **Specify Conventions**: Document naming conventions, file organization, and code style preferences + +By customizing OpenHands for your repository, you'll get more accurate and consistent results that align with your project's standards and requirements. diff --git a/docs/modules/usage/troubleshooting/troubleshooting.md b/docs/modules/usage/troubleshooting/troubleshooting.md index e031e65b4623..b117411b51d7 100644 --- a/docs/modules/usage/troubleshooting/troubleshooting.md +++ b/docs/modules/usage/troubleshooting/troubleshooting.md @@ -1,180 +1,44 @@ # 🚧 Troubleshooting -There are some error messages that frequently get reported by users. -We'll try to make the install process easier, but for now you can look for your error message below and see if there are any workarounds. -If you find more information or a workaround for one of these issues, please open a *PR* to add details to this file. - :::tip -OpenHands only supports Windows via [WSL](https://learn.microsoft.com/en-us/windows/wsl/install). -Please be sure to run all commands inside your WSL terminal. -Check out [Notes for WSL on Windows Users](troubleshooting/windows) for some troubleshooting guides. +OpenHands only supports Windows via WSL. Please be sure to run all commands inside your WSL terminal. ::: -## Common Issues - -* [Unable to connect to Docker](#unable-to-connect-to-docker) -* [404 Resource not found](#404-resource-not-found) -* [`make build` getting stuck on package installations](#make-build-getting-stuck-on-package-installations) -* [Sessions are not restored](#sessions-are-not-restored) -* [Connection to host.docker.internal timed out](#connection-to-host-docker-internal-timed-out) - -### Unable to connect to Docker - -[GitHub Issue](https://github.com/All-Hands-AI/OpenHands/issues/1226) - -**Symptoms** - -```bash -Error creating controller. Please check Docker is running and visit `https://docs.all-hands.dev/modules/usage/troubleshooting` for more debugging information. -``` - -```bash -docker.errors.DockerException: Error while fetching server API version: ('Connection aborted.', FileNotFoundError(2, 'No such file or directory')) -``` - -**Details** - -OpenHands uses a Docker container to do its work safely, without potentially breaking your machine. +### Launch docker client failed -**Workarounds** +**Description** -* Run `docker ps` to ensure that docker is running -* Make sure you don't need `sudo` to run docker [see here](https://www.baeldung.com/linux/docker-run-without-sudo) -* If you are on a Mac, check the [permissions requirements](https://docs.docker.com/desktop/mac/permission-requirements/) and in particular consider enabling the `Allow the default Docker socket to be used` under `Settings > Advanced` in Docker Desktop. -* In addition, upgrade your Docker to the latest version under `Check for Updates` - ---- -### `404 Resource not found` - -**Symptoms** - -```python -Traceback (most recent call last): - File "/app/.venv/lib/python3.12/site-packages/litellm/llms/openai.py", line 414, in completion - raise e - File "/app/.venv/lib/python3.12/site-packages/litellm/llms/openai.py", line 373, in completion - response = openai_client.chat.completions.create(**data, timeout=timeout) # type: ignore - ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - File "/app/.venv/lib/python3.12/site-packages/openai/_utils/_utils.py", line 277, in wrapper - return func(*args, **kwargs) - ^^^^^^^^^^^^^^^^^^^^^ - File "/app/.venv/lib/python3.12/site-packages/openai/resources/chat/completions.py", line 579, in create - return self._post( - ^^^^^^^^^^^ - File "/app/.venv/lib/python3.12/site-packages/openai/_base_client.py", line 1232, in post - return cast(ResponseT, self.request(cast_to, opts, stream=stream, stream_cls=stream_cls)) - ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - File "/app/.venv/lib/python3.12/site-packages/openai/_base_client.py", line 921, in request - return self._request( - ^^^^^^^^^^^^^^ - File "/app/.venv/lib/python3.12/site-packages/openai/_base_client.py", line 1012, in _request - raise self._make_status_error_from_response(err.response) from None -openai.NotFoundError: Error code: 404 - {'error': {'code': '404', 'message': 'Resource not found'}} +When running OpenHands, the following error is seen: ``` - -**Details** - -This happens when LiteLLM (our library for connecting to different LLM providers) can't find -the API endpoint you're trying to connect to. Most often this happens for Azure or ollama users. - -**Workarounds** - -* Check that you've set `LLM_BASE_URL` properly -* Check that the model is set properly, based on the [LiteLLM docs](https://docs.litellm.ai/docs/providers) - * If you're running inside the UI, be sure to set the `model` in the settings modal - * If you're running headless (via main.py) be sure to set `LLM_MODEL` in your env/config -* Make sure you've followed any special instructions for your LLM provider - * [Azure](/modules/usage/llms/azure-llms) - * [Google](/modules/usage/llms/google-llms) -* Make sure your API key is correct -* See if you can connect to the LLM using `curl` -* Try [connecting via LiteLLM directly](https://github.com/BerriAI/litellm) to test your setup - ---- -### `make build` getting stuck on package installations - -**Symptoms** - -Package installation stuck on `Pending...` without any error message: - -```bash -Package operations: 286 installs, 0 updates, 0 removals - - - Installing certifi (2024.2.2): Pending... - - Installing h11 (0.14.0): Pending... - - Installing idna (3.7): Pending... - - Installing sniffio (1.3.1): Pending... - - Installing typing-extensions (4.11.0): Pending... +Launch docker client failed. Please make sure you have installed docker and started docker desktop/daemon. ``` -**Details** - -In rare cases, `make build` can seemingly get stuck on package installations -without any error message. - -**Workarounds** - -The package installer Poetry may miss a configuration setting for where credentials are to be looked up (keyring). - -First check with `env` if a value for `PYTHON_KEYRING_BACKEND` exists. -If not, run the below command to set it to a known value and retry the build: - -```bash -export PYTHON_KEYRING_BACKEND=keyring.backends.null.Keyring -``` +**Resolution** +Try these in order: +* Confirm `docker` is running on your system. You should be able to run `docker ps` in the terminal successfully. +* If using Docker Desktop, ensure `Settings > Advanced > Allow the default Docker socket to be used` is enabled. +* Depending on your configuration you may need `Settings > Resources > Network > Enable host networking` enabled in Docker Desktop. +* Reinstall Docker Desktop. --- -### Sessions are not restored - -**Symptoms** - -OpenHands usually asks whether to resume or start a new session when opening the UI. -But clicking "Resume" still starts a fresh new chat. -**Details** +# Development Workflow Specific +### Error building runtime docker image -With a standard installation as of today session data is stored in memory. -Currently, if OpenHands's service is restarted, previous sessions become -invalid (a new secret is generated) and thus not recoverable. +**Description** -**Workarounds** - -* Change configuration to make sessions persistent by editing the `config.toml` -file (in OpenHands's root folder) by specifying a `file_store` and an -absolute `file_store_path`: - -```toml -file_store="local" -file_store_path="/absolute/path/to/openhands/cache/directory" +Attempts to start a new session fail, and errors with terms like the following appear in the logs: ``` - -* Add a fixed jwt secret in your .bashrc, like below, so that previous session id's -should stay accepted. - -```bash -EXPORT JWT_SECRET=A_CONST_VALUE +debian-security bookworm-security +InRelease At least one invalid signature was encountered. ``` ---- -### Connection to host docker internal timed out - -**Symptoms** - -When you start the server using the docker command from the main [README](https://github.com/All-Hands-AI/OpenHands/README.md), you get a long timeout -followed by the a stack trace containing messages like: - -* `Connection to host.docker.internal timed out. (connect timeout=310)` -* `Max retries exceeded with url: /alive` - -**Details** - -If Docker Engine is installed rather than Docker Desktop, the main command will not work as expected. -Docker Desktop includes easy DNS configuration for connecting processes running in different containers -which OpenHands makes use of when the main server is running inside a docker container. -(Further details: https://forums.docker.com/t/difference-between-docker-desktop-and-docker-engine/124612) - -**Workarounds** +This seems to happen when the hash of an existing external library changes and your local docker instance has +cached a previous version. To work around this, please try the following: -* [Install Docker Desktop](https://www.docker.com/products/docker-desktop/) -* Run OpenHands in [Development Mode](https://github.com/All-Hands-AI/OpenHands/blob/main/Development.md), - So that the main server is not run inside a container, but still creates dockerized runtime sandboxes. +* Stop any containers where the name has the prefix `openhands-runtime-` : + `docker ps --filter name=openhands-runtime- --filter status=running -aq | xargs docker stop` +* Remove any containers where the name has the prefix `openhands-runtime-` : + `docker rmi $(docker images --filter name=openhands-runtime- -q --no-trunc)` +* Stop and Remove any containers / images where the name has the prefix `openhands-runtime-` +* Prune containers / images : `docker container prune -f && docker image prune -f` diff --git a/docs/modules/usage/troubleshooting/windows.md b/docs/modules/usage/troubleshooting/windows.md deleted file mode 100644 index c0196b75138b..000000000000 --- a/docs/modules/usage/troubleshooting/windows.md +++ /dev/null @@ -1,64 +0,0 @@ -# Notes for WSL on Windows Users - -OpenHands only supports Windows via [WSL](https://learn.microsoft.com/en-us/windows/wsl/install). -Please be sure to run all commands inside your WSL terminal. - -## Troubleshooting - -### Recommendation: Do not run as root user - -For security reasons, it is highly recommended to not run OpenHands as the root user, but a user with a non-zero UID. - -References: - -* [Why it is bad to login as root](https://askubuntu.com/questions/16178/why-is-it-bad-to-log-in-as-root) -* [Set default user in WSL](https://www.tenforums.com/tutorials/128152-set-default-user-windows-subsystem-linux-distro-windows-10-a.html#option2) -Hint about the 2nd reference: for Ubuntu users, the command could actually be "ubuntupreview" instead of "ubuntu". - ---- -### Error: 'docker' could not be found in this WSL 2 distro. - -If you are using Docker Desktop, make sure to start it before calling any docker command from inside WSL. -Docker also needs to have the WSL integration option activated. - ---- -### Poetry Installation - -* If you face issues running Poetry even after installing it during the build process, you may need to add its binary path to your environment: - -```sh -export PATH="$HOME/.local/bin:$PATH" -``` - -* If make build stops on an error like this: - -```sh -ModuleNotFoundError: no module named -``` - -This could be an issue with Poetry's cache. -Try to run these 2 commands after another: - -```sh -rm -r ~/.cache/pypoetry -make build -``` - ---- -### NoneType object has no attribute 'request' - -If you are experiencing issues related to networking, such as `NoneType object has no attribute 'request'` when executing `make run`, you may need to configure your WSL2 networking settings. Follow these steps: - -* Open or create the `.wslconfig` file located at `C:\Users\%username%\.wslconfig` on your Windows host machine. -* Add the following configuration to the `.wslconfig` file: - -```sh -[wsl2] -networkingMode=mirrored -localhostForwarding=true -``` - -* Save the `.wslconfig` file. -* Restart WSL2 completely by exiting any running WSL2 instances and executing the command `wsl --shutdown` in your command prompt or terminal. -* After restarting WSL, attempt to execute `make run` again. -The networking issue should be resolved. diff --git a/docs/modules/usage/upgrade-guide.md b/docs/modules/usage/upgrade-guide.md deleted file mode 100644 index 01e68d558b5f..000000000000 --- a/docs/modules/usage/upgrade-guide.md +++ /dev/null @@ -1,71 +0,0 @@ -# ⬆️ Upgrade Guide - -## 0.8.0 (2024-07-13) - -### Config breaking changes - -In this release we introduced a few breaking changes to backend configurations. -If you have only been using OpenHands via frontend (web GUI), nothing needs -to be taken care of. - -Here's a list of breaking changes in configs. They only apply to users who -use OpenHands CLI via `main.py`. For more detail, see [#2756](https://github.com/All-Hands-AI/OpenHands/pull/2756). - -#### Removal of --model-name option from main.py - -Please note that `--model-name`, or `-m` option, no longer exists. You should set up the LLM -configs in `config.toml` or via environmental variables. - -#### LLM config groups must be subgroups of 'llm' - -Prior to release 0.8, you can use arbitrary name for llm config in `config.toml`, e.g. - -```toml -[gpt-4o] -model="gpt-4o" -api_key="" -``` - -and then use `--llm-config` CLI argument to specify the desired LLM config group -by name. This no longer works. Instead, the config group must be under `llm` group, -e.g.: - -```toml -[llm.gpt-4o] -model="gpt-4o" -api_key="" -``` - -If you have a config group named `llm`, no need to change it, it will be used -as the default LLM config group. - -#### 'agent' group no longer contains 'name' field - -Prior to release 0.8, you may or may not have a config group named `agent` that -looks like this: - -```toml -[agent] -name="CodeActAgent" -memory_max_threads=2 -``` - -Note the `name` field is now removed. Instead, you should put `default_agent` field -under `core` group, e.g. - -```toml -[core] -# other configs -default_agent='CodeActAgent' - -[agent] -llm_config='llm' -memory_max_threads=2 - -[agent.CodeActAgent] -llm_config='gpt-4o' -``` - -Note that similar to `llm` subgroups, you can also define `agent` subgroups. -Moreover, an agent can be associated with a specific LLM config group. For more -detail, see the examples in `config.template.toml`. diff --git a/docs/package-lock.json b/docs/package-lock.json index 1cdb00ab818e..d83acb021786 100644 --- a/docs/package-lock.json +++ b/docs/package-lock.json @@ -17,8 +17,8 @@ "prism-react-renderer": "^2.4.0", "react": "^18.3.1", "react-dom": "^18.3.1", - "react-icons": "^5.3.0", - "react-use": "^17.5.1" + "react-icons": "^5.4.0", + "react-use": "^17.6.0" }, "devDependencies": { "@docusaurus/module-type-aliases": "^3.5.1", @@ -15155,9 +15155,10 @@ } }, "node_modules/react-icons": { - "version": "5.3.0", - "resolved": "https://registry.npmjs.org/react-icons/-/react-icons-5.3.0.tgz", - "integrity": "sha512-DnUk8aFbTyQPSkCfF8dbX6kQjXA9DktMeJqfjrg6cK9vwQVMxmcA3BfP4QoiztVmEHtwlTgLFsPuH2NskKT6eg==", + "version": "5.4.0", + "resolved": "https://registry.npmjs.org/react-icons/-/react-icons-5.4.0.tgz", + "integrity": "sha512-7eltJxgVt7X64oHh6wSWNwwbKTCtMfK35hcjvJS0yxEAhPM8oUKdS3+kqaW1vicIltw+kR2unHaa12S9pPALoQ==", + "license": "MIT", "peerDependencies": { "react": "*" } @@ -15263,9 +15264,9 @@ } }, "node_modules/react-use": { - "version": "17.5.1", - "resolved": "https://registry.npmjs.org/react-use/-/react-use-17.5.1.tgz", - "integrity": "sha512-LG/uPEVRflLWMwi3j/sZqR00nF6JGqTTDblkXK2nzXsIvij06hXl1V/MZIlwj1OKIQUtlh1l9jK8gLsRyCQxMg==", + "version": "17.6.0", + "resolved": "https://registry.npmjs.org/react-use/-/react-use-17.6.0.tgz", + "integrity": "sha512-OmedEScUMKFfzn1Ir8dBxiLLSOzhKe/dPZwVxcujweSj45aNM7BEGPb9BEVIgVEqEXx6f3/TsXzwIktNgUR02g==", "dependencies": { "@types/js-cookie": "^2.2.6", "@xobotyi/scrollbar-width": "^1.9.5", diff --git a/docs/package.json b/docs/package.json index 5c5b54d023f4..232898bd88b8 100644 --- a/docs/package.json +++ b/docs/package.json @@ -24,8 +24,8 @@ "prism-react-renderer": "^2.4.0", "react": "^18.3.1", "react-dom": "^18.3.1", - "react-icons": "^5.3.0", - "react-use": "^17.5.1" + "react-icons": "^5.4.0", + "react-use": "^17.6.0" }, "devDependencies": { "@docusaurus/module-type-aliases": "^3.5.1", diff --git a/docs/sidebars.ts b/docs/sidebars.ts index 44f8c7b85037..436bd63e909a 100644 --- a/docs/sidebars.ts +++ b/docs/sidebars.ts @@ -14,9 +14,20 @@ const sidebars: SidebarsConfig = { id: 'usage/getting-started', }, { - type: 'doc', - label: 'Prompting Best Practices', - id: 'usage/prompting-best-practices', + type: 'category', + label: 'Prompting', + items: [ + { + type: 'doc', + label: 'Best Practices', + id: 'usage/prompting-best-practices', + }, + { + type: 'doc', + label: 'Micro-Agents', + id: 'usage/micro-agents', + }, + ], }, { type: 'category', @@ -110,6 +121,11 @@ const sidebars: SidebarsConfig = { label: 'Custom Sandbox', id: 'usage/how-to/custom-sandbox-guide', }, + { + type: 'doc', + label: 'Persist Session Data', + id: 'usage/how-to/persist-session-data', + }, ], }, { diff --git a/evaluation/benchmarks/EDA/README.md b/evaluation/benchmarks/EDA/README.md index fee875c5dd51..11de7ca36e13 100644 --- a/evaluation/benchmarks/EDA/README.md +++ b/evaluation/benchmarks/EDA/README.md @@ -4,12 +4,10 @@ This folder contains evaluation harness for evaluating agents on the Entity-dedu ## Setup Environment and LLM Configuration -Please follow instruction [here](../README.md#setup) to setup your local development environment and LLM. - +Please follow instruction [here](../../README.md#setup) to setup your local development environment and LLM. ## Start the evaluation - ```bash export OPENAI_API_KEY="sk-XXX"; # This is required for evaluation (to simulate another party of conversation) ./evaluation/benchmarks/EDA/scripts/run_infer.sh [model_config] [git-version] [agent] [dataset] [eval_limit] @@ -37,7 +35,8 @@ For example, ``` ## Reference -``` + +```bibtex @inproceedings{zhang2023entity, title={Probing the Multi-turn Planning Capabilities of LLMs via 20 Question Games}, author={Zhang, Yizhe and Lu, Jiarui and Jaitly, Navdeep}, diff --git a/evaluation/benchmarks/agent_bench/README.md b/evaluation/benchmarks/agent_bench/README.md index ea7da04e9f29..9ee8482eb39b 100644 --- a/evaluation/benchmarks/agent_bench/README.md +++ b/evaluation/benchmarks/agent_bench/README.md @@ -4,7 +4,7 @@ This folder contains evaluation harness for evaluating agents on the [AgentBench ## Setup Environment and LLM Configuration -Please follow instruction [here](../README.md#setup) to setup your local development environment and LLM. +Please follow instruction [here](../../README.md#setup) to setup your local development environment and LLM. ## Start the evaluation diff --git a/evaluation/benchmarks/aider_bench/README.md b/evaluation/benchmarks/aider_bench/README.md index 965fc06d7ecc..086cfe58160a 100644 --- a/evaluation/benchmarks/aider_bench/README.md +++ b/evaluation/benchmarks/aider_bench/README.md @@ -10,7 +10,7 @@ Hugging Face dataset based on the ## Setup Environment and LLM Configuration -Please follow instruction [here](../README.md#setup) to setup your local +Please follow instruction [here](../../README.md#setup) to setup your local development environment and LLM. ## Start the evaluation diff --git a/evaluation/benchmarks/biocoder/README.md b/evaluation/benchmarks/biocoder/README.md index 035f2d20bf12..4cd1643fa98f 100644 --- a/evaluation/benchmarks/biocoder/README.md +++ b/evaluation/benchmarks/biocoder/README.md @@ -4,13 +4,14 @@ Implements evaluation of agents on BioCoder from the BioCoder benchmark introduc ## Setup Environment and LLM Configuration -Please follow instruction [here](../README.md#setup) to setup your local development environment and LLM. +Please follow instruction [here](../../README.md#setup) to setup your local development environment and LLM. ## BioCoder Docker Image In the openhands branch of the Biocoder repository, we have slightly modified our original Docker image to work with the OpenHands environment. In the Docker image are testing scripts (`/testing/start_test_openhands.py` and aux files in `/testing_files/`) to assist with evaluation. Additionally, we have installed all dependencies, including OpenJDK, mamba (with Python 3.6), and many system libraries. Notably, we have **not** packaged all repositories into the image, so they are downloaded at runtime. **Before first execution, pull our Docker image with the following command** + ```bash docker pull public.ecr.aws/i5g0m1f6/eval_biocoder:v1.0 ``` @@ -19,7 +20,6 @@ To reproduce this image, please see the Dockerfile_Openopenhands in the `biocode ## Start the evaluation - ```bash ./evaluation/benchmarks/biocoder/scripts/run_infer.sh [model_config] [git-version] [agent] [eval_limit] ``` @@ -47,7 +47,8 @@ with current OpenHands version, then your command would be: ``` ## Reference -``` + +```bibtex @misc{tang2024biocoder, title={BioCoder: A Benchmark for Bioinformatics Code Generation with Large Language Models}, author={Xiangru Tang and Bill Qian and Rick Gao and Jiakang Chen and Xinyun Chen and Mark Gerstein}, diff --git a/evaluation/benchmarks/bird/README.md b/evaluation/benchmarks/bird/README.md index 90e3fa300cbd..41874fe99f59 100644 --- a/evaluation/benchmarks/bird/README.md +++ b/evaluation/benchmarks/bird/README.md @@ -4,7 +4,7 @@ Implements evaluation of agents on BIRD introduced in [Can LLM Already Serve as ## Setup Environment and LLM Configuration -Please follow instruction [here](../README.md#setup) to setup your local development environment and LLM. +Please follow instruction [here](../../README.md#setup) to setup your local development environment and LLM. ## Run Inference on Bird @@ -22,8 +22,7 @@ like to evaluate. It could also be a release tag like `0.6.2`. For each problem, OpenHands is given a set number of iterations to fix the failing code. The history field shows each iteration's response to correct its code that fails any test case. - -``` +```json { "task_id": "0", "instruction": "You are a SQL expert and need to complete the following text-to-SQL tasks.\n\nCREATE TABLE frpm\n(\n CDSCode TEXT not null\n primary key,\n `Academic Year` TEXT null,\n `County Code` TEXT null,\n `District Code` INTEGER null,\n `School Code` TEXT null,\n `County Name` TEXT null,\n `District Name` TEXT null,\n `School Name` TEXT null,\n `District Type` TEXT null,\n `School Type` TEXT null,\n `Educational Option Type` TEXT null,\n `NSLP Provision Status` TEXT null,\n `Charter School (Y/N)` INTEGER null,\n `Charter School Number` TEXT null,\n `Charter Funding Type` TEXT null,\n IRC INTEGER null,\n `Low Grade` TEXT null,\n `High Grade` TEXT null,\n `Enrollment (K-12)` REAL null,\n `Free Meal Count (K-12)` REAL null,\n `Percent (%) Eligible Free (K-12)` REAL null,\n `FRPM Count (K-12)` REAL null,\n `Percent (%) Eligible FRPM (K-12)` REAL null,\n `Enrollment (Ages 5-17)` REAL null,\n `Free Meal Count (Ages 5-17)` REAL null,\n `Percent (%) Eligible Free (Ages 5-17)` REAL null,\n `FRPM Count (Ages 5-17)` REAL null,\n `Percent (%) Eligible FRPM (Ages 5-17)` REAL null,\n `2013-14 CALPADS Fall 1 Certification Status` INTEGER null,\n foreign key (CDSCode) references schools (CDSCode)\n);\n\nCREATE TABLE satscores\n(\n cds TEXT not null\n primary key,\n rtype TEXT not null,\n sname TEXT null,\n dname TEXT null,\n cname TEXT null,\n enroll12 INTEGER not null,\n NumTstTakr INTEGER not null,\n AvgScrRead INTEGER null,\n AvgScrMath INTEGER null,\n AvgScrWrite INTEGER null,\n NumGE1500 INTEGER null,\n-- PctGE1500 double null,\n foreign key (cds) references schools (CDSCode)\n);\n\nCREATE TABLE schools\n(\n CDSCode TEXT not null\n primary key,\n NCESDist TEXT null,\n NCESSchool TEXT null,\n StatusType TEXT not null,\n County TEXT not null,\n District TEXT not null,\n School TEXT null,\n Street TEXT null,\n StreetAbr TEXT null,\n City TEXT null,\n Zip TEXT null,\n State TEXT null,\n MailStreet TEXT null,\n MailStrAbr TEXT null,\n MailCity TEXT null,\n MailZip TEXT null,\n MailState TEXT null,\n Phone TEXT null,\n Ext TEXT null,\n Website TEXT null,\n OpenDate DATE null,\n ClosedDate DATE null,\n Charter INTEGER null,\n CharterNum TEXT null,\n FundingType TEXT null,\n DOC TEXT not null,\n DOCType TEXT not null,\n SOC TEXT null,\n SOCType TEXT null,\n EdOpsCode TEXT null,\n EdOpsName TEXT null,\n EILCode TEXT null,\n EILName TEXT null,\n GSoffered TEXT null,\n GSserved TEXT null,\n Virtual TEXT null,\n Magnet INTEGER null,\n Latitude REAL null,\n Longitude REAL null,\n AdmFName1 TEXT null,\n AdmLName1 TEXT null,\n AdmEmail1 TEXT null,\n AdmFName2 TEXT null,\n AdmLName2 TEXT null,\n AdmEmail2 TEXT null,\n AdmFName3 TEXT null,\n AdmLName3 TEXT null,\n AdmEmail3 TEXT null,\n LastUpdate DATE not null\n);\n\n-- External Knowledge: Eligible free rate for K-12 = `Free Meal Count (K-12)` / `Enrollment (K-12)`\n\n-- Using valid SQLite and understanding External Knowledge, answer the following questions for the tables provided above.\n\n-- Using valid SQLite, answer the following questions for the tables provided above.\nQuestion: What is the highest eligible free rate for K-12 students in the schools in Alameda County?\n\n\nPlease write the SQL in one line without line breaks.And write a new python file named 0.py to call the SQL you wrote.You need to follow the code template below:\n\n\n import sqlite3\n def execute_sql(db_path, sql):\n with sqlite3.connect(db_path) as conn:\n cursor = conn.cursor()\n cursor.execute(sql)\n result = cursor.fetchall()\n return result\n\n if __name__ == '__main__':\n sql = \"\" # filling your SQL here\n db_path = \"california_schools/california_schools.sqlite\"\n print(db_path)\n result = execute_sql(db_path, sql)\n print(result)\n \n\nEnvironment has been set up for you to start working.You may assume all necessary tools are installed.\n\nIMPORTANT: You should ONLY interact with the environment provided to you AND NEVER ASK FOR HUMAN HELP.\nYou SHOULD INCLUDE PROPER INDENTATION in your edit commands.\nWhen you think you have fixed the issue through code changes, please finish the interaction using the "finish" tool.\n", diff --git a/evaluation/benchmarks/browsing_delegation/README.md b/evaluation/benchmarks/browsing_delegation/README.md index a06170f8b9e0..9ae349b81900 100644 --- a/evaluation/benchmarks/browsing_delegation/README.md +++ b/evaluation/benchmarks/browsing_delegation/README.md @@ -7,7 +7,7 @@ If so, the browsing performance upper-bound of CodeActAgent will be the performa ## Setup Environment and LLM Configuration -Please follow instruction [here](../README.md#setup) to setup your local development environment and LLM. +Please follow instruction [here](../../README.md#setup) to setup your local development environment and LLM. ## Run Inference diff --git a/evaluation/benchmarks/commit0_bench/README.md b/evaluation/benchmarks/commit0_bench/README.md index 78b58b02137f..9ac3a0e05dd3 100644 --- a/evaluation/benchmarks/commit0_bench/README.md +++ b/evaluation/benchmarks/commit0_bench/README.md @@ -4,19 +4,18 @@ This folder contains the evaluation harness that we built on top of the original The evaluation consists of three steps: -1. Environment setup: [install python environment](../README.md#development-environment), [configure LLM config](../README.md#configure-openhands-and-your-llm). +1. Environment setup: [install python environment](../../README.md#development-environment), [configure LLM config](../../README.md#configure-openhands-and-your-llm). 2. [Run Evaluation](#run-inference-on-commit0-instances): Generate a edit patch for each Commit0 Repo, and get the evaluation results ## Setup Environment and LLM Configuration -Please follow instruction [here](../README.md#setup) to setup your local development environment and LLM. +Please follow instruction [here](../../README.md#setup) to setup your local development environment and LLM. ## OpenHands Commit0 Instance-level Docker Support OpenHands supports using the Commit0 Docker for **[inference](#run-inference-on-commit0-instances). This is now the default behavior. - ## Run Inference on Commit0 Instances Make sure your Docker daemon is running, and you have ample disk space (at least 200-500GB, depends on the Commit0 set you are running on) for the [instance-level docker image](#openhands-commit0-instance-level-docker-support). diff --git a/evaluation/benchmarks/gaia/README.md b/evaluation/benchmarks/gaia/README.md index f592e5f7118d..9a7bbd7fa346 100644 --- a/evaluation/benchmarks/gaia/README.md +++ b/evaluation/benchmarks/gaia/README.md @@ -4,9 +4,10 @@ This folder contains evaluation harness for evaluating agents on the [GAIA bench ## Setup Environment and LLM Configuration -Please follow instruction [here](../README.md#setup) to setup your local development environment and LLM. +Please follow instruction [here](../../README.md#setup) to setup your local development environment and LLM. ## Run the evaluation + We are using the GAIA dataset hosted on [Hugging Face](https://huggingface.co/datasets/gaia-benchmark/GAIA). Please accept the terms and make sure to have logged in on your computer by `huggingface-cli login` before running the evaluation. @@ -41,6 +42,7 @@ For example, ## Get score Then you can get stats by running the following command: + ```bash python ./evaluation/benchmarks/gaia/get_score.py \ --file diff --git a/evaluation/benchmarks/gorilla/README.md b/evaluation/benchmarks/gorilla/README.md index c6f1cde55b40..d5a076234a5a 100644 --- a/evaluation/benchmarks/gorilla/README.md +++ b/evaluation/benchmarks/gorilla/README.md @@ -4,7 +4,7 @@ This folder contains evaluation harness we built on top of the original [Gorilla ## Setup Environment and LLM Configuration -Please follow instruction [here](../README.md#setup) to setup your local development environment and LLM. +Please follow instruction [here](../../README.md#setup) to setup your local development environment and LLM. ## Run Inference on APIBench Instances diff --git a/evaluation/benchmarks/gpqa/README.md b/evaluation/benchmarks/gpqa/README.md index 235b9ab9b281..735584d4556e 100644 --- a/evaluation/benchmarks/gpqa/README.md +++ b/evaluation/benchmarks/gpqa/README.md @@ -3,6 +3,7 @@ Implements the evaluation of agents on the GPQA benchmark introduced in [GPQA: A Graduate-Level Google-Proof Q&A Benchmark](https://arxiv.org/abs/2308.07124). This code implements the evaluation of agents on the GPQA Benchmark with Open Book setting. + - The benchmark consists of 448 high-quality and extremely difficult multiple-choice questions in the domains of biology, physics, and chemistry. The questions are intentionally designed to be "Google-proof," meaning that even highly skilled non-expert validators achieve only 34% accuracy despite unrestricted access to the web. - Even experts in the corresponding domains achieve only 65% accuracy. - State-of-the-art AI systems achieve only 39% accuracy on this challenging dataset. @@ -11,20 +12,24 @@ This code implements the evaluation of agents on the GPQA Benchmark with Open Bo Accurate solving of above graduate level questions would require both tool use (e.g., python for calculations) and web-search for finding related facts as information required for the questions might not be part of the LLM knowledge / training data. Further references: -- https://arxiv.org/pdf/2311.12022 -- https://paperswithcode.com/dataset/gpqa -- https://github.com/idavidrein/gpqa + +- +- +- ## Setup Environment and LLM Configuration -Please follow instruction [here](../README.md#setup) to setup your local development environment and LLM. +Please follow instruction [here](../../README.md#setup) to setup your local development environment and LLM. ## Run Inference on GPQA Benchmark + 'gpqa_main', 'gqpa_diamond', 'gpqa_experts', 'gpqa_extended' -- data split options From the root of the OpenHands repo, run the following command: + ```bash ./evaluation/benchmarks/gpqa/scripts/run_infer.sh [model_config_name] [git-version] [num_samples_eval] [data_split] [AgentClass] ``` + You can replace `model_config_name` with any model you set up in `config.toml`. - `model_config_name`: The model configuration name from `config.toml` that you want to evaluate. diff --git a/evaluation/benchmarks/humanevalfix/README.md b/evaluation/benchmarks/humanevalfix/README.md index 5f3ae58ee29d..60dabef1f609 100644 --- a/evaluation/benchmarks/humanevalfix/README.md +++ b/evaluation/benchmarks/humanevalfix/README.md @@ -4,7 +4,7 @@ Implements evaluation of agents on HumanEvalFix from the HumanEvalPack benchmark ## Setup Environment and LLM Configuration -Please follow instruction [here](../README.md#setup) to setup your local development environment and LLM. +Please follow instruction [here](../../README.md#setup) to setup your local development environment and LLM. ## Run Inference on HumanEvalFix @@ -14,13 +14,11 @@ Please follow instruction [here](../README.md#setup) to setup your local develop You can replace `eval_gpt4_1106_preview` with any model you set up in `config.toml`. - ## Examples For each problem, OpenHands is given a set number of iterations to fix the failing code. The history field shows each iteration's response to correct its code that fails any test case. - -``` +```json { "task_id": "Python/2", "instruction": "Please fix the function in Python__2.py such that all test cases pass.\nEnvironment has been set up for you to start working. You may assume all necessary tools are installed.\n\n# Problem Statement\ndef truncate_number(number: float) -> float:\n return number % 1.0 + 1.0\n\n\n\n\n\n\ndef check(truncate_number):\n assert truncate_number(3.5) == 0.5\n assert abs(truncate_number(1.33) - 0.33) < 1e-6\n assert abs(truncate_number(123.456) - 0.456) < 1e-6\n\ncheck(truncate_number)\n\nIMPORTANT: You should ONLY interact with the environment provided to you AND NEVER ASK FOR HUMAN HELP.\nYou should NOT modify any existing test case files. If needed, you can add new test cases in a NEW file to reproduce the issue.\nYou SHOULD INCLUDE PROPER INDENTATION in your edit commands.\nWhen you think you have fixed the issue through code changes, please finish the interaction using the "finish" tool.\n", diff --git a/evaluation/benchmarks/logic_reasoning/README.md b/evaluation/benchmarks/logic_reasoning/README.md index d4e4d3e9a554..bba0076f25fa 100644 --- a/evaluation/benchmarks/logic_reasoning/README.md +++ b/evaluation/benchmarks/logic_reasoning/README.md @@ -4,9 +4,10 @@ This folder contains evaluation harness for evaluating agents on the logic reaso ## Setup Environment and LLM Configuration -Please follow instruction [here](../README.md#setup) to setup your local development environment and LLM. +Please follow instruction [here](../../README.md#setup) to setup your local development environment and LLM. ## Run Inference on logic_reasoning + The following code will run inference on the first example of the ProofWriter dataset, ```bash diff --git a/evaluation/benchmarks/miniwob/README.md b/evaluation/benchmarks/miniwob/README.md index 5535e45a7dc0..3809925b3fd6 100644 --- a/evaluation/benchmarks/miniwob/README.md +++ b/evaluation/benchmarks/miniwob/README.md @@ -4,7 +4,7 @@ This folder contains evaluation for [MiniWoB++](https://miniwob.farama.org/) ben ## Setup Environment and LLM Configuration -Please follow instruction [here](../README.md#setup) to setup your local development environment and LLM. +Please follow instruction [here](../../README.md#setup) to setup your local development environment and LLM. ## Test if your environment works @@ -42,7 +42,6 @@ poetry run python evaluation/benchmarks/miniwob/get_success_rate.py evaluation/e You can start your own fork of [our huggingface evaluation outputs](https://huggingface.co/spaces/OpenHands/evaluation) and submit a PR of your evaluation results following the guide [here](https://huggingface.co/docs/hub/en/repositories-pull-requests-discussions#pull-requests-and-discussions). - ## BrowsingAgent V1.0 result Tested on BrowsingAgent V1.0 diff --git a/evaluation/benchmarks/ml_bench/README.md b/evaluation/benchmarks/ml_bench/README.md index 528edddc148a..e8b386205230 100644 --- a/evaluation/benchmarks/ml_bench/README.md +++ b/evaluation/benchmarks/ml_bench/README.md @@ -12,7 +12,7 @@ For more details on the ML-Bench task and dataset, please refer to the paper: [M ## Setup Environment and LLM Configuration -Please follow instruction [here](../README.md#setup) to setup your local development environment and LLM. +Please follow instruction [here](../../README.md#setup) to setup your local development environment and LLM. ## Run Inference on ML-Bench diff --git a/evaluation/benchmarks/scienceagentbench/README.md b/evaluation/benchmarks/scienceagentbench/README.md index 4d979177215b..5cb39da591af 100644 --- a/evaluation/benchmarks/scienceagentbench/README.md +++ b/evaluation/benchmarks/scienceagentbench/README.md @@ -1,10 +1,10 @@ # ScienceAgentBench Evaluation with OpenHands -This folder contains the evaluation harness for [ScienceAgentBench](https://osu-nlp-group.github.io/ScienceAgentBench/) (paper: https://arxiv.org/abs/2410.05080). +This folder contains the evaluation harness for [ScienceAgentBench](https://osu-nlp-group.github.io/ScienceAgentBench/) (paper: ). ## Setup Environment and LLM Configuration -Please follow instruction [here](../README.md#setup) to setup your local development environment and LLM. +Please follow instruction [here](../../README.md#setup) to setup your local development environment and LLM. ## Setup ScienceAgentBench @@ -45,6 +45,7 @@ After the inference is completed, you may use the following command to extract n ```bash python post_proc.py [log_fname] ``` + - `log_fname`, e.g. `evaluation/.../output.jsonl`, is the automatically saved trajectory log of an OpenHands agent. Output will be write to e.g. `evaluation/.../output.converted.jsonl` diff --git a/evaluation/benchmarks/swe_bench/README.md b/evaluation/benchmarks/swe_bench/README.md index b69a7389555c..7ed1e2688198 100644 --- a/evaluation/benchmarks/swe_bench/README.md +++ b/evaluation/benchmarks/swe_bench/README.md @@ -6,20 +6,19 @@ This folder contains the evaluation harness that we built on top of the original The evaluation consists of three steps: -1. Environment setup: [install python environment](../README.md#development-environment), [configure LLM config](../README.md#configure-openhands-and-your-llm), and [pull docker](#openhands-swe-bench-instance-level-docker-support). +1. Environment setup: [install python environment](../../README.md#development-environment), [configure LLM config](../../README.md#configure-openhands-and-your-llm), and [pull docker](#openhands-swe-bench-instance-level-docker-support). 2. [Run inference](#run-inference-on-swe-bench-instances): Generate a edit patch for each Github issue 3. [Evaluate patches using SWE-Bench docker](#evaluate-generated-patches) ## Setup Environment and LLM Configuration -Please follow instruction [here](../README.md#setup) to setup your local development environment and LLM. +Please follow instruction [here](../../README.md#setup) to setup your local development environment and LLM. ## OpenHands SWE-Bench Instance-level Docker Support OpenHands now support using the [official evaluation docker](https://github.com/princeton-nlp/SWE-bench/blob/main/docs/20240627_docker/README.md) for both **[inference](#run-inference-on-swe-bench-instances) and [evaluation](#evaluate-generated-patches)**. This is now the default behavior. - ## Run Inference on SWE-Bench Instances Make sure your Docker daemon is running, and you have ample disk space (at least 200-500GB, depends on the SWE-Bench set you are running on) for the [instance-level docker image](#openhands-swe-bench-instance-level-docker-support). @@ -52,7 +51,8 @@ default, it is set to 1. - `dataset_split`, split for the huggingface dataset. e.g., `test`, `dev`. Default to `test`. There are also two optional environment variables you can set. -``` + +```bash export USE_HINT_TEXT=true # if you want to use hint text in the evaluation. Default to false. Ignore this if you are not sure. export USE_INSTANCE_IMAGE=true # if you want to use instance-level docker images. Default to true ``` @@ -127,6 +127,7 @@ With `output.jsonl` file, you can run `eval_infer.sh` to evaluate generated patc **This evaluation is performed using the official dockerized evaluation announced [here](https://github.com/princeton-nlp/SWE-bench/blob/main/docs/20240627_docker/README.md).** > If you want to evaluate existing results, you should first run this to clone existing outputs +> >```bash >git clone https://huggingface.co/spaces/OpenHands/evaluation evaluation/evaluation_outputs >``` @@ -143,6 +144,7 @@ Then you can run the following: ``` The script now accepts optional arguments: + - `instance_id`: Specify a single instance to evaluate (optional) - `dataset_name`: The name of the dataset to use (default: `"princeton-nlp/SWE-bench_Lite"`) - `split`: The split of the dataset to use (default: `"test"`) @@ -179,7 +181,6 @@ To clean-up all existing runtimes that you've already started, run: ALLHANDS_API_KEY="YOUR-API-KEY" ./evaluation/benchmarks/swe_bench/scripts/cleanup_remote_runtime.sh ``` - ## Visualize Results First you need to clone `https://huggingface.co/spaces/OpenHands/evaluation` and add your own running results from openhands into the `outputs` of the cloned repo. @@ -189,6 +190,7 @@ git clone https://huggingface.co/spaces/OpenHands/evaluation ``` **(optional) setup streamlit environment with conda**: + ```bash cd evaluation conda create -n streamlit python=3.10 diff --git a/evaluation/benchmarks/swe_bench/scripts/eval/summarize_outputs.py b/evaluation/benchmarks/swe_bench/scripts/eval/summarize_outputs.py index 0da6eb25b54c..b376a70aea28 100755 --- a/evaluation/benchmarks/swe_bench/scripts/eval/summarize_outputs.py +++ b/evaluation/benchmarks/swe_bench/scripts/eval/summarize_outputs.py @@ -128,6 +128,11 @@ def process_file(file_path): for error, count in error_counter.items() }, }, + 'costs': { + 'main_agent': sum(main_agent_cost), + 'editor': sum(editor_cost), + 'total': sum(main_agent_cost) + sum(editor_cost), + }, 'statistics': { 'avg_turns': sum(num_turns) / num_lines if num_lines > 0 else 0, 'costs': { @@ -251,6 +256,7 @@ def aggregate_directory(input_path) -> pd.DataFrame: print( f"Number of unfinished runs: {result['unfinished_runs']['count']} / {result['total_instances']} ({result['unfinished_runs']['percentage']:.2f}%)" ) + print(f"Total cost: {result['costs']['total']:.2f} USD") print('## Statistics') print( f"Avg. num of turns per instance: {result['statistics']['avg_turns']:.2f}" diff --git a/evaluation/benchmarks/swe_bench/scripts/eval/verify_costs.py b/evaluation/benchmarks/swe_bench/scripts/eval/verify_costs.py new file mode 100644 index 000000000000..2e7b151e6873 --- /dev/null +++ b/evaluation/benchmarks/swe_bench/scripts/eval/verify_costs.py @@ -0,0 +1,104 @@ +import argparse + +import pandas as pd + +from openhands.core.logger import openhands_logger as logger + + +def verify_instance_costs(row: pd.Series) -> float: + """ + Verifies that the accumulated_cost matches the sum of individual costs in metrics. + Also checks for duplicate consecutive costs which might indicate buggy counting. + If the consecutive costs are identical, the file is affected by this bug: + https://github.com/All-Hands-AI/OpenHands/issues/5383 + + Args: + row: DataFrame row containing instance data with metrics + Returns: + float: The verified total cost for this instance (corrected if needed) + """ + try: + metrics = row.get('metrics') + if not metrics: + logger.warning(f"Instance {row['instance_id']}: No metrics found") + return 0.0 + + accumulated = metrics.get('accumulated_cost') + costs = metrics.get('costs', []) + + if accumulated is None: + logger.warning( + f"Instance {row['instance_id']}: No accumulated_cost in metrics" + ) + return 0.0 + + # Check for duplicate consecutive costs and systematic even-odd pairs + has_duplicate = False + all_pairs_match = True + + # Check each even-odd pair (0-1, 2-3, etc.) + for i in range(0, len(costs) - 1, 2): + if abs(costs[i]['cost'] - costs[i + 1]['cost']) < 1e-6: + has_duplicate = True + logger.debug( + f"Instance {row['instance_id']}: Possible buggy double-counting detected! " + f"Steps {i} and {i+1} have identical costs: {costs[i]['cost']:.2f}" + ) + else: + all_pairs_match = False + break + + # Calculate total cost, accounting for buggy double counting if detected + if len(costs) >= 2 and has_duplicate and all_pairs_match: + paired_steps_cost = sum( + cost_entry['cost'] + for cost_entry in costs[: -1 if len(costs) % 2 else None] + ) + real_paired_cost = paired_steps_cost / 2 + + unpaired_cost = costs[-1]['cost'] if len(costs) % 2 else 0 + total_cost = real_paired_cost + unpaired_cost + + else: + total_cost = sum(cost_entry['cost'] for cost_entry in costs) + + if not abs(total_cost - accumulated) < 1e-6: + logger.warning( + f"Instance {row['instance_id']}: Cost mismatch: " + f"accumulated: {accumulated:.2f}, sum of costs: {total_cost:.2f}, " + ) + + return total_cost + + except Exception as e: + logger.error( + f"Error verifying costs for instance {row.get('instance_id', 'UNKNOWN')}: {e}" + ) + return 0.0 + + +def main(): + parser = argparse.ArgumentParser( + description='Verify costs in SWE-bench output file' + ) + parser.add_argument( + 'input_filepath', type=str, help='Path to the output.jsonl file' + ) + args = parser.parse_args() + + try: + # Load and verify the JSONL file + df = pd.read_json(args.input_filepath, lines=True) + logger.info(f'Loaded {len(df)} instances from {args.input_filepath}') + + # Verify costs for each instance and sum up total + total_cost = df.apply(verify_instance_costs, axis=1).sum() + logger.info(f'Total verified cost across all instances: ${total_cost:.2f}') + + except Exception as e: + logger.error(f'Failed to process file: {e}') + raise + + +if __name__ == '__main__': + main() diff --git a/evaluation/benchmarks/swe_bench/scripts/setup/instance_swe_entry.sh b/evaluation/benchmarks/swe_bench/scripts/setup/instance_swe_entry.sh index 22427b001254..9cbf9cc00710 100755 --- a/evaluation/benchmarks/swe_bench/scripts/setup/instance_swe_entry.sh +++ b/evaluation/benchmarks/swe_bench/scripts/setup/instance_swe_entry.sh @@ -33,7 +33,7 @@ if [ -d /workspace/$WORKSPACE_NAME ]; then rm -rf /workspace/$WORKSPACE_NAME fi mkdir -p /workspace -ln -s /testbed /workspace/$WORKSPACE_NAME +mv /testbed /workspace/$WORKSPACE_NAME # Activate instance-specific environment . /opt/miniconda3/etc/profile.d/conda.sh diff --git a/evaluation/benchmarks/toolqa/README.md b/evaluation/benchmarks/toolqa/README.md index eda478f4489f..b6b25da43b0e 100644 --- a/evaluation/benchmarks/toolqa/README.md +++ b/evaluation/benchmarks/toolqa/README.md @@ -4,7 +4,7 @@ This folder contains an evaluation harness we built on top of the original [Tool ## Setup Environment and LLM Configuration -Please follow instruction [here](../README.md#setup) to setup your local development environment and LLM. +Please follow instruction [here](../../README.md#setup) to setup your local development environment and LLM. ## Run Inference on ToolQA Instances diff --git a/evaluation/benchmarks/webarena/README.md b/evaluation/benchmarks/webarena/README.md index 3e403d5a7f46..68f37c1a7b8f 100644 --- a/evaluation/benchmarks/webarena/README.md +++ b/evaluation/benchmarks/webarena/README.md @@ -4,7 +4,7 @@ This folder contains evaluation for [WebArena](https://github.com/web-arena-x/we ## Setup Environment and LLM Configuration -Please follow instruction [here](../README.md#setup) to setup your local development environment and LLM. +Please follow instruction [here](../../README.md#setup) to setup your local development environment and LLM. ## Setup WebArena Environment diff --git a/frontend/__tests__/components/browser.test.tsx b/frontend/__tests__/components/browser.test.tsx index eea2eb910a48..8fb7e0a31014 100644 --- a/frontend/__tests__/components/browser.test.tsx +++ b/frontend/__tests__/components/browser.test.tsx @@ -11,6 +11,7 @@ describe("Browser", () => { browser: { url: "https://example.com", screenshotSrc: "", + updateCount: 0, }, }, }); @@ -26,6 +27,7 @@ describe("Browser", () => { url: "https://example.com", screenshotSrc: "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mN0uGvyHwAFCAJS091fQwAAAABJRU5ErkJggg==", + updateCount: 0, }, }, }); diff --git a/frontend/__tests__/components/chat-message.test.tsx b/frontend/__tests__/components/chat-message.test.tsx index 9b3156ee54fe..08fd090551d3 100644 --- a/frontend/__tests__/components/chat-message.test.tsx +++ b/frontend/__tests__/components/chat-message.test.tsx @@ -70,4 +70,12 @@ describe("ChatMessage", () => { ); expect(screen.getByTestId("custom-component")).toBeInTheDocument(); }); + + it("should apply correct styles to inline code", () => { + render(); + const codeElement = screen.getByText("inline code"); + + expect(codeElement.tagName.toLowerCase()).toBe("code"); + expect(codeElement.closest("article")).not.toBeNull(); + }); }); diff --git a/frontend/__tests__/components/chat/expandable-message.test.tsx b/frontend/__tests__/components/chat/expandable-message.test.tsx new file mode 100644 index 000000000000..8eab988339de --- /dev/null +++ b/frontend/__tests__/components/chat/expandable-message.test.tsx @@ -0,0 +1,60 @@ +import { describe, expect, it } from "vitest"; +import { screen } from "@testing-library/react"; +import { renderWithProviders } from "test-utils"; +import { ExpandableMessage } from "#/components/features/chat/expandable-message"; + +describe("ExpandableMessage", () => { + it("should render with neutral border for non-action messages", () => { + renderWithProviders(); + const element = screen.getByText("Hello"); + const container = element.closest("div.flex.gap-2.items-center.justify-between"); + expect(container).toHaveClass("border-neutral-300"); + expect(screen.queryByTestId("status-icon")).not.toBeInTheDocument(); + }); + + it("should render with neutral border for error messages", () => { + renderWithProviders(); + const element = screen.getByText("Error occurred"); + const container = element.closest("div.flex.gap-2.items-center.justify-between"); + expect(container).toHaveClass("border-neutral-300"); + expect(screen.queryByTestId("status-icon")).not.toBeInTheDocument(); + }); + + it("should render with success icon for successful action messages", () => { + renderWithProviders( + + ); + const element = screen.getByText("Command executed successfully"); + const container = element.closest("div.flex.gap-2.items-center.justify-between"); + expect(container).toHaveClass("border-neutral-300"); + const icon = screen.getByTestId("status-icon"); + expect(icon).toHaveClass("fill-success"); + }); + + it("should render with error icon for failed action messages", () => { + renderWithProviders( + + ); + const element = screen.getByText("Command failed"); + const container = element.closest("div.flex.gap-2.items-center.justify-between"); + expect(container).toHaveClass("border-neutral-300"); + const icon = screen.getByTestId("status-icon"); + expect(icon).toHaveClass("fill-danger"); + }); + + it("should render with neutral border and no icon for action messages without success prop", () => { + renderWithProviders(); + const element = screen.getByText("Running command"); + const container = element.closest("div.flex.gap-2.items-center.justify-between"); + expect(container).toHaveClass("border-neutral-300"); + expect(screen.queryByTestId("status-icon")).not.toBeInTheDocument(); + }); +}); diff --git a/frontend/__tests__/components/features/waitlist-modal.test.tsx b/frontend/__tests__/components/features/waitlist-modal.test.tsx new file mode 100644 index 000000000000..b1f17bd26eac --- /dev/null +++ b/frontend/__tests__/components/features/waitlist-modal.test.tsx @@ -0,0 +1,45 @@ +import { render, screen } from "@testing-library/react"; +import { it, describe, expect, vi } from "vitest"; +import userEvent from "@testing-library/user-event"; +import { WaitlistModal } from "#/components/features/waitlist/waitlist-modal"; +import * as CaptureConsent from "#/utils/handle-capture-consent"; + +describe("WaitlistModal", () => { + it("should render a tos checkbox that is unchecked by default", () => { + render(); + const checkbox = screen.getByRole("checkbox"); + + expect(checkbox).not.toBeChecked(); + }); + + it("should only enable the GitHub button if the tos checkbox is checked", async () => { + const user = userEvent.setup(); + render(); + const checkbox = screen.getByRole("checkbox"); + const button = screen.getByRole("button", { name: "Connect to GitHub" }); + + expect(button).toBeDisabled(); + + await user.click(checkbox); + + expect(button).not.toBeDisabled(); + }); + + it("should set user analytics consent to true when the user checks the tos checkbox", async () => { + const handleCaptureConsentSpy = vi.spyOn( + CaptureConsent, + "handleCaptureConsent", + ); + + const user = userEvent.setup(); + render(); + + const checkbox = screen.getByRole("checkbox"); + await user.click(checkbox); + + const button = screen.getByRole("button", { name: "Connect to GitHub" }); + await user.click(button); + + expect(handleCaptureConsentSpy).toHaveBeenCalledWith(true); + }); +}); diff --git a/frontend/__tests__/components/interactive-chat-box.test.tsx b/frontend/__tests__/components/interactive-chat-box.test.tsx index fa0d3a1b8e30..fe6ba329763b 100644 --- a/frontend/__tests__/components/interactive-chat-box.test.tsx +++ b/frontend/__tests__/components/interactive-chat-box.test.tsx @@ -1,4 +1,4 @@ -import { render, screen, within } from "@testing-library/react"; +import { render, screen, within, fireEvent } from "@testing-library/react"; import userEvent from "@testing-library/user-event"; import { afterEach, beforeAll, describe, expect, it, vi } from "vitest"; import { InteractiveChatBox } from "#/components/features/chat/interactive-chat-box"; @@ -131,4 +131,60 @@ describe("InteractiveChatBox", () => { await user.click(stopButton); expect(onStopMock).toHaveBeenCalledOnce(); }); + + it("should handle image upload and message submission correctly", async () => { + const user = userEvent.setup(); + const onSubmit = vi.fn(); + const onStop = vi.fn(); + const onChange = vi.fn(); + + const { rerender } = render( + + ); + + // Upload an image via the upload button - this should NOT clear the text input + const file = new File(["dummy content"], "test.png", { type: "image/png" }); + const input = screen.getByTestId("upload-image-input"); + await user.upload(input, file); + + // Verify text input was not cleared + expect(screen.getByRole("textbox")).toHaveValue("test message"); + expect(onChange).not.toHaveBeenCalledWith(""); + + // Submit the message with image + const submitButton = screen.getByRole("button", { name: "Send" }); + await user.click(submitButton); + + // Verify onSubmit was called with the message and image + expect(onSubmit).toHaveBeenCalledWith("test message", [file]); + + // Verify onChange was called to clear the text input + expect(onChange).toHaveBeenCalledWith(""); + + // Simulate parent component updating the value prop + rerender( + + ); + + // Verify the text input was cleared + expect(screen.getByRole("textbox")).toHaveValue(""); + + // Upload another image - this should NOT clear the text input + onChange.mockClear(); + await user.upload(input, file); + + // Verify text input is still empty and onChange was not called + expect(screen.getByRole("textbox")).toHaveValue(""); + expect(onChange).not.toHaveBeenCalled(); + }); }); diff --git a/frontend/__tests__/routes/_oh.test.tsx b/frontend/__tests__/routes/_oh.test.tsx index c97a9a825d56..8897b5dd8bd3 100644 --- a/frontend/__tests__/routes/_oh.test.tsx +++ b/frontend/__tests__/routes/_oh.test.tsx @@ -4,8 +4,9 @@ import { screen, waitFor, within } from "@testing-library/react"; import { renderWithProviders } from "test-utils"; import userEvent from "@testing-library/user-event"; import MainApp from "#/routes/_oh/route"; -import * as CaptureConsent from "#/utils/handle-capture-consent"; import i18n from "#/i18n"; +import * as CaptureConsent from "#/utils/handle-capture-consent"; +import OpenHands from "#/api/open-hands"; describe("frontend/routes/_oh", () => { const RouteStub = createRoutesStub([{ Component: MainApp, path: "/" }]); @@ -60,13 +61,20 @@ describe("frontend/routes/_oh", () => { }); }); - it("should capture the user's consent", async () => { + it("should render and capture the user's consent if oss mode", async () => { const user = userEvent.setup(); + const getConfigSpy = vi.spyOn(OpenHands, "getConfig"); const handleCaptureConsentSpy = vi.spyOn( CaptureConsent, "handleCaptureConsent", ); + getConfigSpy.mockResolvedValue({ + APP_MODE: "oss", + GITHUB_CLIENT_ID: "test-id", + POSTHOG_CLIENT_KEY: "test-key", + }); + renderWithProviders(); // The user has not consented to tracking @@ -87,6 +95,23 @@ describe("frontend/routes/_oh", () => { ).not.toBeInTheDocument(); }); + it("should not render the user consent form if saas mode", async () => { + const getConfigSpy = vi.spyOn(OpenHands, "getConfig"); + getConfigSpy.mockResolvedValue({ + APP_MODE: "saas", + GITHUB_CLIENT_ID: "test-id", + POSTHOG_CLIENT_KEY: "test-key", + }); + + renderWithProviders(); + + await waitFor(() => { + expect( + screen.queryByTestId("user-capture-consent-form"), + ).not.toBeInTheDocument(); + }); + }); + it("should not render the user consent form if the user has already made a decision", async () => { localStorage.setItem("analytics-consent", "true"); renderWithProviders(); diff --git a/frontend/package-lock.json b/frontend/package-lock.json index ea59e9e41a73..b2213074af30 100644 --- a/frontend/package-lock.json +++ b/frontend/package-lock.json @@ -1,12 +1,12 @@ { "name": "openhands-frontend", - "version": "0.15.0", + "version": "0.15.2", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "openhands-frontend", - "version": "0.15.0", + "version": "0.15.2", "dependencies": { "@monaco-editor/react": "^4.6.0", "@nextui-org/react": "^2.4.8", @@ -51,7 +51,7 @@ "@playwright/test": "^1.48.2", "@react-router/dev": "^7.0.1", "@tailwindcss/typography": "^0.5.15", - "@tanstack/eslint-plugin-query": "^5.60.1", + "@tanstack/eslint-plugin-query": "^5.62.1", "@testing-library/jest-dom": "^6.6.1", "@testing-library/react": "^16.0.1", "@testing-library/user-event": "^14.5.2", @@ -78,7 +78,7 @@ "husky": "^9.1.6", "jsdom": "^25.0.1", "lint-staged": "^15.2.10", - "msw": "^2.3.0-ws.rc-12", + "msw": "^2.6.6", "postcss": "^8.4.47", "prettier": "^3.3.3", "tailwindcss": "^3.4.14", @@ -5503,9 +5503,9 @@ } }, "node_modules/@tanstack/eslint-plugin-query": { - "version": "5.61.4", - "resolved": "https://registry.npmjs.org/@tanstack/eslint-plugin-query/-/eslint-plugin-query-5.61.4.tgz", - "integrity": "sha512-QVVsY8hwrX9r6c8lLV48oY682SU2GeVlo0hWMSaOKkI05Yi4bXhw5jv7E2qkbjGrgA6DcVl3o/F0dT4wpT+/SQ==", + "version": "5.62.1", + "resolved": "https://registry.npmjs.org/@tanstack/eslint-plugin-query/-/eslint-plugin-query-5.62.1.tgz", + "integrity": "sha512-1886D5U+re1TW0wSH4/kUGG36yIoW5Wkz4twVEzlk3ZWmjF3XkRSWgB+Sc7n+Lyzt8usNV8ZqkZE6DA7IC47fQ==", "dev": true, "dependencies": { "@typescript-eslint/utils": "^8.15.0" diff --git a/frontend/package.json b/frontend/package.json index 7980387f71ba..827808729752 100644 --- a/frontend/package.json +++ b/frontend/package.json @@ -1,6 +1,6 @@ { "name": "openhands-frontend", - "version": "0.15.0", + "version": "0.15.2", "private": true, "type": "module", "engines": { @@ -78,7 +78,7 @@ "@playwright/test": "^1.48.2", "@react-router/dev": "^7.0.1", "@tailwindcss/typography": "^0.5.15", - "@tanstack/eslint-plugin-query": "^5.60.1", + "@tanstack/eslint-plugin-query": "^5.62.1", "@testing-library/jest-dom": "^6.6.1", "@testing-library/react": "^16.0.1", "@testing-library/user-event": "^14.5.2", @@ -105,7 +105,7 @@ "husky": "^9.1.6", "jsdom": "^25.0.1", "lint-staged": "^15.2.10", - "msw": "^2.3.0-ws.rc-12", + "msw": "^2.6.6", "postcss": "^8.4.47", "prettier": "^3.3.3", "tailwindcss": "^3.4.14", diff --git a/frontend/src/components/features/chat/chat-input.tsx b/frontend/src/components/features/chat/chat-input.tsx index 815eb1933720..6cec5f42e04d 100644 --- a/frontend/src/components/features/chat/chat-input.tsx +++ b/frontend/src/components/features/chat/chat-input.tsx @@ -83,9 +83,13 @@ export function ChatInput({ }; const handleSubmitMessage = () => { - if (textareaRef.current?.value) { - onSubmit(textareaRef.current.value); - textareaRef.current.value = ""; + const message = value || textareaRef.current?.value || ""; + if (message) { + onSubmit(message); + onChange?.(""); + if (textareaRef.current) { + textareaRef.current.value = ""; + } } }; diff --git a/frontend/src/components/features/chat/expandable-message.tsx b/frontend/src/components/features/chat/expandable-message.tsx index f42b3f0b13ad..6ebcaa3aeed5 100644 --- a/frontend/src/components/features/chat/expandable-message.tsx +++ b/frontend/src/components/features/chat/expandable-message.tsx @@ -6,17 +6,21 @@ import { code } from "../markdown/code"; import { ol, ul } from "../markdown/list"; import ArrowUp from "#/icons/angle-up-solid.svg?react"; import ArrowDown from "#/icons/angle-down-solid.svg?react"; +import CheckCircle from "#/icons/check-circle-solid.svg?react"; +import XCircle from "#/icons/x-circle-solid.svg?react"; interface ExpandableMessageProps { id?: string; message: string; type: string; + success?: boolean; } export function ExpandableMessage({ id, message, type, + success, }: ExpandableMessageProps) { const { t, i18n } = useTranslation(); const [showDetails, setShowDetails] = useState(true); @@ -31,22 +35,14 @@ export function ExpandableMessage({ } }, [id, message, i18n.language]); - const border = type === "error" ? "border-danger" : "border-neutral-300"; - const textColor = type === "error" ? "text-danger" : "text-neutral-300"; - let arrowClasses = "h-4 w-4 ml-2 inline"; - if (type === "error") { - arrowClasses += " fill-danger"; - } else { - arrowClasses += " fill-neutral-300"; - } + const arrowClasses = "h-4 w-4 ml-2 inline fill-neutral-300"; + const statusIconClasses = "h-4 w-4 ml-2 inline"; return ( -
+
{headline && ( -

+

{headline}

+ {type === "action" && success !== undefined && ( +
+ {success ? ( + + ) : ( + + )} +
+ )}
); } diff --git a/frontend/src/components/features/chat/interactive-chat-box.tsx b/frontend/src/components/features/chat/interactive-chat-box.tsx index e96339adf0a7..09dcf84b32d6 100644 --- a/frontend/src/components/features/chat/interactive-chat-box.tsx +++ b/frontend/src/components/features/chat/interactive-chat-box.tsx @@ -38,6 +38,9 @@ export function InteractiveChatBox({ const handleSubmit = (message: string) => { onSubmit(message, images); setImages([]); + if (message) { + onChange?.(""); + } }; return ( diff --git a/frontend/src/components/features/chat/messages.tsx b/frontend/src/components/features/chat/messages.tsx index 1f7eff016582..e1bd34637472 100644 --- a/frontend/src/components/features/chat/messages.tsx +++ b/frontend/src/components/features/chat/messages.tsx @@ -14,13 +14,13 @@ export function Messages({ }: MessagesProps) { return messages.map((message, index) => { if (message.type === "error" || message.type === "action") { - console.log("expando", message); return ( ); } diff --git a/frontend/src/components/features/file-explorer/file-explorer.tsx b/frontend/src/components/features/file-explorer/file-explorer.tsx index b033cfb62126..039fc1602003 100644 --- a/frontend/src/components/features/file-explorer/file-explorer.tsx +++ b/frontend/src/components/features/file-explorer/file-explorer.tsx @@ -1,5 +1,5 @@ import React from "react"; -import { useSelector } from "react-redux"; +import { useDispatch, useSelector } from "react-redux"; import { useTranslation } from "react-i18next"; import AgentState from "#/types/agent-state"; import { ExplorerTree } from "#/components/features/file-explorer/explorer-tree"; @@ -14,6 +14,7 @@ import { Dropzone } from "./dropzone"; import { FileExplorerHeader } from "./file-explorer-header"; import { useVSCodeUrl } from "#/hooks/query/use-vscode-url"; import { OpenVSCodeButton } from "#/components/shared/buttons/open-vscode-button"; +import { addAssistantMessage } from "#/state/chat-slice"; interface FileExplorerProps { isOpen: boolean; @@ -22,15 +23,37 @@ interface FileExplorerProps { export function FileExplorer({ isOpen, onToggle }: FileExplorerProps) { const { t } = useTranslation(); + const dispatch = useDispatch(); const fileInputRef = React.useRef(null); const [isDragging, setIsDragging] = React.useState(false); const { curAgentState } = useSelector((state: RootState) => state.agent); + const agentIsReady = + curAgentState !== AgentState.INIT && curAgentState !== AgentState.LOADING; + const { data: paths, refetch, error } = useListFiles(); const { mutate: uploadFiles } = useUploadFiles(); - const { refetch: getVSCodeUrl } = useVSCodeUrl(); + const { data: vscodeUrl } = useVSCodeUrl({ enabled: agentIsReady }); + + const handleOpenVSCode = () => { + if (vscodeUrl?.vscode_url) { + dispatch( + addAssistantMessage( + "You opened VS Code. Please inform the agent of any changes you made to the workspace or environment. To avoid conflicts, it's best to pause the agent before making any changes.", + ), + ); + window.open(vscodeUrl.vscode_url, "_blank"); + } else if (vscodeUrl?.error) { + toast.error( + `open-vscode-error-${new Date().getTime()}`, + t(I18nKey.EXPLORER$VSCODE_SWITCHING_ERROR_MESSAGE, { + error: vscodeUrl.error, + }), + ); + } + }; const selectFileInput = () => { fileInputRef.current?.click(); // Trigger the file browser @@ -142,11 +165,8 @@ export function FileExplorer({ isOpen, onToggle }: FileExplorerProps) { )} {isOpen && ( )}
diff --git a/frontend/src/components/features/file-explorer/tree-node.tsx b/frontend/src/components/features/file-explorer/tree-node.tsx index 524f56578e1c..1410e38a9c7b 100644 --- a/frontend/src/components/features/file-explorer/tree-node.tsx +++ b/frontend/src/components/features/file-explorer/tree-node.tsx @@ -1,10 +1,12 @@ import React from "react"; +import { useSelector } from "react-redux"; import { useFiles } from "#/context/files"; import { cn } from "#/utils/utils"; import { useListFiles } from "#/hooks/query/use-list-files"; import { useListFile } from "#/hooks/query/use-list-file"; import { Filename } from "./filename"; +import { RootState } from "#/store"; interface TreeNodeProps { path: string; @@ -20,6 +22,7 @@ function TreeNode({ path, defaultOpen = false }: TreeNodeProps) { selectedPath, } = useFiles(); const [isOpen, setIsOpen] = React.useState(defaultOpen); + const { curAgentState } = useSelector((state: RootState) => state.agent); const isDirectory = path.endsWith("/"); @@ -39,6 +42,12 @@ function TreeNode({ path, defaultOpen = false }: TreeNodeProps) { } }, [fileContent, path]); + React.useEffect(() => { + if (selectedPath === path && !isDirectory) { + refetch(); + } + }, [curAgentState, selectedPath, path, isDirectory]); + const fileParts = path.split("/"); const filename = fileParts[fileParts.length - 1] || fileParts[fileParts.length - 2]; diff --git a/frontend/src/components/features/markdown/code.tsx b/frontend/src/components/features/markdown/code.tsx index a7522722d5ea..d68191d4766e 100644 --- a/frontend/src/components/features/markdown/code.tsx +++ b/frontend/src/components/features/markdown/code.tsx @@ -17,7 +17,20 @@ export function code({ const match = /language-(\w+)/.exec(className || ""); // get the language if (!match) { - return {children}; + return ( + + {children} + + ); } return ( diff --git a/frontend/src/components/features/project-menu/ProjectMenuCard.tsx b/frontend/src/components/features/project-menu/ProjectMenuCard.tsx index b8fd755a6050..bb4074907682 100644 --- a/frontend/src/components/features/project-menu/ProjectMenuCard.tsx +++ b/frontend/src/components/features/project-menu/ProjectMenuCard.tsx @@ -1,9 +1,7 @@ import React from "react"; -import { useDispatch } from "react-redux"; import toast from "react-hot-toast"; import posthog from "posthog-js"; import EllipsisH from "#/icons/ellipsis-h.svg?react"; -import { addUserMessage } from "#/state/chat-slice"; import { createChatMessage } from "#/services/chat-service"; import { ProjectMenuCardContextMenu } from "./project.menu-card-context-menu"; import { ProjectMenuDetailsPlaceholder } from "./project-menu-details-placeholder"; @@ -28,7 +26,6 @@ export function ProjectMenuCard({ githubData, }: ProjectMenuCardProps) { const { send } = useWsClient(); - const dispatch = useDispatch(); const [contextMenuIsOpen, setContextMenuIsOpen] = React.useState(false); const [connectToGitHubModalOpen, setConnectToGitHubModalOpen] = @@ -56,7 +53,6 @@ Please push the changes to GitHub and open a pull request. ); send(event); // send to socket - dispatch(addUserMessage(rawEvent)); // display in chat interface setContextMenuIsOpen(false); }; diff --git a/frontend/src/components/features/sidebar/sidebar.tsx b/frontend/src/components/features/sidebar/sidebar.tsx index 468c5c156882..fa11bc3fb366 100644 --- a/frontend/src/components/features/sidebar/sidebar.tsx +++ b/frontend/src/components/features/sidebar/sidebar.tsx @@ -54,13 +54,13 @@ export function Sidebar() { return ( <> -