mirror of
https://github.com/All-Hands-AI/OpenHands.git
synced 2026-04-29 03:00:45 -04:00
Compare commits
14 Commits
openhands/
...
fix-git-co
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
8067ae85c3 | ||
|
|
4e300b24b7 | ||
|
|
6ceae397d7 | ||
|
|
f894c25597 | ||
|
|
87b936b04a | ||
|
|
6068e4298b | ||
|
|
388e3ba496 | ||
|
|
2fd68cef2f | ||
|
|
e1788a74c5 | ||
|
|
f046982d41 | ||
|
|
e600225f0f | ||
|
|
dd8401cc98 | ||
|
|
e99f41372a | ||
|
|
e43f73f643 |
2
.github/workflows/e2e-tests.yml
vendored
2
.github/workflows/e2e-tests.yml
vendored
@@ -187,8 +187,6 @@ jobs:
|
||||
test_settings.py::test_github_token_configuration \
|
||||
test_conversation.py::test_conversation_start \
|
||||
test_browsing_catchphrase.py::test_browsing_catchphrase \
|
||||
test_multi_conversation_resume.py::test_multi_conversation_resume \
|
||||
test_react_app_creation.py::test_react_app_creation \
|
||||
-v --no-header --capture=no --timeout=900
|
||||
|
||||
- name: Upload test results
|
||||
|
||||
2
.github/workflows/stale.yml
vendored
2
.github/workflows/stale.yml
vendored
@@ -15,7 +15,7 @@ jobs:
|
||||
stale-issue-message: 'This issue is stale because it has been open for 40 days with no activity. Remove the stale label or leave a comment, otherwise it will be closed in 10 days.'
|
||||
stale-pr-message: 'This PR is stale because it has been open for 40 days with no activity. Remove the stale label or leave a comment, otherwise it will be closed in 10 days.'
|
||||
days-before-stale: 40
|
||||
exempt-issue-labels: roadmap,backlog
|
||||
exempt-issue-labels: 'roadmap'
|
||||
close-issue-message: 'This issue was automatically closed due to 50 days of inactivity. We do this to help keep the issues somewhat manageable and focus on active issues.'
|
||||
close-pr-message: 'This PR was closed because it had no activity for 50 days. If you feel this was closed in error, and you would like to continue the PR, please resubmit or let us know.'
|
||||
days-before-close: 10
|
||||
|
||||
2
.gitignore
vendored
2
.gitignore
vendored
@@ -257,5 +257,5 @@ containers/runtime/code
|
||||
|
||||
# test results
|
||||
test-results
|
||||
.sessions
|
||||
|
||||
.eval_sessions
|
||||
|
||||
47
.pre-commit-config.yaml
Normal file
47
.pre-commit-config.yaml
Normal file
@@ -0,0 +1,47 @@
|
||||
repos:
|
||||
- repo: https://github.com/pre-commit/pre-commit-hooks
|
||||
rev: v5.0.0
|
||||
hooks:
|
||||
- id: trailing-whitespace
|
||||
exclude: ^(docs/|modules/|python/|openhands-ui/|third_party/)
|
||||
- id: end-of-file-fixer
|
||||
exclude: ^(docs/|modules/|python/|openhands-ui/|third_party/)
|
||||
- id: check-yaml
|
||||
args: ["--allow-multiple-documents"]
|
||||
- id: debug-statements
|
||||
|
||||
- repo: https://github.com/tox-dev/pyproject-fmt
|
||||
rev: v2.5.1
|
||||
hooks:
|
||||
- id: pyproject-fmt
|
||||
- repo: https://github.com/abravalheri/validate-pyproject
|
||||
rev: v0.24.1
|
||||
hooks:
|
||||
- id: validate-pyproject
|
||||
|
||||
- repo: https://github.com/astral-sh/ruff-pre-commit
|
||||
# Ruff version.
|
||||
rev: v0.11.8
|
||||
hooks:
|
||||
# Run the linter.
|
||||
- id: ruff
|
||||
entry: ruff check --config dev_config/python/ruff.toml
|
||||
types_or: [python, pyi, jupyter]
|
||||
args: [--fix, --unsafe-fixes]
|
||||
exclude: third_party/
|
||||
# Run the formatter.
|
||||
- id: ruff-format
|
||||
entry: ruff format --config dev_config/python/ruff.toml
|
||||
types_or: [python, pyi, jupyter]
|
||||
exclude: third_party/
|
||||
|
||||
- repo: https://github.com/pre-commit/mirrors-mypy
|
||||
rev: v1.15.0
|
||||
hooks:
|
||||
- id: mypy
|
||||
additional_dependencies:
|
||||
[types-requests, types-setuptools, types-pyyaml, types-toml, types-docker, types-Markdown, pydantic, lxml]
|
||||
# To see gaps add `--html-report mypy-report/`
|
||||
entry: mypy --config-file dev_config/python/mypy.ini openhands/
|
||||
always_run: true
|
||||
pass_filenames: false
|
||||
@@ -363,11 +363,10 @@ classpath = "my_package.my_module.MyCustomAgent"
|
||||
#confirmation_mode = false
|
||||
|
||||
# The security analyzer to use (For Headless / CLI only - In Web this is overridden by Session Init)
|
||||
# Available options: 'llm' (default), 'invariant'
|
||||
#security_analyzer = "llm"
|
||||
#security_analyzer = ""
|
||||
|
||||
# Whether to enable security analyzer
|
||||
#enable_security_analyzer = true
|
||||
#enable_security_analyzer = false
|
||||
|
||||
#################################### Condenser #################################
|
||||
# Condensers control how conversation history is managed and compressed when
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
---
|
||||
title: Jira Data Center Integration (Coming soon...)
|
||||
title: Jira Data Center Integration (Beta)
|
||||
description: Complete guide for setting up Jira Data Center integration with OpenHands Cloud, including service account creation, personal access token generation, webhook configuration, and workspace integration setup.
|
||||
---
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
---
|
||||
title: Jira Cloud Integration (Coming soon...)
|
||||
title: Jira Cloud Integration
|
||||
description: Complete guide for setting up Jira Cloud integration with OpenHands Cloud, including service account creation, API token generation, webhook configuration, and workspace integration setup.
|
||||
---
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
---
|
||||
title: Linear Integration (Coming soon...)
|
||||
title: Linear Integration
|
||||
description: Complete guide for setting up Linear integration with OpenHands Cloud, including service account creation, API key generation, webhook configuration, and workspace integration setup.
|
||||
---
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
---
|
||||
title: Project Management Tool Integrations (Coming soon...)
|
||||
title: Project Management Tool Integrations
|
||||
description: Overview of OpenHands Cloud integrations with project management platforms including Jira Cloud, Jira Data Center, and Linear. Learn about setup requirements, usage methods, and troubleshooting.
|
||||
---
|
||||
|
||||
@@ -18,9 +18,9 @@ Integration requires two levels of setup:
|
||||
2. **Workspace Integration** - Self-service configuration through the OpenHands Cloud UI to link your OpenHands account to the target workspace
|
||||
|
||||
### Platform-Specific Setup Guides:
|
||||
- [Jira Cloud Integration (Coming soon...)](./jira-integration.md)
|
||||
- [Jira Data Center Integration (Coming soon...)](./jira-dc-integration.md)
|
||||
- [Linear Integration (Coming soon...)](./linear-integration.md)
|
||||
- [Jira Cloud Integration](./jira-integration.md)
|
||||
- [Jira Data Center Integration](./jira-dc-integration.md)
|
||||
- [Linear Integration](./linear-integration.md)
|
||||
|
||||
## Usage
|
||||
|
||||
|
||||
@@ -1,52 +0,0 @@
|
||||
# Confirmation Mode and Security Analyzers
|
||||
|
||||
OpenHands provides a security framework to help protect users from potentially risky actions through **Confirmation Mode** and **Security Analyzers**. This system analyzes agent actions and prompts users for confirmation when high-risk operations are detected.
|
||||
|
||||
## Overview
|
||||
|
||||
The security system consists of two main components:
|
||||
|
||||
1. **Confirmation Mode**: When enabled, the agent will pause and ask for user confirmation before executing actions that are flagged as high-risk by the security analyzer.
|
||||
|
||||
2. **Security Analyzers**: These are modules that evaluate the risk level of agent actions and determine whether user confirmation is required.
|
||||
|
||||
## Configuration
|
||||
|
||||
### CLI
|
||||
In CLI mode, confirmation is enabled by default. You will have an option to uses the LLM Analyzer and will automatically confirm LOW and MEDIUM risk actions, only prompting for HIGH risk actions.
|
||||
|
||||
## Security Analyzers
|
||||
|
||||
OpenHands includes multiple analyzers:
|
||||
|
||||
- **No Analyzer**: Do not use any security analyzer. The agent will prompt you to confirm *EVERY* action.
|
||||
- **LLM Risk Analyzer** (default): Uses the same LLM as the agent to assess action risk levels
|
||||
- **Invariant Analyzer**: Uses Invariant Labs' policy engine to evaluate action traces against security policies
|
||||
|
||||
### LLM Risk Analyzer
|
||||
The default analyzer that leverages the agent's LLM to evaluate the security risk of each action. It considers the action type, parameters, and context to assign risk levels.
|
||||
|
||||
### Invariant Analyzer
|
||||
An advanced analyzer that:
|
||||
- Collects conversation events and parses them into a trace
|
||||
- Checks the trace against an Invariant policy to classify risk (low, medium, high)
|
||||
- Manages an Invariant server container automatically if needed
|
||||
- Supports optional browsing-alignment and harmful-content checks
|
||||
|
||||
## How It Works
|
||||
|
||||
1. **Action Analysis**: When the agent wants to perform an action, the selected security analyzer evaluates its risk level.
|
||||
|
||||
2. **Risk Assessment**: The analyzer returns one of three risk levels:
|
||||
- **LOW**: Action proceeds without confirmation
|
||||
- **MEDIUM**: Action proceeds without confirmation (may be configurable in future)
|
||||
- **HIGH**: Action is paused, and user confirmation is requested
|
||||
|
||||
3. **User Confirmation**: For high-risk actions, a confirmation dialog appears with:
|
||||
- Description of the action
|
||||
- Risk assessment explanation
|
||||
- Options to approve or deny action
|
||||
|
||||
4. **Action Execution**: Based on user response:
|
||||
- **Approve**: Action proceeds as planned
|
||||
- **Deny**: Action is cancelled
|
||||
@@ -14,31 +14,21 @@ import { Conversation } from "#/api/open-hands.types";
|
||||
|
||||
// Mock hooks
|
||||
const mockUseUserProviders = vi.fn();
|
||||
const mockUseGitRepositories = vi.fn();
|
||||
const mockUseUserRepositories = vi.fn();
|
||||
const mockUseConfig = vi.fn();
|
||||
const mockUseRepositoryMicroagents = vi.fn();
|
||||
const mockUseSearchConversations = vi.fn();
|
||||
|
||||
vi.mock("#/hooks/use-user-providers", () => ({
|
||||
useUserProviders: () => mockUseUserProviders(),
|
||||
}));
|
||||
|
||||
vi.mock("#/hooks/query/use-git-repositories", () => ({
|
||||
useGitRepositories: () => mockUseGitRepositories(),
|
||||
vi.mock("#/hooks/query/use-user-repositories", () => ({
|
||||
useUserRepositories: () => mockUseUserRepositories(),
|
||||
}));
|
||||
|
||||
vi.mock("#/hooks/query/use-config", () => ({
|
||||
useConfig: () => mockUseConfig(),
|
||||
}));
|
||||
|
||||
vi.mock("#/hooks/query/use-repository-microagents", () => ({
|
||||
useRepositoryMicroagents: () => mockUseRepositoryMicroagents(),
|
||||
}));
|
||||
|
||||
vi.mock("#/hooks/query/use-search-conversations", () => ({
|
||||
useSearchConversations: () => mockUseSearchConversations(),
|
||||
}));
|
||||
|
||||
describe("MicroagentManagement", () => {
|
||||
const RouterStub = createRoutesStub([
|
||||
{
|
||||
@@ -184,7 +174,7 @@ describe("MicroagentManagement", () => {
|
||||
providers: ["github"],
|
||||
});
|
||||
|
||||
mockUseGitRepositories.mockReturnValue({
|
||||
mockUseUserRepositories.mockReturnValue({
|
||||
data: {
|
||||
pages: [
|
||||
{
|
||||
@@ -206,18 +196,6 @@ describe("MicroagentManagement", () => {
|
||||
},
|
||||
});
|
||||
|
||||
mockUseRepositoryMicroagents.mockReturnValue({
|
||||
data: mockMicroagents,
|
||||
isLoading: false,
|
||||
isError: false,
|
||||
});
|
||||
|
||||
mockUseSearchConversations.mockReturnValue({
|
||||
data: mockConversations,
|
||||
isLoading: false,
|
||||
isError: false,
|
||||
});
|
||||
|
||||
// Setup default mock for retrieveUserGitRepositories
|
||||
vi.spyOn(OpenHands, "retrieveUserGitRepositories").mockResolvedValue({
|
||||
data: [...mockRepositories],
|
||||
@@ -249,7 +227,7 @@ describe("MicroagentManagement", () => {
|
||||
|
||||
it("should display loading state when fetching repositories", async () => {
|
||||
// Mock loading state
|
||||
mockUseGitRepositories.mockReturnValue({
|
||||
mockUseUserRepositories.mockReturnValue({
|
||||
data: undefined,
|
||||
isLoading: true,
|
||||
isError: false,
|
||||
@@ -267,7 +245,7 @@ describe("MicroagentManagement", () => {
|
||||
|
||||
it("should handle error when fetching repositories", async () => {
|
||||
// Mock error state
|
||||
mockUseGitRepositories.mockReturnValue({
|
||||
mockUseUserRepositories.mockReturnValue({
|
||||
data: undefined,
|
||||
isLoading: false,
|
||||
isError: true,
|
||||
@@ -280,7 +258,7 @@ describe("MicroagentManagement", () => {
|
||||
|
||||
// Wait for the error to be handled
|
||||
await waitFor(() => {
|
||||
expect(mockUseGitRepositories).toHaveBeenCalled();
|
||||
expect(mockUseUserRepositories).toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
|
||||
@@ -289,7 +267,7 @@ describe("MicroagentManagement", () => {
|
||||
|
||||
// Wait for repositories to be loaded
|
||||
await waitFor(() => {
|
||||
expect(mockUseGitRepositories).toHaveBeenCalled();
|
||||
expect(mockUseUserRepositories).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
// Check that tabs are rendered
|
||||
@@ -307,7 +285,7 @@ describe("MicroagentManagement", () => {
|
||||
|
||||
// Wait for repositories to be loaded and rendered
|
||||
await waitFor(() => {
|
||||
expect(mockUseGitRepositories).toHaveBeenCalled();
|
||||
expect(mockUseUserRepositories).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
// Check that repository names are displayed
|
||||
@@ -322,7 +300,7 @@ describe("MicroagentManagement", () => {
|
||||
|
||||
// Wait for repositories to be loaded
|
||||
await waitFor(() => {
|
||||
expect(mockUseGitRepositories).toHaveBeenCalled();
|
||||
expect(mockUseUserRepositories).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
// Find and click on the first repository accordion
|
||||
@@ -331,7 +309,10 @@ describe("MicroagentManagement", () => {
|
||||
|
||||
// Wait for microagents to be fetched
|
||||
await waitFor(() => {
|
||||
expect(mockUseRepositoryMicroagents).toHaveBeenCalled();
|
||||
expect(OpenHands.getRepositoryMicroagents).toHaveBeenCalledWith(
|
||||
"user",
|
||||
"repo2",
|
||||
);
|
||||
});
|
||||
|
||||
// Check that microagents are displayed
|
||||
@@ -344,17 +325,19 @@ describe("MicroagentManagement", () => {
|
||||
|
||||
it("should display loading state when fetching microagents", async () => {
|
||||
const user = userEvent.setup();
|
||||
mockUseRepositoryMicroagents.mockReturnValue({
|
||||
data: undefined,
|
||||
isLoading: true,
|
||||
isError: false,
|
||||
});
|
||||
const getRepositoryMicroagentsSpy = vi.spyOn(
|
||||
OpenHands,
|
||||
"getRepositoryMicroagents",
|
||||
);
|
||||
getRepositoryMicroagentsSpy.mockImplementation(
|
||||
() => new Promise(() => {}), // Never resolves
|
||||
);
|
||||
|
||||
renderMicroagentManagement();
|
||||
|
||||
// Wait for repositories to be loaded
|
||||
await waitFor(() => {
|
||||
expect(mockUseGitRepositories).toHaveBeenCalled();
|
||||
expect(mockUseUserRepositories).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
// Find and click on the first repository accordion
|
||||
@@ -367,17 +350,19 @@ describe("MicroagentManagement", () => {
|
||||
|
||||
it("should handle error when fetching microagents", async () => {
|
||||
const user = userEvent.setup();
|
||||
mockUseRepositoryMicroagents.mockReturnValue({
|
||||
data: undefined,
|
||||
isLoading: false,
|
||||
isError: true,
|
||||
});
|
||||
const getRepositoryMicroagentsSpy = vi.spyOn(
|
||||
OpenHands,
|
||||
"getRepositoryMicroagents",
|
||||
);
|
||||
getRepositoryMicroagentsSpy.mockRejectedValue(
|
||||
new Error("Failed to fetch microagents"),
|
||||
);
|
||||
|
||||
renderMicroagentManagement();
|
||||
|
||||
// Wait for repositories to be loaded
|
||||
await waitFor(() => {
|
||||
expect(mockUseGitRepositories).toHaveBeenCalled();
|
||||
expect(mockUseUserRepositories).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
// Find and click on the first repository accordion
|
||||
@@ -386,23 +371,23 @@ describe("MicroagentManagement", () => {
|
||||
|
||||
// Wait for the error to be handled
|
||||
await waitFor(() => {
|
||||
expect(mockUseRepositoryMicroagents).toHaveBeenCalled();
|
||||
expect(getRepositoryMicroagentsSpy).toHaveBeenCalledWith("user", "repo2");
|
||||
});
|
||||
});
|
||||
|
||||
it("should display empty state when no microagents are found", async () => {
|
||||
const user = userEvent.setup();
|
||||
mockUseRepositoryMicroagents.mockReturnValue({
|
||||
data: [],
|
||||
isLoading: false,
|
||||
isError: false,
|
||||
});
|
||||
const getRepositoryMicroagentsSpy = vi.spyOn(
|
||||
OpenHands,
|
||||
"getRepositoryMicroagents",
|
||||
);
|
||||
getRepositoryMicroagentsSpy.mockResolvedValue([]);
|
||||
|
||||
renderMicroagentManagement();
|
||||
|
||||
// Wait for repositories to be loaded
|
||||
await waitFor(() => {
|
||||
expect(mockUseGitRepositories).toHaveBeenCalled();
|
||||
expect(mockUseUserRepositories).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
// Find and click on the first repository accordion
|
||||
@@ -411,7 +396,7 @@ describe("MicroagentManagement", () => {
|
||||
|
||||
// Wait for microagents to be fetched
|
||||
await waitFor(() => {
|
||||
expect(mockUseRepositoryMicroagents).toHaveBeenCalled();
|
||||
expect(getRepositoryMicroagentsSpy).toHaveBeenCalledWith("user", "repo2");
|
||||
});
|
||||
|
||||
// Check that no microagents are displayed
|
||||
@@ -425,7 +410,7 @@ describe("MicroagentManagement", () => {
|
||||
|
||||
// Wait for repositories to be loaded
|
||||
await waitFor(() => {
|
||||
expect(mockUseGitRepositories).toHaveBeenCalled();
|
||||
expect(mockUseUserRepositories).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
// Find and click on the first repository accordion
|
||||
@@ -434,7 +419,10 @@ describe("MicroagentManagement", () => {
|
||||
|
||||
// Wait for microagents to be fetched
|
||||
await waitFor(() => {
|
||||
expect(mockUseRepositoryMicroagents).toHaveBeenCalled();
|
||||
expect(OpenHands.getRepositoryMicroagents).toHaveBeenCalledWith(
|
||||
"user",
|
||||
"repo2",
|
||||
);
|
||||
});
|
||||
|
||||
// Check that microagent cards display correct information
|
||||
@@ -461,7 +449,7 @@ describe("MicroagentManagement", () => {
|
||||
|
||||
// Wait for repositories to be loaded and processed
|
||||
await waitFor(() => {
|
||||
expect(mockUseGitRepositories).toHaveBeenCalled();
|
||||
expect(mockUseUserRepositories).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
// Wait for repositories to be displayed in the accordion
|
||||
@@ -480,7 +468,7 @@ describe("MicroagentManagement", () => {
|
||||
|
||||
// Wait for repositories to be loaded and processed
|
||||
await waitFor(() => {
|
||||
expect(mockUseGitRepositories).toHaveBeenCalled();
|
||||
expect(mockUseUserRepositories).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
// Wait for repositories to be displayed in the accordion
|
||||
@@ -504,7 +492,7 @@ describe("MicroagentManagement", () => {
|
||||
|
||||
// Wait for repositories to be loaded
|
||||
await waitFor(() => {
|
||||
expect(mockUseGitRepositories).toHaveBeenCalled();
|
||||
expect(mockUseUserRepositories).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
// Find and click the first add microagent button
|
||||
@@ -525,7 +513,7 @@ describe("MicroagentManagement", () => {
|
||||
|
||||
it("should display empty state when no repositories are found", async () => {
|
||||
// Mock empty repositories
|
||||
mockUseGitRepositories.mockReturnValue({
|
||||
mockUseUserRepositories.mockReturnValue({
|
||||
data: {
|
||||
pages: [
|
||||
{
|
||||
@@ -545,7 +533,7 @@ describe("MicroagentManagement", () => {
|
||||
|
||||
// Wait for repositories to be loaded
|
||||
await waitFor(() => {
|
||||
expect(mockUseGitRepositories).toHaveBeenCalled();
|
||||
expect(mockUseUserRepositories).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
// Check that empty state messages are displayed
|
||||
@@ -562,7 +550,7 @@ describe("MicroagentManagement", () => {
|
||||
|
||||
// Wait for repositories to be loaded
|
||||
await waitFor(() => {
|
||||
expect(mockUseGitRepositories).toHaveBeenCalled();
|
||||
expect(mockUseUserRepositories).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
// Find and click on the first repository accordion
|
||||
@@ -571,11 +559,14 @@ describe("MicroagentManagement", () => {
|
||||
|
||||
// Wait for microagents to be fetched for first repo
|
||||
await waitFor(() => {
|
||||
expect(mockUseRepositoryMicroagents).toHaveBeenCalled();
|
||||
expect(OpenHands.getRepositoryMicroagents).toHaveBeenCalledWith(
|
||||
"user",
|
||||
"repo2",
|
||||
);
|
||||
});
|
||||
|
||||
// Check that the hook was called
|
||||
expect(mockUseRepositoryMicroagents).toHaveBeenCalledTimes(1);
|
||||
// Check that the API call was made
|
||||
expect(OpenHands.getRepositoryMicroagents).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
|
||||
it("should display ready to add microagent message in main area", async () => {
|
||||
@@ -600,7 +591,7 @@ describe("MicroagentManagement", () => {
|
||||
|
||||
// Wait for repositories to be loaded
|
||||
await waitFor(() => {
|
||||
expect(mockUseGitRepositories).toHaveBeenCalled();
|
||||
expect(mockUseUserRepositories).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
// Check that search input is rendered
|
||||
@@ -620,7 +611,7 @@ describe("MicroagentManagement", () => {
|
||||
|
||||
// Wait for repositories to be loaded
|
||||
await waitFor(() => {
|
||||
expect(mockUseGitRepositories).toHaveBeenCalled();
|
||||
expect(mockUseUserRepositories).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
// Initially only repositories with .openhands should be visible
|
||||
@@ -651,7 +642,7 @@ describe("MicroagentManagement", () => {
|
||||
|
||||
// Wait for repositories to be loaded
|
||||
await waitFor(() => {
|
||||
expect(mockUseGitRepositories).toHaveBeenCalled();
|
||||
expect(mockUseUserRepositories).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
// Type in search input with uppercase
|
||||
@@ -674,7 +665,7 @@ describe("MicroagentManagement", () => {
|
||||
|
||||
// Wait for repositories to be loaded
|
||||
await waitFor(() => {
|
||||
expect(mockUseGitRepositories).toHaveBeenCalled();
|
||||
expect(mockUseUserRepositories).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
// Type in search input with partial match
|
||||
@@ -700,7 +691,7 @@ describe("MicroagentManagement", () => {
|
||||
|
||||
// Wait for repositories to be loaded
|
||||
await waitFor(() => {
|
||||
expect(mockUseGitRepositories).toHaveBeenCalled();
|
||||
expect(mockUseUserRepositories).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
// Type in search input
|
||||
@@ -733,7 +724,7 @@ describe("MicroagentManagement", () => {
|
||||
|
||||
// Wait for repositories to be loaded
|
||||
await waitFor(() => {
|
||||
expect(mockUseGitRepositories).toHaveBeenCalled();
|
||||
expect(mockUseUserRepositories).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
// Type in search input with non-existent repository name
|
||||
@@ -761,7 +752,7 @@ describe("MicroagentManagement", () => {
|
||||
|
||||
// Wait for repositories to be loaded
|
||||
await waitFor(() => {
|
||||
expect(mockUseGitRepositories).toHaveBeenCalled();
|
||||
expect(mockUseUserRepositories).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
// Type in search input with special characters
|
||||
@@ -782,7 +773,7 @@ describe("MicroagentManagement", () => {
|
||||
|
||||
// Wait for repositories to be loaded
|
||||
await waitFor(() => {
|
||||
expect(mockUseGitRepositories).toHaveBeenCalled();
|
||||
expect(mockUseUserRepositories).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
// Filter to show only repo2
|
||||
@@ -797,7 +788,10 @@ describe("MicroagentManagement", () => {
|
||||
|
||||
// Wait for microagents to be fetched
|
||||
await waitFor(() => {
|
||||
expect(mockUseRepositoryMicroagents).toHaveBeenCalled();
|
||||
expect(OpenHands.getRepositoryMicroagents).toHaveBeenCalledWith(
|
||||
"user",
|
||||
"repo2",
|
||||
);
|
||||
});
|
||||
|
||||
// Check that microagents are displayed
|
||||
@@ -814,7 +808,7 @@ describe("MicroagentManagement", () => {
|
||||
|
||||
// Wait for repositories to be loaded
|
||||
await waitFor(() => {
|
||||
expect(mockUseGitRepositories).toHaveBeenCalled();
|
||||
expect(mockUseUserRepositories).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
// Type in search input with leading/trailing whitespace
|
||||
@@ -834,7 +828,7 @@ describe("MicroagentManagement", () => {
|
||||
|
||||
// Wait for repositories to be loaded
|
||||
await waitFor(() => {
|
||||
expect(mockUseGitRepositories).toHaveBeenCalled();
|
||||
expect(mockUseUserRepositories).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
const searchInput = screen.getByRole("textbox", {
|
||||
@@ -866,7 +860,7 @@ describe("MicroagentManagement", () => {
|
||||
|
||||
// Wait for repositories to be loaded
|
||||
await waitFor(() => {
|
||||
expect(mockUseGitRepositories).toHaveBeenCalled();
|
||||
expect(mockUseUserRepositories).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
// Find and click on the first repository accordion
|
||||
@@ -875,8 +869,15 @@ describe("MicroagentManagement", () => {
|
||||
|
||||
// Wait for both microagents and conversations to be fetched
|
||||
await waitFor(() => {
|
||||
expect(mockUseRepositoryMicroagents).toHaveBeenCalled();
|
||||
expect(mockUseSearchConversations).toHaveBeenCalled();
|
||||
expect(OpenHands.getRepositoryMicroagents).toHaveBeenCalledWith(
|
||||
"user",
|
||||
"repo2",
|
||||
);
|
||||
expect(OpenHands.searchConversations).toHaveBeenCalledWith(
|
||||
"user/repo2/.openhands",
|
||||
"microagent_management",
|
||||
1000,
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -886,7 +887,7 @@ describe("MicroagentManagement", () => {
|
||||
|
||||
// Wait for repositories to be loaded
|
||||
await waitFor(() => {
|
||||
expect(mockUseGitRepositories).toHaveBeenCalled();
|
||||
expect(mockUseUserRepositories).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
// Find and click on the first repository accordion
|
||||
@@ -895,8 +896,8 @@ describe("MicroagentManagement", () => {
|
||||
|
||||
// Wait for both queries to complete
|
||||
await waitFor(() => {
|
||||
expect(mockUseRepositoryMicroagents).toHaveBeenCalled();
|
||||
expect(mockUseSearchConversations).toHaveBeenCalled();
|
||||
expect(OpenHands.getRepositoryMicroagents).toHaveBeenCalled();
|
||||
expect(OpenHands.searchConversations).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
// Check that microagents are displayed
|
||||
@@ -916,22 +917,23 @@ describe("MicroagentManagement", () => {
|
||||
|
||||
it("should show loading state when both microagents and conversations are loading", async () => {
|
||||
const user = userEvent.setup();
|
||||
mockUseRepositoryMicroagents.mockReturnValue({
|
||||
data: undefined,
|
||||
isLoading: true,
|
||||
isError: false,
|
||||
});
|
||||
mockUseSearchConversations.mockReturnValue({
|
||||
data: undefined,
|
||||
isLoading: true,
|
||||
isError: false,
|
||||
});
|
||||
const getRepositoryMicroagentsSpy = vi.spyOn(
|
||||
OpenHands,
|
||||
"getRepositoryMicroagents",
|
||||
);
|
||||
const searchConversationsSpy = vi.spyOn(OpenHands, "searchConversations");
|
||||
|
||||
// Make both queries never resolve
|
||||
getRepositoryMicroagentsSpy.mockImplementation(
|
||||
() => new Promise(() => {}),
|
||||
);
|
||||
searchConversationsSpy.mockImplementation(() => new Promise(() => {}));
|
||||
|
||||
renderMicroagentManagement();
|
||||
|
||||
// Wait for repositories to be loaded
|
||||
await waitFor(() => {
|
||||
expect(mockUseGitRepositories).toHaveBeenCalled();
|
||||
expect(mockUseUserRepositories).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
// Find and click on the first repository accordion
|
||||
@@ -948,7 +950,7 @@ describe("MicroagentManagement", () => {
|
||||
|
||||
// Wait for repositories to be loaded
|
||||
await waitFor(() => {
|
||||
expect(mockUseGitRepositories).toHaveBeenCalled();
|
||||
expect(mockUseUserRepositories).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
// Find and click on the first repository accordion
|
||||
@@ -957,8 +959,8 @@ describe("MicroagentManagement", () => {
|
||||
|
||||
// Wait for both queries to complete
|
||||
await waitFor(() => {
|
||||
expect(mockUseRepositoryMicroagents).toHaveBeenCalled();
|
||||
expect(mockUseSearchConversations).toHaveBeenCalled();
|
||||
expect(OpenHands.getRepositoryMicroagents).toHaveBeenCalled();
|
||||
expect(OpenHands.searchConversations).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
// Check that loading spinner is not displayed
|
||||
@@ -973,7 +975,7 @@ describe("MicroagentManagement", () => {
|
||||
|
||||
// Wait for repositories to be loaded
|
||||
await waitFor(() => {
|
||||
expect(mockUseGitRepositories).toHaveBeenCalled();
|
||||
expect(mockUseUserRepositories).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
// Find and click on the first repository accordion
|
||||
@@ -982,8 +984,8 @@ describe("MicroagentManagement", () => {
|
||||
|
||||
// Wait for both queries to complete
|
||||
await waitFor(() => {
|
||||
expect(mockUseRepositoryMicroagents).toHaveBeenCalled();
|
||||
expect(mockUseSearchConversations).toHaveBeenCalled();
|
||||
expect(OpenHands.getRepositoryMicroagents).toHaveBeenCalled();
|
||||
expect(OpenHands.searchConversations).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
// Check that microagent file paths are displayed for microagents
|
||||
@@ -1008,22 +1010,21 @@ describe("MicroagentManagement", () => {
|
||||
|
||||
it("should show learn this repo component when no microagents and no conversations", async () => {
|
||||
const user = userEvent.setup();
|
||||
mockUseRepositoryMicroagents.mockReturnValue({
|
||||
data: [],
|
||||
isLoading: false,
|
||||
isError: false,
|
||||
});
|
||||
mockUseSearchConversations.mockReturnValue({
|
||||
data: [],
|
||||
isLoading: false,
|
||||
isError: false,
|
||||
});
|
||||
const getRepositoryMicroagentsSpy = vi.spyOn(
|
||||
OpenHands,
|
||||
"getRepositoryMicroagents",
|
||||
);
|
||||
const searchConversationsSpy = vi.spyOn(OpenHands, "searchConversations");
|
||||
|
||||
// Mock both queries to return empty arrays
|
||||
getRepositoryMicroagentsSpy.mockResolvedValue([]);
|
||||
searchConversationsSpy.mockResolvedValue([]);
|
||||
|
||||
renderMicroagentManagement();
|
||||
|
||||
// Wait for repositories to be loaded
|
||||
await waitFor(() => {
|
||||
expect(mockUseGitRepositories).toHaveBeenCalled();
|
||||
expect(mockUseUserRepositories).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
// Find and click on the first repository accordion
|
||||
@@ -1032,8 +1033,8 @@ describe("MicroagentManagement", () => {
|
||||
|
||||
// Wait for both queries to complete
|
||||
await waitFor(() => {
|
||||
expect(mockUseRepositoryMicroagents).toHaveBeenCalled();
|
||||
expect(mockUseSearchConversations).toHaveBeenCalled();
|
||||
expect(getRepositoryMicroagentsSpy).toHaveBeenCalled();
|
||||
expect(searchConversationsSpy).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
// Check that the learn this repo component is displayed
|
||||
@@ -1045,22 +1046,21 @@ describe("MicroagentManagement", () => {
|
||||
|
||||
it("should show learn this repo component when only conversations exist but no microagents", async () => {
|
||||
const user = userEvent.setup();
|
||||
mockUseRepositoryMicroagents.mockReturnValue({
|
||||
data: [],
|
||||
isLoading: false,
|
||||
isError: false,
|
||||
});
|
||||
mockUseSearchConversations.mockReturnValue({
|
||||
data: [...mockConversations],
|
||||
isLoading: false,
|
||||
isError: false,
|
||||
});
|
||||
const getRepositoryMicroagentsSpy = vi.spyOn(
|
||||
OpenHands,
|
||||
"getRepositoryMicroagents",
|
||||
);
|
||||
const searchConversationsSpy = vi.spyOn(OpenHands, "searchConversations");
|
||||
|
||||
// Mock microagents to return empty array, conversations to return data
|
||||
getRepositoryMicroagentsSpy.mockResolvedValue([]);
|
||||
searchConversationsSpy.mockResolvedValue([...mockConversations]);
|
||||
|
||||
renderMicroagentManagement();
|
||||
|
||||
// Wait for repositories to be loaded
|
||||
await waitFor(() => {
|
||||
expect(mockUseGitRepositories).toHaveBeenCalled();
|
||||
expect(mockUseUserRepositories).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
// Find and click on the first repository accordion
|
||||
@@ -1069,8 +1069,8 @@ describe("MicroagentManagement", () => {
|
||||
|
||||
// Wait for both queries to complete
|
||||
await waitFor(() => {
|
||||
expect(mockUseRepositoryMicroagents).toHaveBeenCalled();
|
||||
expect(mockUseSearchConversations).toHaveBeenCalled();
|
||||
expect(getRepositoryMicroagentsSpy).toHaveBeenCalled();
|
||||
expect(searchConversationsSpy).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
// Check that conversations are displayed
|
||||
@@ -1088,22 +1088,21 @@ describe("MicroagentManagement", () => {
|
||||
|
||||
it("should show learn this repo component when only microagents exist but no conversations", async () => {
|
||||
const user = userEvent.setup();
|
||||
mockUseRepositoryMicroagents.mockReturnValue({
|
||||
data: [...mockMicroagents],
|
||||
isLoading: false,
|
||||
isError: false,
|
||||
});
|
||||
mockUseSearchConversations.mockReturnValue({
|
||||
data: [],
|
||||
isLoading: false,
|
||||
isError: false,
|
||||
});
|
||||
const getRepositoryMicroagentsSpy = vi.spyOn(
|
||||
OpenHands,
|
||||
"getRepositoryMicroagents",
|
||||
);
|
||||
const searchConversationsSpy = vi.spyOn(OpenHands, "searchConversations");
|
||||
|
||||
// Mock microagents to return data, conversations to return empty array
|
||||
getRepositoryMicroagentsSpy.mockResolvedValue([...mockMicroagents]);
|
||||
searchConversationsSpy.mockResolvedValue([]);
|
||||
|
||||
renderMicroagentManagement();
|
||||
|
||||
// Wait for repositories to be loaded
|
||||
await waitFor(() => {
|
||||
expect(mockUseGitRepositories).toHaveBeenCalled();
|
||||
expect(mockUseUserRepositories).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
// Find and click on the first repository accordion
|
||||
@@ -1112,8 +1111,8 @@ describe("MicroagentManagement", () => {
|
||||
|
||||
// Wait for both queries to complete
|
||||
await waitFor(() => {
|
||||
expect(mockUseRepositoryMicroagents).toHaveBeenCalled();
|
||||
expect(mockUseSearchConversations).toHaveBeenCalled();
|
||||
expect(getRepositoryMicroagentsSpy).toHaveBeenCalled();
|
||||
expect(searchConversationsSpy).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
// Check that microagents are displayed
|
||||
@@ -1131,17 +1130,16 @@ describe("MicroagentManagement", () => {
|
||||
|
||||
it("should handle error when fetching conversations", async () => {
|
||||
const user = userEvent.setup();
|
||||
mockUseSearchConversations.mockReturnValue({
|
||||
data: undefined,
|
||||
isLoading: false,
|
||||
isError: true,
|
||||
});
|
||||
const searchConversationsSpy = vi.spyOn(OpenHands, "searchConversations");
|
||||
searchConversationsSpy.mockRejectedValue(
|
||||
new Error("Failed to fetch conversations"),
|
||||
);
|
||||
|
||||
renderMicroagentManagement();
|
||||
|
||||
// Wait for repositories to be loaded
|
||||
await waitFor(() => {
|
||||
expect(mockUseGitRepositories).toHaveBeenCalled();
|
||||
expect(mockUseUserRepositories).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
// Find and click on the first repository accordion
|
||||
@@ -1150,7 +1148,11 @@ describe("MicroagentManagement", () => {
|
||||
|
||||
// Wait for the error to be handled
|
||||
await waitFor(() => {
|
||||
expect(mockUseSearchConversations).toHaveBeenCalled();
|
||||
expect(searchConversationsSpy).toHaveBeenCalledWith(
|
||||
"user/repo2/.openhands",
|
||||
"microagent_management",
|
||||
1000,
|
||||
);
|
||||
});
|
||||
|
||||
// Check that the learn this repo component is displayed (since conversations failed)
|
||||
@@ -1161,22 +1163,27 @@ describe("MicroagentManagement", () => {
|
||||
});
|
||||
|
||||
// Also check that the microagents query was called successfully
|
||||
expect(mockUseRepositoryMicroagents).toHaveBeenCalled();
|
||||
expect(OpenHands.getRepositoryMicroagents).toHaveBeenCalledWith(
|
||||
"user",
|
||||
"repo2",
|
||||
);
|
||||
});
|
||||
|
||||
it("should handle error when fetching microagents but conversations succeed", async () => {
|
||||
const user = userEvent.setup();
|
||||
mockUseRepositoryMicroagents.mockReturnValue({
|
||||
data: undefined,
|
||||
isLoading: false,
|
||||
isError: true,
|
||||
});
|
||||
const getRepositoryMicroagentsSpy = vi.spyOn(
|
||||
OpenHands,
|
||||
"getRepositoryMicroagents",
|
||||
);
|
||||
getRepositoryMicroagentsSpy.mockRejectedValue(
|
||||
new Error("Failed to fetch microagents"),
|
||||
);
|
||||
|
||||
renderMicroagentManagement();
|
||||
|
||||
// Wait for repositories to be loaded
|
||||
await waitFor(() => {
|
||||
expect(mockUseGitRepositories).toHaveBeenCalled();
|
||||
expect(mockUseUserRepositories).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
// Find and click on the first repository accordion
|
||||
@@ -1185,7 +1192,10 @@ describe("MicroagentManagement", () => {
|
||||
|
||||
// Wait for the error to be handled
|
||||
await waitFor(() => {
|
||||
expect(mockUseRepositoryMicroagents).toHaveBeenCalled();
|
||||
expect(getRepositoryMicroagentsSpy).toHaveBeenCalledWith(
|
||||
"user",
|
||||
"repo2",
|
||||
);
|
||||
});
|
||||
|
||||
// Check that the learn this repo component is displayed (since microagents failed)
|
||||
@@ -1197,11 +1207,13 @@ describe("MicroagentManagement", () => {
|
||||
|
||||
it("should call searchConversations with correct parameters", async () => {
|
||||
const user = userEvent.setup();
|
||||
const searchConversationsSpy = vi.spyOn(OpenHands, "searchConversations");
|
||||
|
||||
renderMicroagentManagement();
|
||||
|
||||
// Wait for repositories to be loaded
|
||||
await waitFor(() => {
|
||||
expect(mockUseGitRepositories).toHaveBeenCalled();
|
||||
expect(mockUseUserRepositories).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
// Find and click on the first repository accordion
|
||||
@@ -1210,7 +1222,11 @@ describe("MicroagentManagement", () => {
|
||||
|
||||
// Wait for searchConversations to be called
|
||||
await waitFor(() => {
|
||||
expect(mockUseSearchConversations).toHaveBeenCalled();
|
||||
expect(searchConversationsSpy).toHaveBeenCalledWith(
|
||||
"user/repo2/.openhands",
|
||||
"microagent_management",
|
||||
1000,
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1220,7 +1236,7 @@ describe("MicroagentManagement", () => {
|
||||
|
||||
// Wait for repositories to be loaded
|
||||
await waitFor(() => {
|
||||
expect(mockUseGitRepositories).toHaveBeenCalled();
|
||||
expect(mockUseUserRepositories).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
// Find and click on the first repository accordion
|
||||
@@ -1229,8 +1245,8 @@ describe("MicroagentManagement", () => {
|
||||
|
||||
// Wait for both queries to complete
|
||||
await waitFor(() => {
|
||||
expect(mockUseRepositoryMicroagents).toHaveBeenCalled();
|
||||
expect(mockUseSearchConversations).toHaveBeenCalled();
|
||||
expect(OpenHands.getRepositoryMicroagents).toHaveBeenCalled();
|
||||
expect(OpenHands.searchConversations).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
// Check that conversations display correct information
|
||||
@@ -1247,7 +1263,7 @@ describe("MicroagentManagement", () => {
|
||||
|
||||
// Wait for repositories to be loaded
|
||||
await waitFor(() => {
|
||||
expect(mockUseGitRepositories).toHaveBeenCalled();
|
||||
expect(mockUseUserRepositories).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
// Find and click on the first repository accordion
|
||||
@@ -1256,8 +1272,15 @@ describe("MicroagentManagement", () => {
|
||||
|
||||
// Wait for both queries to be called for first repo
|
||||
await waitFor(() => {
|
||||
expect(mockUseRepositoryMicroagents).toHaveBeenCalled();
|
||||
expect(mockUseSearchConversations).toHaveBeenCalled();
|
||||
expect(OpenHands.getRepositoryMicroagents).toHaveBeenCalledWith(
|
||||
"user",
|
||||
"repo2",
|
||||
);
|
||||
expect(OpenHands.searchConversations).toHaveBeenCalledWith(
|
||||
"user/repo2/.openhands",
|
||||
"microagent_management",
|
||||
1000,
|
||||
);
|
||||
});
|
||||
|
||||
// Check that both microagents and conversations are displayed
|
||||
@@ -1281,7 +1304,7 @@ describe("MicroagentManagement", () => {
|
||||
|
||||
// Wait for repositories to be loaded and processed
|
||||
await waitFor(() => {
|
||||
expect(mockUseGitRepositories).toHaveBeenCalled();
|
||||
expect(mockUseUserRepositories).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
// Wait for repositories to be displayed in the accordion
|
||||
@@ -1302,7 +1325,7 @@ describe("MicroagentManagement", () => {
|
||||
|
||||
// Wait for repositories to be loaded and processed
|
||||
await waitFor(() => {
|
||||
expect(mockUseGitRepositories).toHaveBeenCalled();
|
||||
expect(mockUseUserRepositories).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
// Wait for repositories to be displayed in the accordion
|
||||
@@ -1364,7 +1387,7 @@ describe("MicroagentManagement", () => {
|
||||
|
||||
// Wait for repositories to be loaded and processed
|
||||
await waitFor(() => {
|
||||
expect(mockUseGitRepositories).toHaveBeenCalled();
|
||||
expect(mockUseUserRepositories).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
// Wait for repositories to be displayed in the accordion
|
||||
@@ -1395,7 +1418,7 @@ describe("MicroagentManagement", () => {
|
||||
|
||||
// Wait for repositories to be loaded and processed
|
||||
await waitFor(() => {
|
||||
expect(mockUseGitRepositories).toHaveBeenCalled();
|
||||
expect(mockUseUserRepositories).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
// Wait for repositories to be displayed in the accordion
|
||||
@@ -1425,7 +1448,7 @@ describe("MicroagentManagement", () => {
|
||||
|
||||
// Wait for repositories to be loaded and processed
|
||||
await waitFor(() => {
|
||||
expect(mockUseGitRepositories).toHaveBeenCalled();
|
||||
expect(mockUseUserRepositories).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
// Wait for repositories to be displayed in the accordion
|
||||
@@ -1465,7 +1488,7 @@ describe("MicroagentManagement", () => {
|
||||
|
||||
// Wait for repositories to be loaded and processed
|
||||
await waitFor(() => {
|
||||
expect(mockUseGitRepositories).toHaveBeenCalled();
|
||||
expect(mockUseUserRepositories).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
// Wait for repositories to be displayed in the accordion
|
||||
@@ -1499,7 +1522,7 @@ describe("MicroagentManagement", () => {
|
||||
|
||||
// Wait for repositories to be loaded and processed
|
||||
await waitFor(() => {
|
||||
expect(mockUseGitRepositories).toHaveBeenCalled();
|
||||
expect(mockUseUserRepositories).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
// Wait for repositories to be displayed in the accordion
|
||||
@@ -1532,7 +1555,7 @@ describe("MicroagentManagement", () => {
|
||||
|
||||
// Wait for repositories to be loaded and processed
|
||||
await waitFor(() => {
|
||||
expect(mockUseGitRepositories).toHaveBeenCalled();
|
||||
expect(mockUseUserRepositories).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
// Wait for repositories to be displayed in the accordion
|
||||
@@ -2386,22 +2409,19 @@ describe("MicroagentManagement", () => {
|
||||
const user = userEvent.setup();
|
||||
|
||||
// Setup mocks before rendering
|
||||
mockUseRepositoryMicroagents.mockReturnValue({
|
||||
data: [],
|
||||
isLoading: false,
|
||||
isError: false,
|
||||
});
|
||||
mockUseSearchConversations.mockReturnValue({
|
||||
data: [],
|
||||
isLoading: false,
|
||||
isError: false,
|
||||
});
|
||||
const getRepositoryMicroagentsSpy = vi.spyOn(
|
||||
OpenHands,
|
||||
"getRepositoryMicroagents",
|
||||
);
|
||||
const searchConversationsSpy = vi.spyOn(OpenHands, "searchConversations");
|
||||
getRepositoryMicroagentsSpy.mockResolvedValue([]);
|
||||
searchConversationsSpy.mockResolvedValue([]);
|
||||
|
||||
renderMicroagentManagement();
|
||||
|
||||
// Wait for repositories to be loaded
|
||||
await waitFor(() => {
|
||||
expect(mockUseGitRepositories).toHaveBeenCalled();
|
||||
expect(mockUseUserRepositories).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
// Find and click on the first repository accordion to expand it
|
||||
@@ -2410,8 +2430,8 @@ describe("MicroagentManagement", () => {
|
||||
|
||||
// Wait for microagents and conversations to be fetched
|
||||
await waitFor(() => {
|
||||
expect(mockUseRepositoryMicroagents).toHaveBeenCalled();
|
||||
expect(mockUseSearchConversations).toHaveBeenCalled();
|
||||
expect(getRepositoryMicroagentsSpy).toHaveBeenCalled();
|
||||
expect(searchConversationsSpy).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
// Verify the learn this repo trigger is displayed when no microagents exist
|
||||
@@ -2431,22 +2451,19 @@ describe("MicroagentManagement", () => {
|
||||
const user = userEvent.setup();
|
||||
|
||||
// Setup mocks
|
||||
mockUseRepositoryMicroagents.mockReturnValue({
|
||||
data: [],
|
||||
isLoading: false,
|
||||
isError: false,
|
||||
});
|
||||
mockUseSearchConversations.mockReturnValue({
|
||||
data: [],
|
||||
isLoading: false,
|
||||
isError: false,
|
||||
});
|
||||
const getRepositoryMicroagentsSpy = vi.spyOn(
|
||||
OpenHands,
|
||||
"getRepositoryMicroagents",
|
||||
);
|
||||
const searchConversationsSpy = vi.spyOn(OpenHands, "searchConversations");
|
||||
getRepositoryMicroagentsSpy.mockResolvedValue([]);
|
||||
searchConversationsSpy.mockResolvedValue([]);
|
||||
|
||||
renderMicroagentManagement();
|
||||
|
||||
// Wait for repositories and expand accordion
|
||||
await waitFor(() => {
|
||||
expect(mockUseGitRepositories).toHaveBeenCalled();
|
||||
expect(mockUseUserRepositories).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
const repoAccordion = screen.getByTestId("repository-name-tooltip");
|
||||
@@ -2479,36 +2496,35 @@ describe("MicroagentManagement", () => {
|
||||
const user = userEvent.setup();
|
||||
|
||||
// Setup mocks with existing microagents (should NOT show trigger)
|
||||
mockUseRepositoryMicroagents.mockReturnValue({
|
||||
data: [
|
||||
{
|
||||
name: "test-microagent",
|
||||
created_at: "2021-10-01",
|
||||
git_provider: "github",
|
||||
path: ".openhands/microagents/test",
|
||||
},
|
||||
],
|
||||
isLoading: false,
|
||||
isError: false,
|
||||
});
|
||||
mockUseSearchConversations.mockReturnValue({
|
||||
data: [],
|
||||
isLoading: false,
|
||||
isError: false,
|
||||
});
|
||||
const getRepositoryMicroagentsSpy = vi.spyOn(
|
||||
OpenHands,
|
||||
"getRepositoryMicroagents",
|
||||
);
|
||||
const searchConversationsSpy = vi.spyOn(OpenHands, "searchConversations");
|
||||
|
||||
// Mock with existing microagent
|
||||
getRepositoryMicroagentsSpy.mockResolvedValue([
|
||||
{
|
||||
name: "test-microagent",
|
||||
created_at: "2021-10-01",
|
||||
git_provider: "github",
|
||||
path: ".openhands/microagents/test",
|
||||
},
|
||||
]);
|
||||
searchConversationsSpy.mockResolvedValue([]);
|
||||
|
||||
renderMicroagentManagement();
|
||||
|
||||
await waitFor(() => {
|
||||
expect(mockUseGitRepositories).toHaveBeenCalled();
|
||||
expect(mockUseUserRepositories).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
const repoAccordion = screen.getByTestId("repository-name-tooltip");
|
||||
await user.click(repoAccordion);
|
||||
|
||||
await waitFor(() => {
|
||||
expect(mockUseRepositoryMicroagents).toHaveBeenCalled();
|
||||
expect(mockUseSearchConversations).toHaveBeenCalled();
|
||||
expect(getRepositoryMicroagentsSpy).toHaveBeenCalled();
|
||||
expect(searchConversationsSpy).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
// Should NOT show the learn this repo trigger when microagents exist
|
||||
|
||||
@@ -79,35 +79,6 @@ describe("Content", () => {
|
||||
expect(screen.getByTestId("set-indicator")).toBeInTheDocument();
|
||||
});
|
||||
});
|
||||
|
||||
it("should conditionally show security analyzer based on confirmation mode", async () => {
|
||||
renderLlmSettingsScreen();
|
||||
await screen.findByTestId("llm-settings-screen");
|
||||
|
||||
const confirmation = screen.getByTestId("enable-confirmation-mode-switch");
|
||||
|
||||
// Initially confirmation mode is false, so security analyzer should not be visible
|
||||
expect(confirmation).not.toBeChecked();
|
||||
expect(
|
||||
screen.queryByTestId("security-analyzer-input"),
|
||||
).not.toBeInTheDocument();
|
||||
|
||||
// Enable confirmation mode
|
||||
await userEvent.click(confirmation);
|
||||
expect(confirmation).toBeChecked();
|
||||
|
||||
// Security analyzer should now be visible
|
||||
screen.getByTestId("security-analyzer-input");
|
||||
|
||||
// Disable confirmation mode again
|
||||
await userEvent.click(confirmation);
|
||||
expect(confirmation).not.toBeChecked();
|
||||
|
||||
// Security analyzer should be hidden again
|
||||
expect(
|
||||
screen.queryByTestId("security-analyzer-input"),
|
||||
).not.toBeInTheDocument();
|
||||
});
|
||||
});
|
||||
|
||||
describe("Advanced form", () => {
|
||||
@@ -136,6 +107,7 @@ describe("Content", () => {
|
||||
within(advancedForm).getByTestId("llm-api-key-input");
|
||||
within(advancedForm).getByTestId("llm-api-key-help-anchor-advanced");
|
||||
within(advancedForm).getByTestId("agent-input");
|
||||
within(advancedForm).getByTestId("enable-confirmation-mode-switch");
|
||||
within(advancedForm).getByTestId("enable-memory-condenser-switch");
|
||||
|
||||
await userEvent.click(advancedSwitch);
|
||||
@@ -158,6 +130,9 @@ describe("Content", () => {
|
||||
const baseUrl = screen.getByTestId("base-url-input");
|
||||
const apiKey = screen.getByTestId("llm-api-key-input");
|
||||
const agent = screen.getByTestId("agent-input");
|
||||
const confirmation = screen.getByTestId(
|
||||
"enable-confirmation-mode-switch",
|
||||
);
|
||||
const condensor = screen.getByTestId("enable-memory-condenser-switch");
|
||||
|
||||
expect(model).toHaveValue("openhands/claude-sonnet-4-20250514");
|
||||
@@ -165,7 +140,15 @@ describe("Content", () => {
|
||||
expect(apiKey).toHaveValue("");
|
||||
expect(apiKey).toHaveProperty("placeholder", "");
|
||||
expect(agent).toHaveValue("CodeActAgent");
|
||||
expect(confirmation).not.toBeChecked();
|
||||
expect(condensor).toBeChecked();
|
||||
|
||||
// check that security analyzer is present
|
||||
expect(
|
||||
screen.queryByTestId("security-analyzer-input"),
|
||||
).not.toBeInTheDocument();
|
||||
await userEvent.click(confirmation);
|
||||
screen.getByTestId("security-analyzer-input");
|
||||
});
|
||||
|
||||
it("should render the advanced form if existings settings are advanced", async () => {
|
||||
@@ -194,7 +177,7 @@ describe("Content", () => {
|
||||
agent: "CoActAgent",
|
||||
confirmation_mode: true,
|
||||
enable_default_condenser: false,
|
||||
security_analyzer: "none",
|
||||
security_analyzer: "mock-invariant",
|
||||
});
|
||||
|
||||
renderLlmSettingsScreen();
|
||||
@@ -220,7 +203,7 @@ describe("Content", () => {
|
||||
expect(agent).toHaveValue("CoActAgent");
|
||||
expect(confirmation).toBeChecked();
|
||||
expect(condensor).not.toBeChecked();
|
||||
expect(securityAnalyzer).toHaveValue("SETTINGS$SECURITY_ANALYZER_NONE");
|
||||
expect(securityAnalyzer).toHaveValue("mock-invariant");
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -310,7 +293,7 @@ describe("Form submission", () => {
|
||||
// select security analyzer
|
||||
const securityAnalyzer = screen.getByTestId("security-analyzer-input");
|
||||
await userEvent.click(securityAnalyzer);
|
||||
const securityAnalyzerOption = screen.getByText("SETTINGS$SECURITY_ANALYZER_NONE");
|
||||
const securityAnalyzerOption = screen.getByText("mock-invariant");
|
||||
await userEvent.click(securityAnalyzerOption);
|
||||
|
||||
const submitButton = screen.getByTestId("submit-button");
|
||||
@@ -323,7 +306,7 @@ describe("Form submission", () => {
|
||||
agent: "CoActAgent",
|
||||
confirmation_mode: true,
|
||||
enable_default_condenser: false,
|
||||
security_analyzer: null,
|
||||
security_analyzer: "mock-invariant",
|
||||
}),
|
||||
);
|
||||
});
|
||||
@@ -392,10 +375,8 @@ describe("Form submission", () => {
|
||||
const baseUrl = await screen.findByTestId("base-url-input");
|
||||
const apiKey = await screen.findByTestId("llm-api-key-input");
|
||||
const agent = await screen.findByTestId("agent-input");
|
||||
const condensor = await screen.findByTestId("enable-memory-condenser-switch");
|
||||
|
||||
// Confirmation mode switch is now in basic settings, always visible
|
||||
const confirmation = await screen.findByTestId("enable-confirmation-mode-switch");
|
||||
const condensor = await screen.findByTestId("enable-memory-condenser-switch");
|
||||
|
||||
// enter custom model
|
||||
await userEvent.type(model, "-mini");
|
||||
@@ -470,17 +451,14 @@ describe("Form submission", () => {
|
||||
// select security analyzer
|
||||
const securityAnalyzer = await screen.findByTestId("security-analyzer-input");
|
||||
await userEvent.click(securityAnalyzer);
|
||||
const securityAnalyzerOption = screen.getByText("SETTINGS$SECURITY_ANALYZER_NONE");
|
||||
const securityAnalyzerOption = screen.getByText("mock-invariant");
|
||||
await userEvent.click(securityAnalyzerOption);
|
||||
expect(securityAnalyzer).toHaveValue("SETTINGS$SECURITY_ANALYZER_NONE");
|
||||
expect(securityAnalyzer).toHaveValue("mock-invariant");
|
||||
|
||||
expect(submitButton).not.toBeDisabled();
|
||||
|
||||
// revert back to original value
|
||||
await userEvent.click(securityAnalyzer);
|
||||
const originalSecurityAnalyzerOption = screen.getByText("SETTINGS$SECURITY_ANALYZER_LLM_DEFAULT");
|
||||
await userEvent.click(originalSecurityAnalyzerOption);
|
||||
expect(securityAnalyzer).toHaveValue("SETTINGS$SECURITY_ANALYZER_LLM_DEFAULT");
|
||||
await userEvent.clear(securityAnalyzer);
|
||||
expect(securityAnalyzer).toHaveValue("");
|
||||
expect(submitButton).toBeDisabled();
|
||||
});
|
||||
|
||||
@@ -574,7 +552,7 @@ describe("Form submission", () => {
|
||||
expect.objectContaining({
|
||||
llm_model: "openhands/claude-sonnet-4-20250514",
|
||||
llm_base_url: "",
|
||||
confirmation_mode: true, // Confirmation mode is now a basic setting, should be preserved
|
||||
confirmation_mode: false,
|
||||
}),
|
||||
);
|
||||
});
|
||||
|
||||
@@ -107,7 +107,9 @@ describe("Content", () => {
|
||||
expect(screen.queryByTestId("add-secret-button")).not.toBeInTheDocument(),
|
||||
);
|
||||
const button = await screen.findByTestId("connect-git-button");
|
||||
expect(button).toHaveAttribute("href", "/settings/integrations");
|
||||
await userEvent.click(button);
|
||||
|
||||
screen.getByTestId("git-settings-screen");
|
||||
});
|
||||
|
||||
it("should render an empty table when there are no existing secrets", async () => {
|
||||
|
||||
@@ -29,5 +29,23 @@ describe("hasAdvancedSettingsSet", () => {
|
||||
}),
|
||||
).toBe(true);
|
||||
});
|
||||
|
||||
test("CONFIRMATION_MODE is true", () => {
|
||||
expect(
|
||||
hasAdvancedSettingsSet({
|
||||
...DEFAULT_SETTINGS,
|
||||
CONFIRMATION_MODE: true,
|
||||
}),
|
||||
).toBe(true);
|
||||
});
|
||||
|
||||
test("SECURITY_ANALYZER is set", () => {
|
||||
expect(
|
||||
hasAdvancedSettingsSet({
|
||||
...DEFAULT_SETTINGS,
|
||||
SECURITY_ANALYZER: "test",
|
||||
}),
|
||||
).toBe(true);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
9
frontend/package-lock.json
generated
9
frontend/package-lock.json
generated
@@ -93,7 +93,7 @@
|
||||
"eslint-plugin-prettier": "^5.5.4",
|
||||
"eslint-plugin-react": "^7.37.5",
|
||||
"eslint-plugin-react-hooks": "^4.6.2",
|
||||
"eslint-plugin-unused-imports": "^4.2.0",
|
||||
"eslint-plugin-unused-imports": "^4.1.4",
|
||||
"husky": "^9.1.7",
|
||||
"jsdom": "^26.1.0",
|
||||
"lint-staged": "^16.1.4",
|
||||
@@ -9860,10 +9860,11 @@
|
||||
}
|
||||
},
|
||||
"node_modules/eslint-plugin-unused-imports": {
|
||||
"version": "4.2.0",
|
||||
"resolved": "https://registry.npmjs.org/eslint-plugin-unused-imports/-/eslint-plugin-unused-imports-4.2.0.tgz",
|
||||
"integrity": "sha512-hLbJ2/wnjKq4kGA9AUaExVFIbNzyxYdVo49QZmKCnhk5pc9wcYRbfgLHvWJ8tnsdcseGhoUAddm9gn/lt+d74w==",
|
||||
"version": "4.1.4",
|
||||
"resolved": "https://registry.npmjs.org/eslint-plugin-unused-imports/-/eslint-plugin-unused-imports-4.1.4.tgz",
|
||||
"integrity": "sha512-YptD6IzQjDardkl0POxnnRBhU1OEePMV0nd6siHaRBbd+lyh6NAhFEobiznKU7kTsSsDeSD62Pe7kAM1b7dAZQ==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"peerDependencies": {
|
||||
"@typescript-eslint/eslint-plugin": "^8.0.0-0 || ^7.0.0 || ^6.0.0 || ^5.0.0",
|
||||
"eslint": "^9.0.0 || ^8.0.0"
|
||||
|
||||
@@ -117,7 +117,7 @@
|
||||
"eslint-plugin-prettier": "^5.5.4",
|
||||
"eslint-plugin-react": "^7.37.5",
|
||||
"eslint-plugin-react-hooks": "^4.6.2",
|
||||
"eslint-plugin-unused-imports": "^4.2.0",
|
||||
"eslint-plugin-unused-imports": "^4.1.4",
|
||||
"husky": "^9.1.7",
|
||||
"jsdom": "^26.1.0",
|
||||
"lint-staged": "^16.1.4",
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
import { useMemo } from "react";
|
||||
import { StylesConfig } from "react-select";
|
||||
import { Provider } from "../../types/settings";
|
||||
import { ReactSelectDropdown, SelectOption } from "./react-select-dropdown";
|
||||
|
||||
@@ -12,8 +11,6 @@ export interface GitProviderDropdownProps {
|
||||
disabled?: boolean;
|
||||
isLoading?: boolean;
|
||||
onChange?: (provider: Provider | null) => void;
|
||||
classNamePrefix?: string;
|
||||
styles?: StylesConfig<SelectOption, false>;
|
||||
}
|
||||
|
||||
export function GitProviderDropdown({
|
||||
@@ -25,8 +22,6 @@ export function GitProviderDropdown({
|
||||
disabled = false,
|
||||
isLoading = false,
|
||||
onChange,
|
||||
classNamePrefix,
|
||||
styles,
|
||||
}: GitProviderDropdownProps) {
|
||||
const options: SelectOption[] = useMemo(
|
||||
() =>
|
||||
@@ -58,8 +53,6 @@ export function GitProviderDropdown({
|
||||
isSearchable={false}
|
||||
isLoading={isLoading}
|
||||
onChange={handleChange}
|
||||
classNamePrefix={classNamePrefix}
|
||||
styles={styles}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { useMemo } from "react";
|
||||
import Select, { StylesConfig } from "react-select";
|
||||
import Select from "react-select";
|
||||
import { cn } from "#/utils/utils";
|
||||
import { SelectOptionBase, getCustomStyles } from "./react-select-styles";
|
||||
|
||||
@@ -17,8 +17,6 @@ export interface ReactSelectDropdownProps {
|
||||
isSearchable?: boolean;
|
||||
isLoading?: boolean;
|
||||
onChange?: (option: SelectOption | null) => void;
|
||||
classNamePrefix?: string;
|
||||
styles?: StylesConfig<SelectOption, false>;
|
||||
}
|
||||
|
||||
export function ReactSelectDropdown({
|
||||
@@ -33,8 +31,6 @@ export function ReactSelectDropdown({
|
||||
isSearchable = true,
|
||||
isLoading = false,
|
||||
onChange,
|
||||
classNamePrefix,
|
||||
styles,
|
||||
}: ReactSelectDropdownProps) {
|
||||
const customStyles = useMemo(() => getCustomStyles<SelectOption>(), []);
|
||||
|
||||
@@ -50,9 +46,8 @@ export function ReactSelectDropdown({
|
||||
isSearchable={isSearchable}
|
||||
isLoading={isLoading}
|
||||
onChange={onChange}
|
||||
styles={styles || customStyles}
|
||||
styles={customStyles}
|
||||
className="w-full"
|
||||
classNamePrefix={classNamePrefix}
|
||||
/>
|
||||
{errorMessage && (
|
||||
<p className="text-red-500 text-sm mt-1">{errorMessage}</p>
|
||||
|
||||
@@ -90,26 +90,3 @@ export const getCustomStyles = <T extends SelectOptionBase>(): StylesConfig<
|
||||
color: "#B7BDC2", // tertiary-light
|
||||
}),
|
||||
});
|
||||
|
||||
export const getGitProviderMicroagentManagementCustomStyles = <
|
||||
T extends SelectOptionBase,
|
||||
>(): StylesConfig<T, false> => ({
|
||||
...getCustomStyles<T>(),
|
||||
control: (provided, state) => ({
|
||||
...provided,
|
||||
backgroundColor: state.isDisabled ? "#363636" : "#454545", // darker tertiary when disabled
|
||||
border: "1px solid #717888",
|
||||
borderRadius: "0.125rem",
|
||||
minHeight: "2.5rem",
|
||||
padding: "0 0.5rem",
|
||||
boxShadow: "none",
|
||||
opacity: state.isDisabled ? 0.6 : 1,
|
||||
cursor: state.isDisabled ? "not-allowed" : "pointer",
|
||||
"&:hover": {
|
||||
borderColor: "#717888",
|
||||
},
|
||||
"& .git-provider-dropdown__value-container": {
|
||||
padding: "2px 0",
|
||||
},
|
||||
}),
|
||||
});
|
||||
|
||||
@@ -24,17 +24,6 @@ import { AgentState } from "#/types/agent-state";
|
||||
import { getFirstPRUrl } from "#/utils/parse-pr-url";
|
||||
import MemoryIcon from "#/icons/memory_icon.svg?react";
|
||||
|
||||
const isErrorEvent = (evt: unknown): evt is { error: true; message: string } =>
|
||||
typeof evt === "object" &&
|
||||
evt !== null &&
|
||||
"error" in evt &&
|
||||
evt.error === true;
|
||||
|
||||
const isAgentStatusError = (evt: unknown): boolean =>
|
||||
isOpenHandsEvent(evt) &&
|
||||
isAgentStateChangeObservation(evt) &&
|
||||
evt.extras.agent_state === AgentState.ERROR;
|
||||
|
||||
interface MessagesProps {
|
||||
messages: (OpenHandsAction | OpenHandsObservation)[];
|
||||
isAwaitingUserConfirmation: boolean;
|
||||
@@ -42,11 +31,8 @@ interface MessagesProps {
|
||||
|
||||
export const Messages: React.FC<MessagesProps> = React.memo(
|
||||
({ messages, isAwaitingUserConfirmation }) => {
|
||||
const {
|
||||
createConversationAndSubscribe,
|
||||
isPending,
|
||||
unsubscribeFromConversation,
|
||||
} = useCreateConversationAndSubscribeMultiple();
|
||||
const { createConversationAndSubscribe, isPending } =
|
||||
useCreateConversationAndSubscribeMultiple();
|
||||
const { getOptimisticUserMessage } = useOptimisticUserMessage();
|
||||
const { conversationId } = useConversationId();
|
||||
const { data: conversation } = useUserConversation(conversationId);
|
||||
@@ -107,6 +93,20 @@ export const Messages: React.FC<MessagesProps> = React.memo(
|
||||
|
||||
const handleMicroagentEvent = React.useCallback(
|
||||
(socketEvent: unknown, microagentConversationId: string) => {
|
||||
// Handle error events
|
||||
const isErrorEvent = (
|
||||
evt: unknown,
|
||||
): evt is { error: true; message: string } =>
|
||||
typeof evt === "object" &&
|
||||
evt !== null &&
|
||||
"error" in evt &&
|
||||
evt.error === true;
|
||||
|
||||
const isAgentStatusError = (evt: unknown): boolean =>
|
||||
isOpenHandsEvent(evt) &&
|
||||
isAgentStateChangeObservation(evt) &&
|
||||
evt.extras.agent_state === AgentState.ERROR;
|
||||
|
||||
if (isErrorEvent(socketEvent) || isAgentStatusError(socketEvent)) {
|
||||
setMicroagentStatuses((prev) =>
|
||||
prev.map((statusEntry) =>
|
||||
@@ -119,11 +119,7 @@ export const Messages: React.FC<MessagesProps> = React.memo(
|
||||
isOpenHandsEvent(socketEvent) &&
|
||||
isAgentStateChangeObservation(socketEvent)
|
||||
) {
|
||||
// Handle completion states
|
||||
if (
|
||||
socketEvent.extras.agent_state === AgentState.FINISHED ||
|
||||
socketEvent.extras.agent_state === AgentState.AWAITING_USER_INPUT
|
||||
) {
|
||||
if (socketEvent.extras.agent_state === AgentState.FINISHED) {
|
||||
setMicroagentStatuses((prev) =>
|
||||
prev.map((statusEntry) =>
|
||||
statusEntry.conversationId === microagentConversationId
|
||||
@@ -131,8 +127,6 @@ export const Messages: React.FC<MessagesProps> = React.memo(
|
||||
: statusEntry,
|
||||
),
|
||||
);
|
||||
|
||||
unsubscribeFromConversation(microagentConversationId);
|
||||
}
|
||||
} else if (
|
||||
isOpenHandsEvent(socketEvent) &&
|
||||
@@ -153,27 +147,9 @@ export const Messages: React.FC<MessagesProps> = React.memo(
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
unsubscribeFromConversation(microagentConversationId);
|
||||
} else {
|
||||
// For any other event, transition from WAITING to CREATING if still waiting
|
||||
setMicroagentStatuses((prev) => {
|
||||
const currentStatus = prev.find(
|
||||
(entry) => entry.conversationId === microagentConversationId,
|
||||
)?.status;
|
||||
|
||||
if (currentStatus === MicroagentStatus.WAITING) {
|
||||
return prev.map((statusEntry) =>
|
||||
statusEntry.conversationId === microagentConversationId
|
||||
? { ...statusEntry, status: MicroagentStatus.CREATING }
|
||||
: statusEntry,
|
||||
);
|
||||
}
|
||||
return prev; // No change needed
|
||||
});
|
||||
}
|
||||
},
|
||||
[setMicroagentStatuses, unsubscribeFromConversation],
|
||||
[setMicroagentStatuses],
|
||||
);
|
||||
|
||||
const handleLaunchMicroagent = (
|
||||
@@ -202,13 +178,13 @@ export const Messages: React.FC<MessagesProps> = React.memo(
|
||||
},
|
||||
onSuccessCallback: (newConversationId: string) => {
|
||||
setShowLaunchMicroagentModal(false);
|
||||
// Update status with conversation ID - start with WAITING
|
||||
// Update status with conversation ID
|
||||
setMicroagentStatuses((prev) => [
|
||||
...prev.filter((status) => status.eventId !== selectedEventId),
|
||||
{
|
||||
eventId: selectedEventId,
|
||||
conversationId: newConversationId,
|
||||
status: MicroagentStatus.WAITING,
|
||||
status: MicroagentStatus.CREATING,
|
||||
},
|
||||
]);
|
||||
},
|
||||
|
||||
@@ -19,8 +19,6 @@ export function MicroagentStatusIndicator({
|
||||
|
||||
const getStatusText = () => {
|
||||
switch (status) {
|
||||
case MicroagentStatus.WAITING:
|
||||
return t("MICROAGENT$STATUS_WAITING");
|
||||
case MicroagentStatus.CREATING:
|
||||
return t("MICROAGENT$STATUS_CREATING");
|
||||
case MicroagentStatus.COMPLETED:
|
||||
@@ -37,8 +35,6 @@ export function MicroagentStatusIndicator({
|
||||
|
||||
const getStatusIcon = () => {
|
||||
switch (status) {
|
||||
case MicroagentStatus.WAITING:
|
||||
return <Spinner size="sm" />;
|
||||
case MicroagentStatus.CREATING:
|
||||
return <Spinner size="sm" />;
|
||||
case MicroagentStatus.COMPLETED:
|
||||
|
||||
@@ -10,11 +10,6 @@ interface ConversationCreatedToastProps {
|
||||
onClose: () => void;
|
||||
}
|
||||
|
||||
interface ConversationStartingToastProps {
|
||||
conversationId: string;
|
||||
onClose: () => void;
|
||||
}
|
||||
|
||||
function ConversationCreatedToast({
|
||||
conversationId,
|
||||
onClose,
|
||||
@@ -42,33 +37,6 @@ function ConversationCreatedToast({
|
||||
);
|
||||
}
|
||||
|
||||
function ConversationStartingToast({
|
||||
conversationId,
|
||||
onClose,
|
||||
}: ConversationStartingToastProps) {
|
||||
const { t } = useTranslation();
|
||||
return (
|
||||
<div className="flex items-start gap-2">
|
||||
<Spinner size="sm" />
|
||||
<div>
|
||||
{t("MICROAGENT$CONVERSATION_STARTING")}
|
||||
<br />
|
||||
<a
|
||||
href={`/conversations/${conversationId}`}
|
||||
target="_blank"
|
||||
rel="noopener noreferrer"
|
||||
className="underline"
|
||||
>
|
||||
{t("MICROAGENT$VIEW_CONVERSATION")}
|
||||
</a>
|
||||
</div>
|
||||
<button type="button" onClick={onClose}>
|
||||
<CloseIcon />
|
||||
</button>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
interface ConversationFinishedToastProps {
|
||||
conversationId: string;
|
||||
onClose: () => void;
|
||||
@@ -110,18 +78,10 @@ function ConversationErroredToast({
|
||||
errorMessage,
|
||||
onClose,
|
||||
}: ConversationErroredToastProps) {
|
||||
const { t } = useTranslation();
|
||||
|
||||
// Check if the error message is a translation key
|
||||
const displayMessage =
|
||||
errorMessage === "MICROAGENT$UNKNOWN_ERROR"
|
||||
? t(errorMessage)
|
||||
: errorMessage;
|
||||
|
||||
return (
|
||||
<div className="flex items-start gap-2">
|
||||
<SuccessIndicator status="error" />
|
||||
<div>{displayMessage}</div>
|
||||
<div>{errorMessage}</div>
|
||||
<button type="button" onClick={onClose}>
|
||||
<CloseIcon />
|
||||
</button>
|
||||
@@ -176,18 +136,3 @@ export const renderConversationErroredToast = (
|
||||
duration: 5000,
|
||||
},
|
||||
);
|
||||
|
||||
export const renderConversationStartingToast = (conversationId: string) =>
|
||||
toast(
|
||||
(toastInstance) => (
|
||||
<ConversationStartingToast
|
||||
conversationId={conversationId}
|
||||
onClose={() => toast.dismiss(toastInstance.id)}
|
||||
/>
|
||||
),
|
||||
{
|
||||
...TOAST_OPTIONS,
|
||||
id: `starting-${conversationId}`,
|
||||
duration: 10000, // Show for 10 seconds or until dismissed
|
||||
},
|
||||
);
|
||||
|
||||
@@ -7,10 +7,11 @@ import { ConversationCard } from "../conversation-panel/conversation-card";
|
||||
import { Provider } from "#/types/settings";
|
||||
|
||||
interface ControlsProps {
|
||||
setSecurityOpen: (isOpen: boolean) => void;
|
||||
showSecurityLock: boolean;
|
||||
}
|
||||
|
||||
export function Controls({ showSecurityLock }: ControlsProps) {
|
||||
export function Controls({ setSecurityOpen, showSecurityLock }: ControlsProps) {
|
||||
const { data: conversation } = useActiveConversation();
|
||||
const [contextMenuOpen, setContextMenuOpen] = React.useState(false);
|
||||
|
||||
@@ -20,7 +21,9 @@ export function Controls({ showSecurityLock }: ControlsProps) {
|
||||
<AgentControlBar />
|
||||
<AgentStatusBar />
|
||||
|
||||
{showSecurityLock && <SecurityLock />}
|
||||
{showSecurityLock && (
|
||||
<SecurityLock onClick={() => setSecurityOpen(true)} />
|
||||
)}
|
||||
</div>
|
||||
|
||||
<ConversationCard
|
||||
|
||||
@@ -1,28 +1,17 @@
|
||||
import { IoLockClosed } from "react-icons/io5";
|
||||
import { Tooltip } from "@heroui/react";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import { Link } from "react-router";
|
||||
import { I18nKey } from "#/i18n/declaration";
|
||||
|
||||
export function SecurityLock() {
|
||||
const { t } = useTranslation();
|
||||
interface SecurityLockProps {
|
||||
onClick: () => void;
|
||||
}
|
||||
|
||||
export function SecurityLock({ onClick }: SecurityLockProps) {
|
||||
return (
|
||||
<Tooltip
|
||||
content={
|
||||
<div className="max-w-xs p-2">
|
||||
{t(I18nKey.SETTINGS$CONFIRMATION_MODE_LOCK_TOOLTIP)}
|
||||
</div>
|
||||
}
|
||||
placement="top"
|
||||
<div
|
||||
className="cursor-pointer hover:opacity-80 transition-all"
|
||||
style={{ marginRight: "8px" }}
|
||||
onClick={onClick}
|
||||
>
|
||||
<Link
|
||||
to="/settings"
|
||||
className="mr-2 cursor-pointer hover:opacity-80 transition-all"
|
||||
aria-label={t(I18nKey.SETTINGS$TITLE)}
|
||||
>
|
||||
<IoLockClosed size={20} />
|
||||
</Link>
|
||||
</Tooltip>
|
||||
<IoLockClosed size={20} />
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -17,7 +17,7 @@ export function MicroagentManagementAccordionTitle({
|
||||
<TooltipButton
|
||||
tooltip={repository.full_name}
|
||||
ariaLabel={repository.full_name}
|
||||
className="text-white text-base font-normal bg-transparent p-0 min-w-0 h-auto cursor-pointer truncate max-w-[194px] translate-y-[-1px]"
|
||||
className="text-white text-base font-normal bg-transparent p-0 min-w-0 h-auto cursor-pointer truncate max-w-[200px] translate-y-[-1px]"
|
||||
testId="repository-name-tooltip"
|
||||
placement="bottom"
|
||||
>
|
||||
|
||||
@@ -32,7 +32,6 @@ import {
|
||||
} from "#/utils/custom-toast-handlers";
|
||||
import { getFirstPRUrl } from "#/utils/parse-pr-url";
|
||||
import { I18nKey } from "#/i18n/declaration";
|
||||
import { useUserProviders } from "#/hooks/use-user-providers";
|
||||
|
||||
// Handle error events
|
||||
const isErrorEvent = (evt: unknown): evt is { error: true; message: string } =>
|
||||
@@ -66,10 +65,16 @@ const getConversationInstructions = (
|
||||
gitProvider: Provider,
|
||||
) => `Create a microagent for the repository ${repositoryName} by following the steps below:
|
||||
|
||||
- Step 1: Create a markdown file inside the .openhands/microagents folder with the name of the microagent (The microagent must be created in the .openhands/microagents folder and should be able to perform the described task when triggered). This is the instructions about what the microagent should do: ${formData.query}. ${
|
||||
- Step 1: Create a markdown file inside the .openhands/microagents folder with the name of the microagent (The microagent must be created in the .openhands/microagents folder and should be able to perform the described task when triggered).
|
||||
|
||||
- This is the instructions about what the microagent should do: ${formData.query}
|
||||
|
||||
${
|
||||
formData.triggers && formData.triggers.length > 0
|
||||
? `This is the triggers of the microagent: ${formData.triggers.join(", ")}`
|
||||
: "Please be noted that the microagent doesn't have any triggers."
|
||||
? `
|
||||
- This is the triggers of the microagent: ${formData.triggers.join(", ")}
|
||||
`
|
||||
: "- Please be noted that the microagent doesn't have any triggers."
|
||||
}
|
||||
|
||||
- Step 2: Create a new branch for the repository ${repositoryName}, must avoid duplicated branches.
|
||||
@@ -86,10 +91,16 @@ const getUpdateConversationInstructions = (
|
||||
) => `Update the microagent for the repository ${repositoryName} by following the steps below:
|
||||
|
||||
|
||||
- Step 1: Update the microagent. This is the path of the microagent: ${formData.microagentPath} (The updated microagent must be in the .openhands/microagents folder and should be able to perform the described task when triggered). This is the updated instructions about what the microagent should do: ${formData.query}. ${
|
||||
- Step 1: Update the microagent. This is the path of the microagent: ${formData.microagentPath} (The updated microagent must be in the .openhands/microagents folder and should be able to perform the described task when triggered).
|
||||
|
||||
- This is the updated instructions about what the microagent should do: ${formData.query}
|
||||
|
||||
${
|
||||
formData.triggers && formData.triggers.length > 0
|
||||
? `This is the triggers of the microagent: ${formData.triggers.join(", ")}`
|
||||
: "Please be noted that the microagent doesn't have any triggers."
|
||||
? `
|
||||
- This is the triggers of the microagent: ${formData.triggers.join(", ")}
|
||||
`
|
||||
: "- Please be noted that the microagent doesn't have any triggers."
|
||||
}
|
||||
|
||||
- Step 2: Create a new branch for the repository ${repositoryName}, must avoid duplicated branches.
|
||||
@@ -108,8 +119,6 @@ export function MicroagentManagementContent() {
|
||||
learnThisRepoModalVisible,
|
||||
} = useSelector((state: RootState) => state.microagentManagement);
|
||||
|
||||
const { providers } = useUserProviders();
|
||||
|
||||
const { t } = useTranslation();
|
||||
|
||||
const dispatch = useDispatch();
|
||||
@@ -173,7 +182,11 @@ export function MicroagentManagementContent() {
|
||||
// Check if agent has finished and we have a PR
|
||||
if (isOpenHandsEvent(socketEvent) && isFinishAction(socketEvent)) {
|
||||
const prUrl = getFirstPRUrl(socketEvent.args.final_thought || "");
|
||||
if (!prUrl) {
|
||||
if (prUrl) {
|
||||
displaySuccessToast(
|
||||
t(I18nKey.MICROAGENT_MANAGEMENT$PR_READY_FOR_REVIEW),
|
||||
);
|
||||
} else {
|
||||
// Agent finished but no PR found
|
||||
displaySuccessToast(t(I18nKey.MICROAGENT_MANAGEMENT$PR_NOT_CREATED));
|
||||
}
|
||||
@@ -316,18 +329,11 @@ export function MicroagentManagementContent() {
|
||||
</>
|
||||
);
|
||||
|
||||
const providersAreSet = providers.length > 0;
|
||||
|
||||
if (width < 1024) {
|
||||
return (
|
||||
<div className="w-full h-full flex flex-col gap-6">
|
||||
<div className="w-full rounded-lg border border-[#525252] bg-[#24272E] max-h-[494px] min-h-[494px]">
|
||||
{providersAreSet && (
|
||||
<MicroagentManagementSidebar
|
||||
isSmallerScreen
|
||||
providers={providers}
|
||||
/>
|
||||
)}
|
||||
<MicroagentManagementSidebar isSmallerScreen />
|
||||
</div>
|
||||
<div className="w-full rounded-lg border border-[#525252] bg-[#24272E] flex-1 min-h-[494px]">
|
||||
<MicroagentManagementMain />
|
||||
@@ -339,7 +345,7 @@ export function MicroagentManagementContent() {
|
||||
|
||||
return (
|
||||
<div className="w-full h-full flex rounded-lg border border-[#525252] bg-[#24272E] overflow-hidden">
|
||||
{providersAreSet && <MicroagentManagementSidebar providers={providers} />}
|
||||
<MicroagentManagementSidebar />
|
||||
<div className="flex-1">
|
||||
<MicroagentManagementMain />
|
||||
</div>
|
||||
|
||||
@@ -59,10 +59,8 @@ export function MicroagentManagementMicroagentCard({
|
||||
if (runtimeStatus === "STATUS$ERROR") {
|
||||
return t(I18nKey.MICROAGENT$STATUS_ERROR);
|
||||
}
|
||||
if (conversationStatus === "RUNNING") {
|
||||
return runtimeStatus === "STATUS$READY"
|
||||
? t(I18nKey.MICROAGENT$STATUS_OPENING_PR)
|
||||
: t(I18nKey.COMMON$STARTING);
|
||||
if (conversationStatus === "RUNNING" && runtimeStatus === "STATUS$READY") {
|
||||
return t(I18nKey.MICROAGENT$STATUS_OPENING_PR);
|
||||
}
|
||||
return "";
|
||||
}, [conversationStatus, runtimeStatus, t, hasPr]);
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
import { useTranslation } from "react-i18next";
|
||||
import { useEffect } from "react";
|
||||
import { useDispatch, useSelector } from "react-redux";
|
||||
import { Spinner } from "@heroui/react";
|
||||
@@ -9,8 +8,6 @@ import { useSearchConversations } from "#/hooks/query/use-search-conversations";
|
||||
import { GitRepository } from "#/types/git";
|
||||
import { RootState } from "#/store";
|
||||
import { setSelectedMicroagentItem } from "#/state/microagent-management-slice";
|
||||
import { cn } from "#/utils/utils";
|
||||
import { I18nKey } from "#/i18n/declaration";
|
||||
|
||||
interface MicroagentManagementRepoMicroagentsProps {
|
||||
repository: GitRepository;
|
||||
@@ -25,8 +22,6 @@ export function MicroagentManagementRepoMicroagents({
|
||||
|
||||
const dispatch = useDispatch();
|
||||
|
||||
const { t } = useTranslation();
|
||||
|
||||
const { full_name: repositoryName } = repository;
|
||||
|
||||
// Extract owner and repo from repositoryName (format: "owner/repo")
|
||||
@@ -108,47 +103,34 @@ export function MicroagentManagementRepoMicroagents({
|
||||
const numberOfMicroagents = microagents?.length || 0;
|
||||
const numberOfConversations = conversations?.length || 0;
|
||||
const totalItems = numberOfMicroagents + numberOfConversations;
|
||||
const hasMicroagents = numberOfMicroagents > 0;
|
||||
const hasConversations = numberOfConversations > 0;
|
||||
|
||||
return (
|
||||
<div>
|
||||
{totalItems === 0 && (
|
||||
<MicroagentManagementLearnThisRepo repository={repository} />
|
||||
)}
|
||||
|
||||
{/* Render microagents */}
|
||||
{hasMicroagents && (
|
||||
<div className="flex flex-col">
|
||||
<span className="text-md text-white font-medium leading-5 mb-4">
|
||||
{t(I18nKey.MICROAGENT_MANAGEMENT$EXISTING_MICROAGENTS)}
|
||||
</span>
|
||||
{microagents?.map((microagent) => (
|
||||
<div key={microagent.name} className="pb-4 last:pb-0">
|
||||
<MicroagentManagementMicroagentCard
|
||||
microagent={microagent}
|
||||
repository={repository}
|
||||
/>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
{numberOfMicroagents > 0 &&
|
||||
microagents?.map((microagent) => (
|
||||
<div key={microagent.name} className="pb-4 last:pb-0">
|
||||
<MicroagentManagementMicroagentCard
|
||||
microagent={microagent}
|
||||
repository={repository}
|
||||
/>
|
||||
</div>
|
||||
))}
|
||||
|
||||
{/* Render conversations */}
|
||||
{hasConversations && (
|
||||
<div className={cn("flex flex-col", hasMicroagents && "mt-4")}>
|
||||
<span className="text-md text-white font-medium leading-5 mb-4">
|
||||
{t(I18nKey.MICROAGENT_MANAGEMENT$OPEN_MICROAGENT_PULL_REQUESTS)}
|
||||
</span>
|
||||
{conversations?.map((conversation) => (
|
||||
<div key={conversation.conversation_id} className="pb-4 last:pb-0">
|
||||
<MicroagentManagementMicroagentCard
|
||||
conversation={conversation}
|
||||
repository={repository}
|
||||
/>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
{numberOfConversations > 0 &&
|
||||
conversations?.map((conversation) => (
|
||||
<div key={conversation.conversation_id} className="pb-4 last:pb-0">
|
||||
<MicroagentManagementMicroagentCard
|
||||
conversation={conversation}
|
||||
repository={repository}
|
||||
/>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1,12 +1,15 @@
|
||||
import { useState, useMemo } from "react";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import { Accordion, AccordionItem } from "@heroui/react";
|
||||
import { MicroagentManagementRepoMicroagents } from "./microagent-management-repo-microagents";
|
||||
import { GitRepository } from "#/types/git";
|
||||
import { cn } from "#/utils/utils";
|
||||
import { TabType } from "#/types/microagent-management";
|
||||
import { MicroagentManagementNoRepositories } from "./microagent-management-no-repositories";
|
||||
import { I18nKey } from "#/i18n/declaration";
|
||||
import { DOCUMENTATION_URL } from "#/utils/constants";
|
||||
import { MicroagentManagementAccordionTitle } from "./microagent-management-accordion-title";
|
||||
import { sanitizeQuery } from "#/utils/sanitize-query";
|
||||
|
||||
type MicroagentManagementRepositoriesProps = {
|
||||
repositories: GitRepository[];
|
||||
@@ -18,9 +21,23 @@ export function MicroagentManagementRepositories({
|
||||
tabType,
|
||||
}: MicroagentManagementRepositoriesProps) {
|
||||
const { t } = useTranslation();
|
||||
const [searchQuery, setSearchQuery] = useState("");
|
||||
|
||||
const numberOfRepoMicroagents = repositories.length;
|
||||
|
||||
// Filter repositories based on search query
|
||||
const filteredRepositories = useMemo(() => {
|
||||
if (!searchQuery.trim()) {
|
||||
return repositories;
|
||||
}
|
||||
|
||||
const sanitizedQuery = sanitizeQuery(searchQuery);
|
||||
return repositories.filter((repository) => {
|
||||
const sanitizedRepoName = sanitizeQuery(repository.full_name);
|
||||
return sanitizedRepoName.includes(sanitizedQuery);
|
||||
});
|
||||
}, [repositories, searchQuery]);
|
||||
|
||||
if (numberOfRepoMicroagents === 0) {
|
||||
if (tabType === "personal") {
|
||||
return (
|
||||
@@ -56,6 +73,25 @@ export function MicroagentManagementRepositories({
|
||||
|
||||
return (
|
||||
<div className="flex flex-col gap-4 w-full">
|
||||
{/* Search Input */}
|
||||
<div className="flex flex-col gap-2 w-full">
|
||||
<label htmlFor="repository-search" className="sr-only">
|
||||
{t(I18nKey.COMMON$SEARCH_REPOSITORIES)}
|
||||
</label>
|
||||
<input
|
||||
id="repository-search"
|
||||
name="repository-search"
|
||||
type="text"
|
||||
placeholder={`${t(I18nKey.COMMON$SEARCH_REPOSITORIES)}...`}
|
||||
value={searchQuery}
|
||||
onChange={(e) => setSearchQuery(e.target.value)}
|
||||
className={cn(
|
||||
"bg-tertiary border border-[#717888] bg-[#454545] w-full rounded-sm p-2 placeholder:italic placeholder:text-tertiary-alt",
|
||||
"disabled:bg-[#2D2F36] disabled:border-[#2D2F36] disabled:cursor-not-allowed",
|
||||
)}
|
||||
/>
|
||||
</div>
|
||||
|
||||
{/* Repositories Accordion */}
|
||||
<Accordion
|
||||
variant="splitted"
|
||||
@@ -68,7 +104,7 @@ export function MicroagentManagementRepositories({
|
||||
}}
|
||||
selectionMode="multiple"
|
||||
>
|
||||
{repositories.map((repository) => (
|
||||
{filteredRepositories.map((repository) => (
|
||||
<AccordionItem
|
||||
key={repository.id}
|
||||
aria-label={repository.full_name}
|
||||
|
||||
@@ -1,109 +1,59 @@
|
||||
import { useEffect, useState, useMemo } from "react";
|
||||
import { useEffect } from "react";
|
||||
import { useDispatch } from "react-redux";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import { Spinner } from "@heroui/react";
|
||||
import { MicroagentManagementSidebarHeader } from "./microagent-management-sidebar-header";
|
||||
import { MicroagentManagementSidebarTabs } from "./microagent-management-sidebar-tabs";
|
||||
import { useGitRepositories } from "#/hooks/query/use-git-repositories";
|
||||
import { GitProviderDropdown } from "#/components/common/git-provider-dropdown";
|
||||
import { useUserRepositories } from "#/hooks/query/use-user-repositories";
|
||||
import { useUserProviders } from "#/hooks/use-user-providers";
|
||||
import {
|
||||
setPersonalRepositories,
|
||||
setOrganizationRepositories,
|
||||
setRepositories,
|
||||
} from "#/state/microagent-management-slice";
|
||||
import { GitRepository } from "#/types/git";
|
||||
import { Provider } from "#/types/settings";
|
||||
import { cn } from "#/utils/utils";
|
||||
import { sanitizeQuery } from "#/utils/sanitize-query";
|
||||
import { I18nKey } from "#/i18n/declaration";
|
||||
import { getGitProviderMicroagentManagementCustomStyles } from "#/components/common/react-select-styles";
|
||||
|
||||
interface MicroagentManagementSidebarProps {
|
||||
isSmallerScreen?: boolean;
|
||||
providers: Provider[];
|
||||
}
|
||||
|
||||
export function MicroagentManagementSidebar({
|
||||
isSmallerScreen = false,
|
||||
providers,
|
||||
}: MicroagentManagementSidebarProps) {
|
||||
const [selectedProvider, setSelectedProvider] = useState<Provider | null>(
|
||||
providers.length > 0 ? providers[0] : null,
|
||||
);
|
||||
|
||||
const [searchQuery, setSearchQuery] = useState("");
|
||||
|
||||
const dispatch = useDispatch();
|
||||
|
||||
const { t } = useTranslation();
|
||||
|
||||
const { data: repositories, isLoading } = useGitRepositories({
|
||||
provider: selectedProvider,
|
||||
pageSize: 200,
|
||||
enabled: !!selectedProvider,
|
||||
});
|
||||
|
||||
// Auto-select provider if there's only one
|
||||
useEffect(() => {
|
||||
if (providers.length > 0 && !selectedProvider) {
|
||||
setSelectedProvider(providers[0]);
|
||||
}
|
||||
}, [providers, selectedProvider]);
|
||||
|
||||
const handleProviderChange = (provider: Provider | null) => {
|
||||
setSelectedProvider(provider);
|
||||
setSearchQuery("");
|
||||
};
|
||||
|
||||
// Filter repositories based on search query
|
||||
const filteredRepositories = useMemo(() => {
|
||||
if (!repositories?.pages) return null;
|
||||
|
||||
// Flatten all pages to get all repositories
|
||||
const allRepositories = repositories.pages.flatMap((page) => page.data);
|
||||
|
||||
if (!searchQuery.trim()) {
|
||||
return allRepositories;
|
||||
}
|
||||
|
||||
const sanitizedQuery = sanitizeQuery(searchQuery);
|
||||
return allRepositories.filter((repository: GitRepository) => {
|
||||
const sanitizedRepoName = sanitizeQuery(repository.full_name);
|
||||
return sanitizedRepoName.includes(sanitizedQuery);
|
||||
});
|
||||
}, [repositories, searchQuery, selectedProvider]);
|
||||
const { providers } = useUserProviders();
|
||||
const selectedProvider = providers.length > 0 ? providers[0] : null;
|
||||
const { data: repositories, isLoading } =
|
||||
useUserRepositories(selectedProvider);
|
||||
|
||||
useEffect(() => {
|
||||
if (!filteredRepositories?.length) {
|
||||
dispatch(setPersonalRepositories([]));
|
||||
dispatch(setOrganizationRepositories([]));
|
||||
dispatch(setRepositories([]));
|
||||
return;
|
||||
if (repositories?.pages) {
|
||||
const personalRepos: GitRepository[] = [];
|
||||
const organizationRepos: GitRepository[] = [];
|
||||
const otherRepos: GitRepository[] = [];
|
||||
|
||||
// Flatten all pages to get all repositories
|
||||
const allRepositories = repositories.pages.flatMap((page) => page.data);
|
||||
|
||||
allRepositories.forEach((repo: GitRepository) => {
|
||||
const hasOpenHandsSuffix = repo.full_name.endsWith("/.openhands");
|
||||
|
||||
if (repo.owner_type === "user" && hasOpenHandsSuffix) {
|
||||
personalRepos.push(repo);
|
||||
} else if (repo.owner_type === "organization" && hasOpenHandsSuffix) {
|
||||
organizationRepos.push(repo);
|
||||
} else {
|
||||
otherRepos.push(repo);
|
||||
}
|
||||
});
|
||||
|
||||
dispatch(setPersonalRepositories(personalRepos));
|
||||
dispatch(setOrganizationRepositories(organizationRepos));
|
||||
dispatch(setRepositories(otherRepos));
|
||||
}
|
||||
|
||||
const personalRepos: GitRepository[] = [];
|
||||
const organizationRepos: GitRepository[] = [];
|
||||
const otherRepos: GitRepository[] = [];
|
||||
|
||||
filteredRepositories.forEach((repo: GitRepository) => {
|
||||
const hasOpenHandsSuffix =
|
||||
selectedProvider === "gitlab"
|
||||
? repo.full_name.endsWith("/openhands-config")
|
||||
: repo.full_name.endsWith("/.openhands");
|
||||
|
||||
if (repo.owner_type === "user" && hasOpenHandsSuffix) {
|
||||
personalRepos.push(repo);
|
||||
} else if (repo.owner_type === "organization" && hasOpenHandsSuffix) {
|
||||
organizationRepos.push(repo);
|
||||
} else {
|
||||
otherRepos.push(repo);
|
||||
}
|
||||
});
|
||||
|
||||
dispatch(setPersonalRepositories(personalRepos));
|
||||
dispatch(setOrganizationRepositories(organizationRepos));
|
||||
dispatch(setRepositories(otherRepos));
|
||||
}, [filteredRepositories, selectedProvider, dispatch]);
|
||||
}, [repositories, dispatch]);
|
||||
|
||||
return (
|
||||
<div
|
||||
@@ -113,41 +63,6 @@ export function MicroagentManagementSidebar({
|
||||
)}
|
||||
>
|
||||
<MicroagentManagementSidebarHeader />
|
||||
|
||||
{/* Provider Selection */}
|
||||
{providers.length > 1 && (
|
||||
<div className="mt-6">
|
||||
<GitProviderDropdown
|
||||
providers={providers}
|
||||
value={selectedProvider}
|
||||
placeholder="Select Provider"
|
||||
onChange={handleProviderChange}
|
||||
className="w-full"
|
||||
classNamePrefix="git-provider-dropdown"
|
||||
styles={getGitProviderMicroagentManagementCustomStyles()}
|
||||
/>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* Search Input */}
|
||||
<div className="flex flex-col gap-2 w-full mt-6">
|
||||
<label htmlFor="repository-search" className="sr-only">
|
||||
{t(I18nKey.COMMON$SEARCH_REPOSITORIES)}
|
||||
</label>
|
||||
<input
|
||||
id="repository-search"
|
||||
name="repository-search"
|
||||
type="text"
|
||||
placeholder={`${t(I18nKey.COMMON$SEARCH_REPOSITORIES)}...`}
|
||||
value={searchQuery}
|
||||
onChange={(e) => setSearchQuery(e.target.value)}
|
||||
className={cn(
|
||||
"bg-tertiary border border-[#717888] bg-[#454545] w-full rounded-sm p-2 placeholder:italic placeholder:text-tertiary-alt",
|
||||
"disabled:bg-[#2D2F36] disabled:border-[#2D2F36] disabled:cursor-not-allowed h-10 box-shadow-none outline-none",
|
||||
)}
|
||||
/>
|
||||
</div>
|
||||
|
||||
{isLoading ? (
|
||||
<div className="flex flex-col items-center justify-center gap-4 flex-1">
|
||||
<Spinner size="sm" />
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
import { Tooltip } from "@heroui/react";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import ConfirmIcon from "#/assets/confirm";
|
||||
import RejectIcon from "#/assets/reject";
|
||||
import { I18nKey } from "#/i18n/declaration";
|
||||
import { cn } from "#/utils/utils";
|
||||
|
||||
interface ActionTooltipProps {
|
||||
type: "confirm" | "reject";
|
||||
@@ -11,35 +12,25 @@ interface ActionTooltipProps {
|
||||
export function ActionTooltip({ type, onClick }: ActionTooltipProps) {
|
||||
const { t } = useTranslation();
|
||||
|
||||
const isConfirm = type === "confirm";
|
||||
|
||||
const ariaLabel = isConfirm
|
||||
? t(I18nKey.ACTION$CONFIRM)
|
||||
: t(I18nKey.ACTION$REJECT);
|
||||
|
||||
const content = isConfirm
|
||||
? t(I18nKey.CHAT_INTERFACE$USER_CONFIRMED)
|
||||
: t(I18nKey.CHAT_INTERFACE$USER_REJECTED);
|
||||
|
||||
const buttonLabel = isConfirm
|
||||
? `${t(I18nKey.CHAT_INTERFACE$INPUT_CONTINUE_MESSAGE)} ⌘↩`
|
||||
: `${t(I18nKey.BUTTON$CANCEL)} ⇧⌘⌫`;
|
||||
const content =
|
||||
type === "confirm"
|
||||
? t(I18nKey.CHAT_INTERFACE$USER_CONFIRMED)
|
||||
: t(I18nKey.CHAT_INTERFACE$USER_REJECTED);
|
||||
|
||||
return (
|
||||
<Tooltip content={content} closeDelay={100}>
|
||||
<button
|
||||
data-testid={`action-${type}-button`}
|
||||
type="button"
|
||||
aria-label={ariaLabel}
|
||||
className={cn(
|
||||
"rounded px-2 h-6.5 text-sm font-medium leading-5 cursor-pointer hover:opacity-80",
|
||||
aria-label={
|
||||
type === "confirm"
|
||||
? "bg-tertiary text-white"
|
||||
: "bg-white text-[#0D0F11]",
|
||||
)}
|
||||
? t(I18nKey.ACTION$CONFIRM)
|
||||
: t(I18nKey.ACTION$REJECT)
|
||||
}
|
||||
className="bg-tertiary rounded-full p-1 hover:bg-base-secondary"
|
||||
onClick={onClick}
|
||||
>
|
||||
{buttonLabel}
|
||||
{type === "confirm" ? <ConfirmIcon /> : <RejectIcon />}
|
||||
</button>
|
||||
</Tooltip>
|
||||
);
|
||||
|
||||
@@ -1,120 +1,31 @@
|
||||
import { useDispatch, useSelector } from "react-redux";
|
||||
import { useCallback, useEffect } from "react";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import { I18nKey } from "#/i18n/declaration";
|
||||
import { AgentState } from "#/types/agent-state";
|
||||
import { generateAgentStateChangeEvent } from "#/services/agent-state-service";
|
||||
import { useWsClient } from "#/context/ws-client-provider";
|
||||
import { ActionTooltip } from "../action-tooltip";
|
||||
import { isOpenHandsAction } from "#/types/core/guards";
|
||||
import { ActionSecurityRisk } from "#/state/security-analyzer-slice";
|
||||
import { RiskAlert } from "#/components/shared/risk-alert";
|
||||
import WarningIcon from "#/icons/u-warning.svg?react";
|
||||
import { RootState } from "#/store";
|
||||
import { addSubmittedEventId } from "#/state/event-message-slice";
|
||||
|
||||
export function ConfirmationButtons() {
|
||||
const submittedEventIds = useSelector(
|
||||
(state: RootState) => state.eventMessage.submittedEventIds,
|
||||
);
|
||||
|
||||
const dispatch = useDispatch();
|
||||
|
||||
const { t } = useTranslation();
|
||||
const { send } = useWsClient();
|
||||
|
||||
const { send, parsedEvents } = useWsClient();
|
||||
|
||||
// Find the most recent action awaiting confirmation
|
||||
const awaitingAction = parsedEvents
|
||||
.slice()
|
||||
.reverse()
|
||||
.find((ev) => {
|
||||
if (!isOpenHandsAction(ev) || ev.source !== "agent") return false;
|
||||
const args = ev.args as Record<string, unknown>;
|
||||
return args?.confirmation_state === "awaiting_confirmation";
|
||||
});
|
||||
|
||||
const handleStateChange = useCallback(
|
||||
(state: AgentState) => {
|
||||
if (!awaitingAction) {
|
||||
return;
|
||||
}
|
||||
|
||||
dispatch(addSubmittedEventId(awaitingAction.id));
|
||||
send(generateAgentStateChangeEvent(state));
|
||||
},
|
||||
[send],
|
||||
);
|
||||
|
||||
// Handle keyboard shortcuts
|
||||
useEffect(() => {
|
||||
if (!awaitingAction) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
const handleCancelShortcut = (event: KeyboardEvent) => {
|
||||
if (event.shiftKey && event.metaKey && event.key === "Backspace") {
|
||||
event.preventDefault();
|
||||
handleStateChange(AgentState.USER_REJECTED);
|
||||
}
|
||||
};
|
||||
|
||||
const handleContinueShortcut = (event: KeyboardEvent) => {
|
||||
if (event.metaKey && event.key === "Enter") {
|
||||
event.preventDefault();
|
||||
handleStateChange(AgentState.USER_CONFIRMED);
|
||||
}
|
||||
};
|
||||
|
||||
const handleKeyDown = (event: KeyboardEvent) => {
|
||||
// Cancel: Shift+Cmd+Backspace (⇧⌘⌫)
|
||||
handleCancelShortcut(event);
|
||||
// Continue: Cmd+Enter (⌘↩)
|
||||
handleContinueShortcut(event);
|
||||
};
|
||||
|
||||
document.addEventListener("keydown", handleKeyDown);
|
||||
|
||||
return () => document.removeEventListener("keydown", handleKeyDown);
|
||||
}, [awaitingAction, handleStateChange]);
|
||||
|
||||
if (!awaitingAction || submittedEventIds.includes(awaitingAction.id)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const { args } = awaitingAction as { args: Record<string, unknown> };
|
||||
|
||||
const risk = args?.security_risk;
|
||||
|
||||
const isHighRisk =
|
||||
typeof risk === "string"
|
||||
? risk.toLowerCase() === "high"
|
||||
: Number(risk) === ActionSecurityRisk.HIGH;
|
||||
const handleStateChange = (state: AgentState) => {
|
||||
const event = generateAgentStateChangeEvent(state);
|
||||
send(event);
|
||||
};
|
||||
|
||||
return (
|
||||
<div className="flex flex-col gap-2 pt-4">
|
||||
{isHighRisk && (
|
||||
<RiskAlert
|
||||
content={t(I18nKey.CHAT_INTERFACE$HIGH_RISK_WARNING)}
|
||||
icon={<WarningIcon width={16} height={16} color="#fff" />}
|
||||
severity="high"
|
||||
title={t(I18nKey.COMMON$HIGH_RISK)}
|
||||
<div className="flex justify-between items-center pt-4">
|
||||
<p>{t(I18nKey.CHAT_INTERFACE$USER_ASK_CONFIRMATION)}</p>
|
||||
<div className="flex items-center gap-3">
|
||||
<ActionTooltip
|
||||
type="confirm"
|
||||
onClick={() => handleStateChange(AgentState.USER_CONFIRMED)}
|
||||
/>
|
||||
<ActionTooltip
|
||||
type="reject"
|
||||
onClick={() => handleStateChange(AgentState.USER_REJECTED)}
|
||||
/>
|
||||
)}
|
||||
<div className="flex justify-between items-center">
|
||||
<p className="text-sm font-normal text-white">
|
||||
{t(I18nKey.CHAT_INTERFACE$USER_ASK_CONFIRMATION)}
|
||||
</p>
|
||||
<div className="flex items-center gap-3">
|
||||
<ActionTooltip
|
||||
type="reject"
|
||||
onClick={() => handleStateChange(AgentState.USER_REJECTED)}
|
||||
/>
|
||||
<ActionTooltip
|
||||
type="confirm"
|
||||
onClick={() => handleStateChange(AgentState.USER_CONFIRMED)}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
|
||||
@@ -93,14 +93,14 @@ function SecurityInvariant() {
|
||||
(risk: ActionSecurityRisk) => {
|
||||
switch (risk) {
|
||||
case ActionSecurityRisk.LOW:
|
||||
return t(I18nKey.SECURITY$LOW_RISK);
|
||||
return t(I18nKey.SECURITY_ANALYZER$LOW_RISK);
|
||||
case ActionSecurityRisk.MEDIUM:
|
||||
return t(I18nKey.SECURITY$MEDIUM_RISK);
|
||||
return t(I18nKey.SECURITY_ANALYZER$MEDIUM_RISK);
|
||||
case ActionSecurityRisk.HIGH:
|
||||
return t(I18nKey.SECURITY$HIGH_RISK);
|
||||
return t(I18nKey.SECURITY_ANALYZER$HIGH_RISK);
|
||||
case ActionSecurityRisk.UNKNOWN:
|
||||
default:
|
||||
return t(I18nKey.SECURITY$UNKNOWN_RISK);
|
||||
return t(I18nKey.SECURITY_ANALYZER$UNKNOWN_RISK);
|
||||
}
|
||||
},
|
||||
[t],
|
||||
|
||||
@@ -1,36 +0,0 @@
|
||||
import { ReactNode } from "react";
|
||||
import { cn } from "#/utils/utils";
|
||||
|
||||
interface RiskAlertProps {
|
||||
className?: string;
|
||||
content: ReactNode;
|
||||
icon?: ReactNode;
|
||||
severity: "high" | "medium" | "low";
|
||||
title: string;
|
||||
}
|
||||
|
||||
export function RiskAlert({
|
||||
className,
|
||||
content,
|
||||
icon,
|
||||
severity,
|
||||
title,
|
||||
}: RiskAlertProps) {
|
||||
// Currently, we are only supporting the high risk alert. If we use want to support other risk levels, we can add them here and use cva to create different variants of this component.
|
||||
if (severity === "high") {
|
||||
return (
|
||||
<div
|
||||
className={cn(
|
||||
"flex items-center gap-3.5 bg-[#4A0709] border border-[#FF0006] text-red-400 rounded-xl px-3.5 h-13 text-sm text-white",
|
||||
className,
|
||||
)}
|
||||
>
|
||||
{icon && <span className="">{icon}</span>}
|
||||
<span className="font-bold">{title}</span>
|
||||
<span className="font-normal">{content}</span>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
@@ -33,7 +33,6 @@ interface ConversationSubscriptionsContextType {
|
||||
sessionApiKey: string | null;
|
||||
providersSet: ("github" | "gitlab" | "bitbucket" | "enterprise_sso")[];
|
||||
baseUrl: string;
|
||||
socketPath?: string;
|
||||
onEvent?: (event: unknown, conversationId: string) => void;
|
||||
}) => void;
|
||||
unsubscribeFromConversation: (conversationId: string) => void;
|
||||
@@ -96,10 +95,10 @@ export function ConversationSubscriptionsProvider({
|
||||
[],
|
||||
);
|
||||
|
||||
const unsubscribeFromConversation = useCallback((conversationId: string) => {
|
||||
// Use functional update to access current socket data and perform cleanup
|
||||
setConversationSockets((prev) => {
|
||||
const socketData = prev[conversationId];
|
||||
const unsubscribeFromConversation = useCallback(
|
||||
(conversationId: string) => {
|
||||
// Get a local reference to the socket data to avoid race conditions
|
||||
const socketData = conversationSockets[conversationId];
|
||||
|
||||
if (socketData) {
|
||||
const { socket } = socketData;
|
||||
@@ -113,23 +112,24 @@ export function ConversationSubscriptionsProvider({
|
||||
socket.disconnect();
|
||||
}
|
||||
|
||||
// Update state to remove the socket
|
||||
setConversationSockets((prev) => {
|
||||
const newSockets = { ...prev };
|
||||
delete newSockets[conversationId];
|
||||
return newSockets;
|
||||
});
|
||||
|
||||
// Remove from active IDs
|
||||
setActiveConversationIds((prev) =>
|
||||
prev.filter((id) => id !== conversationId),
|
||||
);
|
||||
|
||||
// Clean up event handler reference
|
||||
delete eventHandlersRef.current[conversationId];
|
||||
|
||||
// Remove the socket from state
|
||||
const newSockets = { ...prev };
|
||||
delete newSockets[conversationId];
|
||||
return newSockets;
|
||||
}
|
||||
|
||||
return prev; // No change if socket not found
|
||||
});
|
||||
|
||||
// Remove from active IDs
|
||||
setActiveConversationIds((prev) =>
|
||||
prev.filter((id) => id !== conversationId),
|
||||
);
|
||||
}, []);
|
||||
},
|
||||
[conversationSockets],
|
||||
);
|
||||
|
||||
const subscribeToConversation = useCallback(
|
||||
(options: {
|
||||
@@ -137,17 +137,10 @@ export function ConversationSubscriptionsProvider({
|
||||
sessionApiKey: string | null;
|
||||
providersSet: ("github" | "gitlab" | "bitbucket" | "enterprise_sso")[];
|
||||
baseUrl: string;
|
||||
socketPath?: string;
|
||||
onEvent?: (event: unknown, conversationId: string) => void;
|
||||
}) => {
|
||||
const {
|
||||
conversationId,
|
||||
sessionApiKey,
|
||||
providersSet,
|
||||
baseUrl,
|
||||
socketPath,
|
||||
onEvent,
|
||||
} = options;
|
||||
const { conversationId, sessionApiKey, providersSet, baseUrl, onEvent } =
|
||||
options;
|
||||
|
||||
// If already subscribed, don't create a new subscription
|
||||
if (conversationSockets[conversationId]) {
|
||||
@@ -180,7 +173,9 @@ export function ConversationSubscriptionsProvider({
|
||||
if (isErrorEvent(event) || isAgentStatusError(event)) {
|
||||
renderConversationErroredToast(
|
||||
conversationId,
|
||||
isErrorEvent(event) ? event.message : "MICROAGENT$UNKNOWN_ERROR",
|
||||
isErrorEvent(event)
|
||||
? event.message
|
||||
: "Unknown error, please try again",
|
||||
);
|
||||
} else if (isStatusUpdate(event)) {
|
||||
if (event.type === "info" && event.id === "STATUS$STARTING_RUNTIME") {
|
||||
@@ -204,7 +199,6 @@ export function ConversationSubscriptionsProvider({
|
||||
// Create socket connection
|
||||
const socket = io(baseUrl, {
|
||||
transports: ["websocket"],
|
||||
path: socketPath ?? "/socket.io",
|
||||
query: {
|
||||
conversation_id: conversationId,
|
||||
session_api_key: sessionApiKey,
|
||||
|
||||
@@ -317,24 +317,15 @@ export function WsClientProvider({
|
||||
session_api_key: conversation.session_api_key, // Have to set here because socketio doesn't support custom headers. :(
|
||||
};
|
||||
|
||||
let baseUrl: string | null = null;
|
||||
let socketPath: string;
|
||||
let baseUrl = null;
|
||||
if (conversation.url && !conversation.url.startsWith("/")) {
|
||||
const u = new URL(conversation.url);
|
||||
baseUrl = u.host;
|
||||
const pathBeforeApi = u.pathname.split("/api/conversations")[0] || "/";
|
||||
// Socket.IO server default path is /socket.io; prefix with pathBeforeApi for path mode
|
||||
socketPath = `${pathBeforeApi.replace(/\/$/, "")}/socket.io`;
|
||||
baseUrl = new URL(conversation.url).host;
|
||||
} else {
|
||||
baseUrl =
|
||||
(import.meta.env.VITE_BACKEND_BASE_URL as string | undefined) ||
|
||||
window?.location.host;
|
||||
socketPath = "/socket.io";
|
||||
baseUrl = import.meta.env.VITE_BACKEND_BASE_URL || window?.location.host;
|
||||
}
|
||||
|
||||
sio = io(baseUrl, {
|
||||
transports: ["websocket"],
|
||||
path: socketPath,
|
||||
query,
|
||||
});
|
||||
|
||||
|
||||
@@ -1,27 +1,14 @@
|
||||
import React from "react";
|
||||
import { useQueries, type Query } from "@tanstack/react-query";
|
||||
import toast from "react-hot-toast";
|
||||
import { AxiosError } from "axios";
|
||||
import { useCreateConversation } from "./mutation/use-create-conversation";
|
||||
import { useUserProviders } from "./use-user-providers";
|
||||
import { useConversationSubscriptions } from "#/context/conversation-subscriptions-provider";
|
||||
import { Provider } from "#/types/settings";
|
||||
import { CreateMicroagent, Conversation } from "#/api/open-hands.types";
|
||||
import OpenHands from "#/api/open-hands";
|
||||
import { renderConversationStartingToast } from "#/components/features/chat/microagent/microagent-status-toast";
|
||||
|
||||
interface ConversationData {
|
||||
conversationId: string;
|
||||
sessionApiKey: string | null;
|
||||
baseUrl: string;
|
||||
socketPath: string;
|
||||
onEventCallback?: (event: unknown, conversationId: string) => void;
|
||||
}
|
||||
import { CreateMicroagent } from "#/api/open-hands.types";
|
||||
|
||||
/**
|
||||
* Custom hook to create a conversation and subscribe to it, supporting multiple subscriptions.
|
||||
* This version waits for conversation status to be "RUNNING" before establishing WebSocket connection.
|
||||
* Shows immediate toast feedback and polls conversation status until ready.
|
||||
* This extends the functionality of useCreateConversationAndSubscribe to allow subscribing to
|
||||
* multiple conversations simultaneously.
|
||||
*/
|
||||
export const useCreateConversationAndSubscribeMultiple = () => {
|
||||
const { mutate: createConversation, isPending } = useCreateConversation();
|
||||
@@ -33,88 +20,6 @@ export const useCreateConversationAndSubscribeMultiple = () => {
|
||||
activeConversationIds,
|
||||
} = useConversationSubscriptions();
|
||||
|
||||
// Store conversation data immediately after creation
|
||||
const [createdConversations, setCreatedConversations] = React.useState<
|
||||
Record<string, ConversationData>
|
||||
>({});
|
||||
|
||||
// Get conversation IDs that need polling
|
||||
const conversationIdsToWatch = Object.keys(createdConversations);
|
||||
|
||||
// Poll each conversation until it's ready
|
||||
const conversationQueries = useQueries({
|
||||
queries: conversationIdsToWatch.map((conversationId) => ({
|
||||
queryKey: ["conversation-ready-poll", conversationId],
|
||||
queryFn: () => OpenHands.getConversation(conversationId),
|
||||
enabled: !!conversationId,
|
||||
refetchInterval: (query: Query<Conversation | null, AxiosError>) => {
|
||||
const status = query.state.data?.status;
|
||||
if (status === "STARTING") {
|
||||
return 3000; // Poll every 3 seconds while STARTING
|
||||
}
|
||||
return false; // Stop polling once not STARTING
|
||||
},
|
||||
retry: false,
|
||||
})),
|
||||
});
|
||||
|
||||
// Extract stable values from queries for dependency array
|
||||
const queryStatuses = conversationQueries.map((query) => query.data?.status);
|
||||
const queryDataExists = conversationQueries.map((query) => !!query.data);
|
||||
|
||||
// Effect to handle subscription when conversations are ready
|
||||
React.useEffect(() => {
|
||||
conversationQueries.forEach((query, index) => {
|
||||
const conversationId = conversationIdsToWatch[index];
|
||||
const conversationData = createdConversations[conversationId];
|
||||
|
||||
if (!query.data || !conversationData) return;
|
||||
|
||||
const { status, url, session_api_key: sessionApiKey } = query.data;
|
||||
|
||||
let { baseUrl } = conversationData;
|
||||
if (url && !url.startsWith("/")) {
|
||||
baseUrl = new URL(url).host;
|
||||
}
|
||||
|
||||
if (status === "RUNNING") {
|
||||
// Conversation is ready - subscribe to WebSocket
|
||||
subscribeToConversation({
|
||||
conversationId,
|
||||
sessionApiKey,
|
||||
providersSet: providers,
|
||||
baseUrl,
|
||||
socketPath: conversationData.socketPath,
|
||||
onEvent: conversationData.onEventCallback,
|
||||
});
|
||||
|
||||
// Remove from created conversations (cleanup)
|
||||
setCreatedConversations((prev) => {
|
||||
const newCreated = { ...prev };
|
||||
delete newCreated[conversationId];
|
||||
return newCreated;
|
||||
});
|
||||
} else if (status === "STOPPED") {
|
||||
// Dismiss the starting toast
|
||||
toast.dismiss(`starting-${conversationId}`);
|
||||
|
||||
// Remove from created conversations (cleanup)
|
||||
setCreatedConversations((prev) => {
|
||||
const newCreated = { ...prev };
|
||||
delete newCreated[conversationId];
|
||||
return newCreated;
|
||||
});
|
||||
}
|
||||
});
|
||||
}, [
|
||||
queryStatuses,
|
||||
queryDataExists,
|
||||
conversationIdsToWatch,
|
||||
createdConversations,
|
||||
subscribeToConversation,
|
||||
providers,
|
||||
]);
|
||||
|
||||
const createConversationAndSubscribe = React.useCallback(
|
||||
({
|
||||
query,
|
||||
@@ -144,46 +49,33 @@ export const useCreateConversationAndSubscribeMultiple = () => {
|
||||
},
|
||||
{
|
||||
onSuccess: (data) => {
|
||||
// Show immediate toast to let user know something is happening
|
||||
renderConversationStartingToast(data.conversation_id);
|
||||
|
||||
// Call the success callback immediately
|
||||
if (onSuccessCallback) {
|
||||
onSuccessCallback(data.conversation_id);
|
||||
}
|
||||
|
||||
// Only handle immediate post-creation tasks here
|
||||
let baseUrl = "";
|
||||
let socketPath: string;
|
||||
if (data?.url && !data.url.startsWith("/")) {
|
||||
const u = new URL(data.url);
|
||||
baseUrl = u.host;
|
||||
const pathBeforeApi =
|
||||
u.pathname.split("/api/conversations")[0] || "/";
|
||||
socketPath = `${pathBeforeApi.replace(/\/$/, "")}/socket.io`;
|
||||
baseUrl = new URL(data.url).host;
|
||||
} else {
|
||||
baseUrl =
|
||||
(import.meta.env.VITE_BACKEND_BASE_URL as string | undefined) ||
|
||||
window?.location.host;
|
||||
socketPath = "/socket.io";
|
||||
}
|
||||
|
||||
// Store conversation data for polling and eventual subscription
|
||||
setCreatedConversations((prev) => ({
|
||||
...prev,
|
||||
[data.conversation_id]: {
|
||||
conversationId: data.conversation_id,
|
||||
sessionApiKey: data.session_api_key,
|
||||
baseUrl,
|
||||
socketPath,
|
||||
onEventCallback,
|
||||
},
|
||||
}));
|
||||
// Subscribe to the conversation
|
||||
subscribeToConversation({
|
||||
conversationId: data.conversation_id,
|
||||
sessionApiKey: data.session_api_key,
|
||||
providersSet: providers,
|
||||
baseUrl,
|
||||
onEvent: onEventCallback,
|
||||
});
|
||||
|
||||
// Call the success callback if provided
|
||||
if (onSuccessCallback) {
|
||||
onSuccessCallback(data.conversation_id);
|
||||
}
|
||||
},
|
||||
},
|
||||
);
|
||||
},
|
||||
[createConversation],
|
||||
[createConversation, subscribeToConversation, providers],
|
||||
);
|
||||
|
||||
return {
|
||||
|
||||
@@ -357,7 +357,6 @@ export enum I18nKey {
|
||||
CHAT_INTERFACE$INPUT_PLACEHOLDER = "CHAT_INTERFACE$INPUT_PLACEHOLDER",
|
||||
CHAT_INTERFACE$INPUT_CONTINUE_MESSAGE = "CHAT_INTERFACE$INPUT_CONTINUE_MESSAGE",
|
||||
CHAT_INTERFACE$USER_ASK_CONFIRMATION = "CHAT_INTERFACE$USER_ASK_CONFIRMATION",
|
||||
CHAT_INTERFACE$HIGH_RISK_WARNING = "CHAT_INTERFACE$HIGH_RISK_WARNING",
|
||||
CHAT_INTERFACE$USER_CONFIRMED = "CHAT_INTERFACE$USER_CONFIRMED",
|
||||
CHAT_INTERFACE$USER_REJECTED = "CHAT_INTERFACE$USER_REJECTED",
|
||||
CHAT_INTERFACE$INPUT_SEND_MESSAGE_BUTTON_CONTENT = "CHAT_INTERFACE$INPUT_SEND_MESSAGE_BUTTON_CONTENT",
|
||||
@@ -372,6 +371,10 @@ export enum I18nKey {
|
||||
CHAT_INTERFACE$MESSAGE_ARIA_LABEL = "CHAT_INTERFACE$MESSAGE_ARIA_LABEL",
|
||||
CHAT_INTERFACE$CHAT_CONVERSATION = "CHAT_INTERFACE$CHAT_CONVERSATION",
|
||||
CHAT_INTERFACE$UNKNOWN_SENDER = "CHAT_INTERFACE$UNKNOWN_SENDER",
|
||||
SECURITY_ANALYZER$UNKNOWN_RISK = "SECURITY_ANALYZER$UNKNOWN_RISK",
|
||||
SECURITY_ANALYZER$LOW_RISK = "SECURITY_ANALYZER$LOW_RISK",
|
||||
SECURITY_ANALYZER$MEDIUM_RISK = "SECURITY_ANALYZER$MEDIUM_RISK",
|
||||
SECURITY_ANALYZER$HIGH_RISK = "SECURITY_ANALYZER$HIGH_RISK",
|
||||
SETTINGS$MODEL_TOOLTIP = "SETTINGS$MODEL_TOOLTIP",
|
||||
SETTINGS$AGENT_TOOLTIP = "SETTINGS$AGENT_TOOLTIP",
|
||||
SETTINGS$LANGUAGE_TOOLTIP = "SETTINGS$LANGUAGE_TOOLTIP",
|
||||
@@ -382,12 +385,9 @@ export enum I18nKey {
|
||||
SETTINGS$REFRESH_LLM_API_KEY = "SETTINGS$REFRESH_LLM_API_KEY",
|
||||
SETTINGS$CONFIRMATION_MODE = "SETTINGS$CONFIRMATION_MODE",
|
||||
SETTINGS$CONFIRMATION_MODE_TOOLTIP = "SETTINGS$CONFIRMATION_MODE_TOOLTIP",
|
||||
SETTINGS$CONFIRMATION_MODE_LOCK_TOOLTIP = "SETTINGS$CONFIRMATION_MODE_LOCK_TOOLTIP",
|
||||
SETTINGS$AGENT_SELECT_ENABLED = "SETTINGS$AGENT_SELECT_ENABLED",
|
||||
SETTINGS$SECURITY_ANALYZER = "SETTINGS$SECURITY_ANALYZER",
|
||||
SETTINGS$SECURITY_ANALYZER_PLACEHOLDER = "SETTINGS$SECURITY_ANALYZER_PLACEHOLDER",
|
||||
SETTINGS$SECURITY_ANALYZER_TOOLTIP = "SETTINGS$SECURITY_ANALYZER_TOOLTIP",
|
||||
SETTINGS$SECURITY_ANALYZER_DESCRIPTION = "SETTINGS$SECURITY_ANALYZER_DESCRIPTION",
|
||||
SETTINGS$DONT_KNOW_API_KEY = "SETTINGS$DONT_KNOW_API_KEY",
|
||||
SETTINGS$CLICK_FOR_INSTRUCTIONS = "SETTINGS$CLICK_FOR_INSTRUCTIONS",
|
||||
SETTINGS$SAVED = "SETTINGS$SAVED",
|
||||
@@ -781,6 +781,8 @@ export enum I18nKey {
|
||||
PROJECT_MANAGEMENT$SVC_ACC_EMAIL_VALIDATION_ERROR = "PROJECT_MANAGEMENT$SVC_ACC_EMAIL_VALIDATION_ERROR",
|
||||
PROJECT_MANAGEMENT$SVC_ACC_API_KEY_VALIDATION_ERROR = "PROJECT_MANAGEMENT$SVC_ACC_API_KEY_VALIDATION_ERROR",
|
||||
MICROAGENT_MANAGEMENT$ERROR_LOADING_MICROAGENT_CONTENT = "MICROAGENT_MANAGEMENT$ERROR_LOADING_MICROAGENT_CONTENT",
|
||||
SETTINGS$MCP_ERROR_ENV_INVALID_FORMAT = "SETTINGS$MCP_ERROR_ENV_INVALID_FORMAT",
|
||||
SETTINGS$MCP_ERROR_URL_DUPLICATE = "SETTINGS$MCP_ERROR_URL_DUPLICATE",
|
||||
SETTINGS$MCP_SERVER_TYPE_SSE = "SETTINGS$MCP_SERVER_TYPE_SSE",
|
||||
SETTINGS$MCP_SERVER_TYPE_STDIO = "SETTINGS$MCP_SERVER_TYPE_STDIO",
|
||||
SETTINGS$MCP_SERVER_TYPE_SHTTP = "SETTINGS$MCP_SERVER_TYPE_SHTTP",
|
||||
@@ -792,8 +794,6 @@ export enum I18nKey {
|
||||
SETTINGS$MCP_ERROR_NAME_DUPLICATE = "SETTINGS$MCP_ERROR_NAME_DUPLICATE",
|
||||
SETTINGS$MCP_ERROR_COMMAND_REQUIRED = "SETTINGS$MCP_ERROR_COMMAND_REQUIRED",
|
||||
SETTINGS$MCP_ERROR_COMMAND_NO_SPACES = "SETTINGS$MCP_ERROR_COMMAND_NO_SPACES",
|
||||
SETTINGS$MCP_ERROR_URL_DUPLICATE = "SETTINGS$MCP_ERROR_URL_DUPLICATE",
|
||||
SETTINGS$MCP_ERROR_ENV_INVALID_FORMAT = "SETTINGS$MCP_ERROR_ENV_INVALID_FORMAT",
|
||||
SETTINGS$MCP_SERVER_TYPE = "SETTINGS$MCP_SERVER_TYPE",
|
||||
SETTINGS$MCP_API_KEY_PLACEHOLDER = "SETTINGS$MCP_API_KEY_PLACEHOLDER",
|
||||
SETTINGS$MCP_COMMAND_ARGUMENTS = "SETTINGS$MCP_COMMAND_ARGUMENTS",
|
||||
@@ -814,13 +814,4 @@ export enum I18nKey {
|
||||
MICROAGENT_MANAGEMENT$PR_READY_FOR_REVIEW = "MICROAGENT_MANAGEMENT$PR_READY_FOR_REVIEW",
|
||||
MICROAGENT_MANAGEMENT$PR_NOT_CREATED = "MICROAGENT_MANAGEMENT$PR_NOT_CREATED",
|
||||
MICROAGENT_MANAGEMENT$ERROR_CREATING_MICROAGENT = "MICROAGENT_MANAGEMENT$ERROR_CREATING_MICROAGENT",
|
||||
MICROAGENT$STATUS_WAITING = "MICROAGENT$STATUS_WAITING",
|
||||
MICROAGENT$UNKNOWN_ERROR = "MICROAGENT$UNKNOWN_ERROR",
|
||||
MICROAGENT$CONVERSATION_STARTING = "MICROAGENT$CONVERSATION_STARTING",
|
||||
MICROAGENT_MANAGEMENT$EXISTING_MICROAGENTS = "MICROAGENT_MANAGEMENT$EXISTING_MICROAGENTS",
|
||||
MICROAGENT_MANAGEMENT$OPEN_MICROAGENT_PULL_REQUESTS = "MICROAGENT_MANAGEMENT$OPEN_MICROAGENT_PULL_REQUESTS",
|
||||
SETTINGS$SECURITY_ANALYZER_LLM_DEFAULT = "SETTINGS$SECURITY_ANALYZER_LLM_DEFAULT",
|
||||
SETTINGS$SECURITY_ANALYZER_NONE = "SETTINGS$SECURITY_ANALYZER_NONE",
|
||||
SETTINGS$SECURITY_ANALYZER_INVARIANT = "SETTINGS$SECURITY_ANALYZER_INVARIANT",
|
||||
COMMON$HIGH_RISK = "COMMON$HIGH_RISK",
|
||||
}
|
||||
|
||||
@@ -432,68 +432,68 @@
|
||||
"uk": "Повторний вхід до OpenHands..."
|
||||
},
|
||||
"SECURITY$LOW_RISK": {
|
||||
"en": "Risk: Low",
|
||||
"ja": "リスク: 低",
|
||||
"zh-CN": "风险: 低",
|
||||
"zh-TW": "風險: 低",
|
||||
"ko-KR": "위험: 낮음",
|
||||
"no": "Risiko: Lav",
|
||||
"it": "Rischio: Basso",
|
||||
"pt": "Risco: Baixo",
|
||||
"es": "Riesgo: Bajo",
|
||||
"ar": "المخاطر: منخفضة",
|
||||
"fr": "Risque : Faible",
|
||||
"tr": "Risk: Düşük",
|
||||
"de": "Risiko: Gering",
|
||||
"uk": "Ризик: Низький"
|
||||
"en": "Low Risk",
|
||||
"ja": "低リスク",
|
||||
"zh-CN": "低风险",
|
||||
"zh-TW": "低風險",
|
||||
"ko-KR": "낮은 위험",
|
||||
"no": "Lav risiko",
|
||||
"it": "Rischio basso",
|
||||
"pt": "Baixo risco",
|
||||
"es": "Riesgo bajo",
|
||||
"ar": "مخاطر منخفضة",
|
||||
"fr": "Risque faible",
|
||||
"tr": "Düşük risk",
|
||||
"de": "Geringes Risiko",
|
||||
"uk": "Низький ризик"
|
||||
},
|
||||
"SECURITY$MEDIUM_RISK": {
|
||||
"en": "Risk: Medium",
|
||||
"ja": "リスク: 中",
|
||||
"zh-CN": "风险: 中等",
|
||||
"zh-TW": "風險: 中等",
|
||||
"ko-KR": "위험: 중간",
|
||||
"no": "Risiko: Middels",
|
||||
"it": "Rischio: Medio",
|
||||
"pt": "Risco: Médio",
|
||||
"es": "Riesgo: Medio",
|
||||
"ar": "المخاطر: متوسطة",
|
||||
"fr": "Risque : Moyen",
|
||||
"tr": "Risk: Orta",
|
||||
"de": "Risiko: Mittel",
|
||||
"uk": "Ризик: Середній"
|
||||
"en": "Medium Risk",
|
||||
"ja": "中リスク",
|
||||
"zh-CN": "中等风险",
|
||||
"zh-TW": "中等風險",
|
||||
"ko-KR": "중간 위험",
|
||||
"no": "Middels risiko",
|
||||
"it": "Rischio medio",
|
||||
"pt": "Risco médio",
|
||||
"es": "Riesgo medio",
|
||||
"ar": "مخاطر متوسطة",
|
||||
"fr": "Risque moyen",
|
||||
"tr": "Orta risk",
|
||||
"de": "Mittleres Risiko",
|
||||
"uk": "Середній ризик"
|
||||
},
|
||||
"SECURITY$HIGH_RISK": {
|
||||
"en": "Risk: High",
|
||||
"ja": "リスク: 高",
|
||||
"zh-CN": "风险: 高",
|
||||
"zh-TW": "風險: 高",
|
||||
"ko-KR": "위험: 높음",
|
||||
"no": "Risiko: Høy",
|
||||
"it": "Rischio: Alto",
|
||||
"pt": "Risco: Alto",
|
||||
"es": "Riesgo: Alto",
|
||||
"ar": "المخاطر: عالية",
|
||||
"fr": "Risque : Élevé",
|
||||
"tr": "Risk: Yüksek",
|
||||
"de": "Risiko: Hoch",
|
||||
"uk": "Ризик: Високий"
|
||||
"en": "High Risk",
|
||||
"ja": "高リスク",
|
||||
"zh-CN": "高风险",
|
||||
"zh-TW": "高風險",
|
||||
"ko-KR": "높은 위험",
|
||||
"no": "Høy risiko",
|
||||
"it": "Rischio alto",
|
||||
"pt": "Alto risco",
|
||||
"es": "Riesgo alto",
|
||||
"ar": "مخاطر عالية",
|
||||
"fr": "Risque élevé",
|
||||
"tr": "Yüksek risk",
|
||||
"de": "Hohes Risiko",
|
||||
"uk": "Високий ризик"
|
||||
},
|
||||
"SECURITY$UNKNOWN_RISK": {
|
||||
"en": "Risk: Unknown",
|
||||
"ja": "リスク: 不明",
|
||||
"zh-CN": "风险: 未知",
|
||||
"zh-TW": "風險: 未知",
|
||||
"ko-KR": "위험: 알 수 없음",
|
||||
"no": "Risiko: Ukjent",
|
||||
"it": "Rischio: Sconosciuto",
|
||||
"pt": "Risco: Desconhecido",
|
||||
"es": "Riesgo: Desconocido",
|
||||
"ar": "المخاطر: غير معروفة",
|
||||
"fr": "Risque : Inconnu",
|
||||
"tr": "Risk: Bilinmeyen",
|
||||
"de": "Risiko: Unbekannt",
|
||||
"uk": "Ризик: Невідомий"
|
||||
"en": "Unknown Risk",
|
||||
"ja": "不明なリスク",
|
||||
"zh-CN": "未知风险",
|
||||
"zh-TW": "未知風險",
|
||||
"ko-KR": "알 수 없는 위험",
|
||||
"no": "Ukjent risiko",
|
||||
"it": "Rischio sconosciuto",
|
||||
"pt": "Risco desconhecido",
|
||||
"es": "Riesgo desconocido",
|
||||
"ar": "مخاطر غير معروفة",
|
||||
"fr": "Risque inconnu",
|
||||
"tr": "Bilinmeyen risk",
|
||||
"de": "Unbekanntes Risiko",
|
||||
"uk": "Невідомий ризик"
|
||||
},
|
||||
"FINISH$TASK_COMPLETED_SUCCESSFULLY": {
|
||||
"en": "I believe that the task was **completed successfully**.",
|
||||
@@ -2432,20 +2432,20 @@
|
||||
"uk": "Git налаштування"
|
||||
},
|
||||
"SETTINGS$GIT_SETTINGS_DESCRIPTION": {
|
||||
"en": "Configure the username and email that OpenHands uses to commit changes.",
|
||||
"ja": "OpenHandsがコミットに使用するユーザー名とメールを設定します。",
|
||||
"zh-CN": "配置OpenHands用于提交更改的用户名和电子邮件。",
|
||||
"zh-TW": "配置OpenHands用於提交更改的用戶名和電子郵件。",
|
||||
"ko-KR": "OpenHands가 변경 사항을 커밋할 때 사용하는 사용자 이름과 이메일을 구성합니다.",
|
||||
"de": "Konfigurieren Sie den Benutzernamen und die E-Mail, die OpenHands zum Committen von Änderungen verwendet.",
|
||||
"no": "Konfigurer brukernavnet og e-posten som OpenHands bruker for å committe endringer.",
|
||||
"it": "Configura il nome utente e l'email che OpenHands utilizza per committare le modifiche.",
|
||||
"pt": "Configure o nome de usuário e o email que o OpenHands usa para fazer commits de alterações.",
|
||||
"es": "Configure el nombre de usuario y el correo electrónico que OpenHands utiliza para confirmar cambios.",
|
||||
"ar": "قم بتكوين اسم المستخدم والبريد الإلكتروني الذي يستخدمه OpenHands لارتكاب التغييرات.",
|
||||
"fr": "Configurez le nom d'utilisateur et l'email qu'OpenHands utilise pour valider les modifications.",
|
||||
"tr": "OpenHands'ın değişiklikleri commit etmek için kullandığı kullanıcı adını ve e-postayı yapılandırın.",
|
||||
"uk": "Налаштуйте ім'я користувача та електронну пошту, які OpenHands використовує для фіксації змін."
|
||||
"en": "Configure Git integration settings",
|
||||
"ja": "Git統合設定を構成する",
|
||||
"zh-CN": "配置Git集成设置",
|
||||
"zh-TW": "配置Git整合設定",
|
||||
"ko-KR": "Git 통합 설정 구성",
|
||||
"de": "Git-Integrationseinstellungen konfigurieren",
|
||||
"no": "Konfigurer Git-integrasjonsinnstillinger",
|
||||
"it": "Configura le impostazioni di integrazione Git",
|
||||
"pt": "Configure as configurações de integração Git",
|
||||
"es": "Configure los ajustes de integración Git",
|
||||
"ar": "تكوين إعدادات تكامل Git",
|
||||
"fr": "Configurer les paramètres d'intégration Git",
|
||||
"tr": "Git entegrasyon ayarlarını yapılandırın",
|
||||
"uk": "Налаштуйте параметри інтеграції Git"
|
||||
},
|
||||
"SETTINGS$SOUND_NOTIFICATIONS": {
|
||||
"en": "Sound Notifications",
|
||||
@@ -2520,11 +2520,11 @@
|
||||
"de": "Lösbarkeitsanalyse aktivieren",
|
||||
"no": "Aktiver løsningsanalyse",
|
||||
"it": "Abilita analisi di risolvibilità",
|
||||
"pt": "Ativar análise de solucionabilidade",
|
||||
"es": "Habilitar análisis de solvencia",
|
||||
"pt": "Ativar análise de resolubilidade",
|
||||
"es": "Habilitar análisis de resolubilidad",
|
||||
"ar": "تمكين تحليل القابلية للحل",
|
||||
"fr": "Activer l'analyse de solvabilité",
|
||||
"tr": "Çözünürlük Analizini Etkinleştir",
|
||||
"fr": "Activer l'analyse de résolvabilité",
|
||||
"tr": "Çözülebilirlik analizini etkinleştir",
|
||||
"uk": "Увімкнути аналіз розв'язності"
|
||||
},
|
||||
"SETTINGS$SEARCH_API_KEY": {
|
||||
@@ -5711,22 +5711,6 @@
|
||||
"ja": "このアクションを実行してもよろしいですか?",
|
||||
"uk": "Ви хочете продовжити цю дію?"
|
||||
},
|
||||
"CHAT_INTERFACE$HIGH_RISK_WARNING": {
|
||||
"en": "Review carefully before proceeding.",
|
||||
"zh-CN": "在继续之前请仔细检查。",
|
||||
"de": "Überprüfen Sie sorgfältig, bevor Sie fortfahren.",
|
||||
"zh-TW": "在繼續之前請仔細檢查。",
|
||||
"ko-KR": "계속하기 전에 신중히 검토하세요.",
|
||||
"no": "Gå nøye gjennom før du fortsetter.",
|
||||
"it": "Esamina attentamente prima di procedere.",
|
||||
"pt": "Revise cuidadosamente antes de prosseguir.",
|
||||
"es": "Revise cuidadosamente antes de continuar.",
|
||||
"ar": "يرجى المراجعة بعناية قبل المتابعة.",
|
||||
"fr": "Examinez attentivement avant de continuer.",
|
||||
"tr": "Devam etmeden önce dikkatlice gözden geçirin.",
|
||||
"ja": "続行する前に慎重に確認してください。",
|
||||
"uk": "Уважно перевірте перед продовженням."
|
||||
},
|
||||
"CHAT_INTERFACE$USER_CONFIRMED": {
|
||||
"en": "Confirm the requested action",
|
||||
"de": "Bestätigen Sie die angeforderte Aktion",
|
||||
@@ -5951,6 +5935,70 @@
|
||||
"ja": "不明な送信者",
|
||||
"uk": "Невідомий"
|
||||
},
|
||||
"SECURITY_ANALYZER$UNKNOWN_RISK": {
|
||||
"en": "Unknown Risk",
|
||||
"de": "Unbekanntes Risiko",
|
||||
"zh-CN": "未知风险",
|
||||
"ko-KR": "알 수 없는 위험",
|
||||
"no": "Ukjent risiko",
|
||||
"zh-TW": "未知風險",
|
||||
"it": "Rischio sconosciuto",
|
||||
"pt": "Risco desconhecido",
|
||||
"es": "Riesgo desconocido",
|
||||
"ar": "مخاطر غير معروفة",
|
||||
"fr": "Risque inconnu",
|
||||
"tr": "Bilinmeyen risk",
|
||||
"ja": "不明なリスク",
|
||||
"uk": "Невідомий ризик"
|
||||
},
|
||||
"SECURITY_ANALYZER$LOW_RISK": {
|
||||
"en": "Low Risk",
|
||||
"de": "Niedriges Risiko",
|
||||
"zh-CN": "低风险",
|
||||
"ko-KR": "낮은 위험",
|
||||
"no": "Lav risiko",
|
||||
"zh-TW": "低風險",
|
||||
"it": "Rischio basso",
|
||||
"pt": "Baixo risco",
|
||||
"es": "Riesgo bajo",
|
||||
"ar": "مخاطر منخفضة",
|
||||
"fr": "Risque faible",
|
||||
"tr": "Düşük risk",
|
||||
"ja": "低リスク",
|
||||
"uk": "Низький ризик"
|
||||
},
|
||||
"SECURITY_ANALYZER$MEDIUM_RISK": {
|
||||
"en": "Medium Risk",
|
||||
"de": "Mittleres Risiko",
|
||||
"zh-CN": "中等风险",
|
||||
"ko-KR": "중간 위험",
|
||||
"no": "Middels risiko",
|
||||
"zh-TW": "中等風險",
|
||||
"it": "Rischio medio",
|
||||
"pt": "Risco médio",
|
||||
"es": "Riesgo medio",
|
||||
"ar": "مخاطر متوسطة",
|
||||
"fr": "Risque moyen",
|
||||
"tr": "Orta risk",
|
||||
"ja": "中リスク",
|
||||
"uk": "Середній ризик"
|
||||
},
|
||||
"SECURITY_ANALYZER$HIGH_RISK": {
|
||||
"en": "High Risk",
|
||||
"de": "Hohes Risiko",
|
||||
"zh-CN": "高风险",
|
||||
"ko-KR": "높은 위험",
|
||||
"no": "Høy risiko",
|
||||
"zh-TW": "高風險",
|
||||
"it": "Rischio elevato",
|
||||
"pt": "Alto risco",
|
||||
"es": "Riesgo alto",
|
||||
"ar": "مخاطر عالية",
|
||||
"fr": "Risque élevé",
|
||||
"tr": "Yüksek risk",
|
||||
"ja": "高リスク",
|
||||
"uk": "Високий ризик"
|
||||
},
|
||||
"SETTINGS$MODEL_TOOLTIP": {
|
||||
"en": "Select the language model to use.",
|
||||
"zh-CN": "选择要使用的语言模型",
|
||||
@@ -6111,22 +6159,6 @@
|
||||
"ja": "エージェントのアクションを実行前に確認",
|
||||
"uk": "Очікує підтвердження користувача перед виконанням коду."
|
||||
},
|
||||
"SETTINGS$CONFIRMATION_MODE_LOCK_TOOLTIP": {
|
||||
"en": "The agent is in confirmation mode. It will prompt the user to confirm certain actions when security analyzer policy detected a high-risk action. Click this icon to go to settings tab for more information.",
|
||||
"de": "Der Agent befindet sich im Bestätigungsmodus. Er wird den Benutzer auffordern, bestimmte Aktionen zu bestätigen, wenn die Sicherheitsanalysator-Richtlinie eine risikoreiche Aktion erkannt hat. Weitere Informationen finden Sie auf der Registerkarte Einstellungen.",
|
||||
"zh-CN": "代理处于确认模式。当安全分析器策略检测到高风险操作时,它会提示用户确认某些操作。查看设置选项卡了解更多信息。",
|
||||
"zh-TW": "代理處於確認模式。當安全分析器策略檢測到高風險操作時,它會提示使用者確認某些操作。查看設定選項卡了解更多資訊。",
|
||||
"ko-KR": "에이전트가 확인 모드에 있습니다. 보안 분석기 정책이 고위험 작업을 감지하면 사용자에게 특정 작업을 확인하도록 요청합니다. 자세한 내용은 설정 탭을 확인하세요.",
|
||||
"no": "Agenten er i bekreftelsesmodus. Den vil be brukeren om å bekrefte visse handlinger når sikkerhetsanalysatorpolitikken oppdager en høyrisiko-handling. Sjekk innstillingsfanen for mer informasjon.",
|
||||
"it": "L'agente è in modalità di conferma. Chiederà all'utente di confermare certe azioni quando la politica dell'analizzatore di sicurezza rileva un'azione ad alto rischio. Controlla la scheda impostazioni per maggiori informazioni.",
|
||||
"pt": "O agente está no modo de confirmação. Ele solicitará ao usuário que confirme certas ações quando a política do analisador de segurança detectar uma ação de alto risco. Verifique a aba de configurações para mais informações.",
|
||||
"es": "El agente está en modo de confirmación. Solicitará al usuario que confirme ciertas acciones cuando la política del analizador de seguridad detecte una acción de alto riesgo. Consulte la pestaña de configuración para obtener más información.",
|
||||
"ar": "الوكيل في وضع التأكيد. سيطلب من المستخدم تأكيد إجراءات معينة عندما تكتشف سياسة محلل الأمان إجراءً عالي المخاطر. تحقق من علامة تبويب الإعدادات للحصول على مزيد من المعلومات.",
|
||||
"fr": "L'agent est en mode de confirmation. Il demandera à l'utilisateur de confirmer certaines actions lorsque la politique de l'analyseur de sécurité détecte une action à haut risque. Consultez l'onglet paramètres pour plus d'informations.",
|
||||
"tr": "Ajan onay modunda. Güvenlik analizörü politikası yüksek riskli bir eylem tespit ettiğinde kullanıcıdan belirli eylemleri onaylamasını isteyecek. Daha fazla bilgi için ayarlar sekmesini kontrol edin.",
|
||||
"ja": "エージェントは確認モードです。セキュリティアナライザーポリシーが高リスクアクションを検出した場合、特定のアクションの確認をユーザーに求めます。詳細については設定タブを確認してください。",
|
||||
"uk": "Агент знаходиться в режимі підтвердження. Він попросить користувача підтвердити певні дії, коли політика аналізатора безпеки виявить дію високого ризику. Перевірте вкладку налаштувань для отримання додаткової інформації."
|
||||
},
|
||||
"SETTINGS$AGENT_SELECT_ENABLED": {
|
||||
"en": "Enable Agent Selection - Advanced Users",
|
||||
"zh-CN": "启用智能体选择 - 高级用户",
|
||||
@@ -6175,38 +6207,6 @@
|
||||
"ja": "セキュリティアナライザーを選択…",
|
||||
"uk": "Виберіть аналізатор безпеки…"
|
||||
},
|
||||
"SETTINGS$SECURITY_ANALYZER_TOOLTIP": {
|
||||
"en": "When enabled, the agent will pause and ask for confirmation when it tries to execute high-risk actions",
|
||||
"de": "Wenn aktiviert, pausiert der Agent und fragt nach Bestätigung, wenn er versucht, risikoreiche Aktionen auszuführen",
|
||||
"zh-CN": "启用后,代理在尝试执行高风险操作时会暂停并要求确认",
|
||||
"zh-TW": "啟用後,代理在嘗試執行高風險操作時會暫停並要求確認",
|
||||
"ko-KR": "활성화되면 에이전트가 고위험 작업을 실행하려고 할 때 일시 중지하고 확인을 요청합니다",
|
||||
"no": "Når aktivert, vil agenten pause og be om bekreftelse når den prøver å utføre høyrisiko-handlinger",
|
||||
"it": "Quando abilitato, l'agente si fermerà e chiederà conferma quando tenta di eseguire azioni ad alto rischio",
|
||||
"pt": "Quando ativado, o agente pausará e pedirá confirmação quando tentar executar ações de alto risco",
|
||||
"es": "Cuando está habilitado, el agente se pausará y pedirá confirmación cuando trate de ejecutar acciones de alto riesgo",
|
||||
"ar": "عند التمكين، سيتوقف الوكيل ويطلب التأكيد عندما يحاول تنفيذ إجراءات عالية المخاطر",
|
||||
"fr": "Lorsqu'il est activé, l'agent se mettra en pause et demandera confirmation lorsqu'il tentera d'exécuter des actions à haut risque",
|
||||
"tr": "Etkinleştirildiğinde, ajan yüksek riskli eylemleri gerçekleştirmeye çalıştığında duraklar ve onay ister",
|
||||
"ja": "有効にすると、エージェントは高リスクなアクションを実行しようとする際に一時停止し、確認を求めます",
|
||||
"uk": "Коли увімкнено, агент зупиниться і попросить підтвердження, коли спробує виконати дії високого ризику"
|
||||
},
|
||||
"SETTINGS$SECURITY_ANALYZER_DESCRIPTION": {
|
||||
"en": "The security analyzer will be used in conjunction with confirmation mode. By default, it utilizes LLM-predicted action risk to determine whether to prompt the user for confirmation. If the risk is HIGH, it will prompt the user for confirmation by default.",
|
||||
"de": "Der Sicherheitsanalysator wird in Verbindung mit dem Bestätigungsmodus verwendet. Standardmäßig nutzt er LLM-vorhergesagtes Aktionsrisiko, um zu bestimmen, ob der Benutzer zur Bestätigung aufgefordert werden soll. Wenn das Risiko HOCH ist, wird er standardmäßig zur Bestätigung auffordern.",
|
||||
"zh-CN": "安全分析器将与确认模式结合使用。默认情况下,它利用LLM预测的操作风险来确定是否提示用户确认。如果风险为高,它将默认提示用户确认。",
|
||||
"zh-TW": "安全分析器將與確認模式結合使用。預設情況下,它利用LLM預測的操作風險來確定是否提示用戶確認。如果風險為高,它將預設提示用戶確認。",
|
||||
"ko-KR": "보안 분석기는 확인 모드와 함께 사용됩니다. 기본적으로 LLM이 예측한 작업 위험을 활용하여 사용자에게 확인을 요청할지 결정합니다. 위험이 높으면 기본적으로 사용자에게 확인을 요청합니다.",
|
||||
"no": "Sikkerhetsanalysatoren vil bli brukt i forbindelse med bekreftelsesmodus. Som standard bruker den LLM-forutsagt handlingsrisiko for å bestemme om brukeren skal bli bedt om bekreftelse. Hvis risikoen er HØY, vil den be om bekreftelse som standard.",
|
||||
"it": "L'analizzatore di sicurezza verrà utilizzato insieme alla modalità di conferma. Per impostazione predefinita, utilizza il rischio di azione previsto dall'LLM per determinare se richiedere conferma all'utente. Se il rischio è ALTO, richiederà conferma per impostazione predefinita.",
|
||||
"pt": "O analisador de segurança será usado em conjunto com o modo de confirmação. Por padrão, utiliza o risco de ação previsto pelo LLM para determinar se deve solicitar confirmação ao usuário. Se o risco for ALTO, solicitará confirmação por padrão.",
|
||||
"es": "El analizador de seguridad se utilizará junto con el modo de confirmación. Por defecto, utiliza el riesgo de acción predicho por LLM para determinar si solicitar confirmación al usuario. Si el riesgo es ALTO, solicitará confirmación por defecto.",
|
||||
"ar": "سيتم استخدام محلل الأمان بالتزامن مع وضع التأكيد. افتراضياً، يستخدم مخاطر الإجراء المتوقعة من LLM لتحديد ما إذا كان يجب مطالبة المستخدم بالتأكيد. إذا كان الخطر عالياً، فسيطالب بالتأكيد افتراضياً.",
|
||||
"fr": "L'analyseur de sécurité sera utilisé en conjonction avec le mode de confirmation. Par défaut, il utilise le risque d'action prédit par LLM pour déterminer s'il faut demander confirmation à l'utilisateur. Si le risque est ÉLEVÉ, il demandera confirmation par défaut.",
|
||||
"tr": "Güvenlik analizörü onay modu ile birlikte kullanılacaktır. Varsayılan olarak, kullanıcıdan onay istenip istenmeyeceğini belirlemek için LLM tarafından tahmin edilen eylem riskini kullanır. Risk YÜKSEK ise, varsayılan olarak kullanıcıdan onay isteyecektir.",
|
||||
"ja": "セキュリティアナライザーは確認モードと組み合わせて使用されます。デフォルトでは、LLMが予測したアクションリスクを利用して、ユーザーに確認を求めるかどうかを決定します。リスクが高い場合、デフォルトでユーザーに確認を求めます。",
|
||||
"uk": "Аналізатор безпеки буде використовуватися разом з режимом підтвердження. За замовчуванням він використовує передбачений LLM ризик дії для визначення, чи потрібно запитувати підтвердження у користувача. Якщо ризик ВИСОКИЙ, він запитуватиме підтвердження за замовчуванням."
|
||||
},
|
||||
"SETTINGS$DONT_KNOW_API_KEY": {
|
||||
"en": "Don't know your API key?",
|
||||
"ja": "APIキーがわかりませんか?",
|
||||
@@ -11536,20 +11536,20 @@
|
||||
"uk": "Визначте тригери для мікроагента"
|
||||
},
|
||||
"MICROAGENT_MANAGEMENT$HELP_TEXT_DESCRIBING_VALID_TRIGGERS": {
|
||||
"en": "Enter a keyword that OpenHands will use to trigger this microagent (Optional).",
|
||||
"ja": "OpenHandsがこのマイクロエージェントを起動するために使用するキーワードを入力してください(任意)。",
|
||||
"zh-CN": "输入OpenHands将用于触发此微代理的关键字(可选)。",
|
||||
"zh-TW": "輸入OpenHands將用於觸發此微代理的關鍵字(可選)。",
|
||||
"ko-KR": "OpenHands가 이 마이크로에이전트를 트리거하는 데 사용할 키워드를 입력하세요(선택 사항).",
|
||||
"no": "Skriv inn et nøkkelord som OpenHands vil bruke for å utløse denne mikroagenten (valgfritt).",
|
||||
"it": "Inserisci una parola chiave che OpenHands userà per attivare questo microagent (opzionale).",
|
||||
"pt": "Digite uma palavra-chave que o OpenHands usará para acionar este microagente (Opcional).",
|
||||
"es": "Introduce una palabra clave que OpenHands usará para activar este microagente (Opcional).",
|
||||
"ar": "أدخل كلمة مفتاحية سيستخدمها OpenHands لتشغيل هذا الوكيل الصغير (اختياري).",
|
||||
"fr": "Entrez un mot-clé qu'OpenHands utilisera pour déclencher ce microagent (facultatif).",
|
||||
"tr": "OpenHands'ın bu mikro ajanı tetiklemek için kullanacağı bir anahtar kelime girin (İsteğe bağlı).",
|
||||
"de": "Geben Sie ein Schlüsselwort ein, das OpenHands verwendet, um diesen Microagenten auszulösen (optional).",
|
||||
"uk": "Введіть ключове слово, яке OpenHands використовуватиме для запуску цього мікроагента (необов'язково)."
|
||||
"en": "Help text describing valid triggers.",
|
||||
"ja": "有効なトリガーについて説明するヘルプテキスト。",
|
||||
"zh-CN": "描述有效触发器的帮助文本。",
|
||||
"zh-TW": "描述有效觸發條件的說明文字。",
|
||||
"ko-KR": "유효한 트리거를 설명하는 도움말 텍스트입니다.",
|
||||
"no": "Hjelpetekst som beskriver gyldige utløsere.",
|
||||
"it": "Testo di aiuto che descrive i trigger validi.",
|
||||
"pt": "Texto de ajuda descrevendo gatilhos válidos.",
|
||||
"es": "Texto de ayuda que describe desencadenantes válidos.",
|
||||
"ar": "نص المساعدة الذي يصف المشغلات الصالحة.",
|
||||
"fr": "Texte d'aide décrivant les déclencheurs valides.",
|
||||
"tr": "Geçerli tetikleyicileri açıklayan yardım metni.",
|
||||
"de": "Hilfetext, der gültige Auslöser beschreibt.",
|
||||
"uk": "Текст довідки, що описує дійсні тригери."
|
||||
},
|
||||
"COMMON$FOR_EXAMPLE": {
|
||||
"en": "For example",
|
||||
@@ -12495,6 +12495,38 @@
|
||||
"de": "Fehler beim Laden des Microagent-Inhalts.",
|
||||
"uk": "Помилка під час завантаження вмісту мікроагента."
|
||||
},
|
||||
"SETTINGS$MCP_ERROR_ENV_INVALID_FORMAT": {
|
||||
"en": "Environment variables must follow KEY=value format",
|
||||
"ja": "Environment variables must follow KEY=value format",
|
||||
"zh-CN": "Environment variables must follow KEY=value format",
|
||||
"zh-TW": "Environment variables must follow KEY=value format",
|
||||
"ko-KR": "Environment variables must follow KEY=value format",
|
||||
"no": "Environment variables must follow KEY=value format",
|
||||
"it": "Environment variables must follow KEY=value format",
|
||||
"pt": "Environment variables must follow KEY=value format",
|
||||
"es": "Environment variables must follow KEY=value format",
|
||||
"ar": "Environment variables must follow KEY=value format",
|
||||
"fr": "Environment variables must follow KEY=value format",
|
||||
"tr": "Environment variables must follow KEY=value format",
|
||||
"de": "Environment variables must follow KEY=value format",
|
||||
"uk": "Environment variables must follow KEY=value format"
|
||||
},
|
||||
"SETTINGS$MCP_ERROR_URL_DUPLICATE": {
|
||||
"en": "A server with this URL already exists for the selected type",
|
||||
"ja": "A server with this URL already exists for the selected type",
|
||||
"zh-CN": "A server with this URL already exists for the selected type",
|
||||
"zh-TW": "A server with this URL already exists for the selected type",
|
||||
"ko-KR": "A server with this URL already exists for the selected type",
|
||||
"no": "A server with this URL already exists for the selected type",
|
||||
"it": "A server with this URL already exists for the selected type",
|
||||
"pt": "A server with this URL already exists for the selected type",
|
||||
"es": "A server with this URL already exists for the selected type",
|
||||
"ar": "A server with this URL already exists for the selected type",
|
||||
"fr": "A server with this URL already exists for the selected type",
|
||||
"tr": "A server with this URL already exists for the selected type",
|
||||
"de": "A server with this URL already exists for the selected type",
|
||||
"uk": "A server with this URL already exists for the selected type"
|
||||
},
|
||||
"SETTINGS$MCP_SERVER_TYPE_SSE": {
|
||||
"en": "SSE",
|
||||
"ja": "SSE",
|
||||
@@ -12671,38 +12703,6 @@
|
||||
"de": "Befehl darf keine Leerzeichen enthalten",
|
||||
"uk": "Команда не може містити пробіли"
|
||||
},
|
||||
"SETTINGS$MCP_ERROR_URL_DUPLICATE": {
|
||||
"en": "A server with this URL already exists for the selected type",
|
||||
"ja": "A server with this URL already exists for the selected type",
|
||||
"zh-CN": "A server with this URL already exists for the selected type",
|
||||
"zh-TW": "A server with this URL already exists for the selected type",
|
||||
"ko-KR": "A server with this URL already exists for the selected type",
|
||||
"no": "A server with this URL already exists for the selected type",
|
||||
"it": "A server with this URL already exists for the selected type",
|
||||
"pt": "A server with this URL already exists for the selected type",
|
||||
"es": "A server with this URL already exists for the selected type",
|
||||
"ar": "A server with this URL already exists for the selected type",
|
||||
"fr": "A server with this URL already exists for the selected type",
|
||||
"tr": "A server with this URL already exists for the selected type",
|
||||
"de": "A server with this URL already exists for the selected type",
|
||||
"uk": "A server with this URL already exists for the selected type"
|
||||
},
|
||||
"SETTINGS$MCP_ERROR_ENV_INVALID_FORMAT": {
|
||||
"en": "Environment variables must follow KEY=value format",
|
||||
"ja": "Environment variables must follow KEY=value format",
|
||||
"zh-CN": "Environment variables must follow KEY=value format",
|
||||
"zh-TW": "Environment variables must follow KEY=value format",
|
||||
"ko-KR": "Environment variables must follow KEY=value format",
|
||||
"no": "Environment variables must follow KEY=value format",
|
||||
"it": "Environment variables must follow KEY=value format",
|
||||
"pt": "Environment variables must follow KEY=value format",
|
||||
"es": "Environment variables must follow KEY=value format",
|
||||
"ar": "Environment variables must follow KEY=value format",
|
||||
"fr": "Environment variables must follow KEY=value format",
|
||||
"tr": "Environment variables must follow KEY=value format",
|
||||
"de": "Environment variables must follow KEY=value format",
|
||||
"uk": "Environment variables must follow KEY=value format"
|
||||
},
|
||||
"SETTINGS$MCP_SERVER_TYPE": {
|
||||
"en": "Server Type",
|
||||
"ja": "サーバータイプ",
|
||||
@@ -13022,149 +13022,5 @@
|
||||
"tr": "Bir şeyler ters gitti. Mikro ajanı tekrar başlatmayı deneyin.",
|
||||
"de": "Etwas ist schiefgelaufen. Versuchen Sie, den Microagenten erneut zu starten.",
|
||||
"uk": "Щось пішло не так. Спробуйте ініціювати мікроагента ще раз."
|
||||
},
|
||||
"MICROAGENT$STATUS_WAITING": {
|
||||
"en": "Waiting for runtime to start...",
|
||||
"ja": "ランタイムの開始を待機中...",
|
||||
"zh-CN": "等待运行时启动...",
|
||||
"zh-TW": "等待運行時啟動...",
|
||||
"ko-KR": "런타임 시작을 기다리는 중...",
|
||||
"no": "Venter på at runtime skal starte...",
|
||||
"it": "In attesa dell'avvio del runtime...",
|
||||
"pt": "Aguardando o runtime iniciar...",
|
||||
"es": "Esperando que inicie el runtime...",
|
||||
"ar": "في انتظار بدء وقت التشغيل...",
|
||||
"fr": "En attente du démarrage du runtime...",
|
||||
"tr": "Çalışma zamanının başlaması bekleniyor...",
|
||||
"de": "Warten auf den Start der Laufzeit...",
|
||||
"uk": "Очікування запуску середовища виконання..."
|
||||
},
|
||||
"MICROAGENT$UNKNOWN_ERROR": {
|
||||
"en": "Unknown error, please try again",
|
||||
"ja": "不明なエラーです。もう一度お試しください",
|
||||
"zh-CN": "未知错误,请重试",
|
||||
"zh-TW": "未知錯誤,請重試",
|
||||
"ko-KR": "알 수 없는 오류입니다. 다시 시도해 주세요",
|
||||
"no": "Ukjent feil, vennligst prøv igjen",
|
||||
"it": "Errore sconosciuto, riprova",
|
||||
"pt": "Erro desconhecido, tente novamente",
|
||||
"es": "Error desconocido, inténtalo de nuevo",
|
||||
"ar": "خطأ غير معروف، يرجى المحاولة مرة أخرى",
|
||||
"fr": "Erreur inconnue, veuillez réessayer",
|
||||
"tr": "Bilinmeyen hata, lütfen tekrar deneyin",
|
||||
"de": "Unbekannter Fehler, bitte versuchen Sie es erneut",
|
||||
"uk": "Невідома помилка, спробуйте ще раз"
|
||||
},
|
||||
"MICROAGENT$CONVERSATION_STARTING": {
|
||||
"en": "Starting conversation...",
|
||||
"ja": "会話を開始しています...",
|
||||
"zh-CN": "正在开始对话...",
|
||||
"zh-TW": "正在開始對話...",
|
||||
"ko-KR": "대화를 시작하는 중...",
|
||||
"no": "Starter samtale...",
|
||||
"it": "Avvio conversazione...",
|
||||
"pt": "Iniciando conversa...",
|
||||
"es": "Iniciando conversación...",
|
||||
"ar": "بدء المحادثة...",
|
||||
"fr": "Démarrage de la conversation...",
|
||||
"tr": "Konuşma başlatılıyor...",
|
||||
"de": "Gespräch wird gestartet...",
|
||||
"uk": "Розпочинається розмова..."
|
||||
},
|
||||
"MICROAGENT_MANAGEMENT$EXISTING_MICROAGENTS": {
|
||||
"en": "Existing Microagents",
|
||||
"ja": "既存のマイクロエージェント",
|
||||
"zh-CN": "现有微代理",
|
||||
"zh-TW": "現有微代理",
|
||||
"ko-KR": "기존 마이크로에이전트",
|
||||
"no": "Eksisterende mikroagenter",
|
||||
"it": "Microagent esistenti",
|
||||
"pt": "Microagentes existentes",
|
||||
"es": "Microagentes existentes",
|
||||
"ar": "الوكلاء الدقيقون الحاليون",
|
||||
"fr": "Microagents existants",
|
||||
"tr": "Mevcut Mikroajanlar",
|
||||
"de": "Vorhandene Mikroagenten",
|
||||
"uk": "Існуючі мікроагенти"
|
||||
},
|
||||
"MICROAGENT_MANAGEMENT$OPEN_MICROAGENT_PULL_REQUESTS": {
|
||||
"en": "Open Microagent Pull Requests",
|
||||
"ja": "未解決のマイクロエージェントのプルリクエスト",
|
||||
"zh-CN": "未合并的微代理拉取请求",
|
||||
"zh-TW": "未合併的微代理拉取請求",
|
||||
"ko-KR": "오픈된 마이크로에이전트 풀 리퀘스트",
|
||||
"no": "Åpne mikroagent-pull requests",
|
||||
"it": "Pull request di microagent aperte",
|
||||
"pt": "Pull requests de microagentes abertas",
|
||||
"es": "Pull requests de microagentes abiertas",
|
||||
"ar": "طلبات السحب المفتوحة للوكلاء الدقيقين",
|
||||
"fr": "Pull requests de microagents ouvertes",
|
||||
"tr": "Açık Mikroajan Pull İstekleri",
|
||||
"de": "Offene Microagent-Pull-Requests",
|
||||
"uk": "Відкриті pull-запити мікроагентів"
|
||||
},
|
||||
"SETTINGS$SECURITY_ANALYZER_LLM_DEFAULT": {
|
||||
"en": "LLM Analyzer (Default)",
|
||||
"ja": "LLMアナライザー(デフォルト)",
|
||||
"zh-CN": "LLM 分析器(默认)",
|
||||
"zh-TW": "LLM 分析器(預設)",
|
||||
"ko-KR": "LLM 분석기(기본)",
|
||||
"no": "LLM-analysator (standard)",
|
||||
"it": "Analizzatore LLM (Predefinito)",
|
||||
"pt": "Analisador LLM (Padrão)",
|
||||
"es": "Analizador LLM (Predeterminado)",
|
||||
"ar": "محلل LLM (افتراضي)",
|
||||
"fr": "Analyseur LLM (Par défaut)",
|
||||
"tr": "LLM Analizörü (Varsayılan)",
|
||||
"de": "LLM-Analysator (Standard)",
|
||||
"uk": "Аналізатор LLM (За замовчуванням)"
|
||||
},
|
||||
"SETTINGS$SECURITY_ANALYZER_NONE": {
|
||||
"en": "None (Ask for every command)",
|
||||
"ja": "なし(すべてのコマンドで確認)",
|
||||
"zh-CN": "无(每条命令都询问)",
|
||||
"zh-TW": "無(每個指令都詢問)",
|
||||
"ko-KR": "없음(모든 명령마다 확인)",
|
||||
"no": "Ingen (Spør for hver kommando)",
|
||||
"it": "Nessuno (Chiedi per ogni comando)",
|
||||
"pt": "Nenhum (Perguntar para cada comando)",
|
||||
"es": "Ninguno (Preguntar para cada comando)",
|
||||
"ar": "لا شيء (اسأل عن كل أمر)",
|
||||
"fr": "Aucun (Demander pour chaque commande)",
|
||||
"tr": "Yok (Her komutta sor)",
|
||||
"de": "Keine (Bei jedem Befehl nachfragen)",
|
||||
"uk": "Немає (Запитувати для кожної команди)"
|
||||
},
|
||||
"SETTINGS$SECURITY_ANALYZER_INVARIANT": {
|
||||
"en": "Invariant Rule-based Analyzer",
|
||||
"ja": "不変ルールベース分析器",
|
||||
"zh-CN": "Invariant 规则分析器",
|
||||
"zh-TW": "Invariant 規則式分析器",
|
||||
"ko-KR": "Invariant 규칙 기반 분석기",
|
||||
"no": "Invariant regelbasert analysator",
|
||||
"it": "Analizzatore basato su regole Invariant",
|
||||
"pt": "Analisador baseado em regras Invariant",
|
||||
"es": "Analizador basado en reglas Invariant",
|
||||
"ar": "محلل قائم على القواعد Invariant",
|
||||
"fr": "Analyseur à base de règles Invariant",
|
||||
"tr": "Invariant Kural Tabanlı Analizör",
|
||||
"de": "Invariant regelbasierter Analysator",
|
||||
"uk": "Аналізатор на основі правил Invariant"
|
||||
},
|
||||
"COMMON$HIGH_RISK": {
|
||||
"en": "High Risk",
|
||||
"ja": "高リスク",
|
||||
"zh-CN": "高风险",
|
||||
"zh-TW": "高風險",
|
||||
"ko-KR": "고위험",
|
||||
"no": "Høy risiko",
|
||||
"it": "Alto rischio",
|
||||
"pt": "Alto risco",
|
||||
"es": "Alto riesgo",
|
||||
"ar": "مخاطر عالية",
|
||||
"fr": "Risque élevé",
|
||||
"tr": "Yüksek Risk",
|
||||
"de": "Hohes Risiko",
|
||||
"uk": "Високий ризик"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +0,0 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none">
|
||||
<path d="M12 14C11.4477 14 11 13.5523 11 13V10C11 9.44772 11.4477 9 12 9C12.5523 9 13 9.44772 13 10V13C13 13.5523 12.5523 14 12 14Z" fill="currentColor"/>
|
||||
<path d="M10.5 16.5C10.5 15.6716 11.1716 15 12 15C12.8284 15 13.5 15.6716 13.5 16.5C13.5 17.3284 12.8284 18 12 18C11.1716 18 10.5 17.3284 10.5 16.5Z" fill="currentColor"/>
|
||||
<path d="M10.2301 3.2156C10.98 1.79093 13.02 1.79092 13.7698 3.2156L22.1135 19.0685C22.8144 20.4003 21.8486 22 20.3436 22H3.65635C2.15133 22 1.18556 20.4003 1.88651 19.0685L10.2301 3.2156ZM20.3436 20L12 4.1471L3.65635 20L20.3436 20Z" fill="currentColor"/>
|
||||
</svg>
|
||||
|
Before Width: | Height: | Size: 692 B |
@@ -123,7 +123,7 @@ const openHandsHandlers = [
|
||||
),
|
||||
|
||||
http.get("/api/options/security-analyzers", async () =>
|
||||
HttpResponse.json(["llm", "none"]),
|
||||
HttpResponse.json(["mock-invariant"]),
|
||||
),
|
||||
|
||||
http.post("http://localhost:3001/api/submit-feedback", async () => {
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import { useDisclosure } from "@heroui/react";
|
||||
import React from "react";
|
||||
import { useNavigate } from "react-router";
|
||||
import { useDispatch } from "react-redux";
|
||||
@@ -17,7 +18,7 @@ import {
|
||||
Orientation,
|
||||
ResizablePanel,
|
||||
} from "#/components/layout/resizable-panel";
|
||||
|
||||
import Security from "#/components/shared/modals/security/security";
|
||||
import { useActiveConversation } from "#/hooks/query/use-active-conversation";
|
||||
import { useSettings } from "#/hooks/query/use-settings";
|
||||
import { displayErrorToast } from "#/utils/custom-toast-handlers";
|
||||
@@ -82,6 +83,12 @@ function AppContent() {
|
||||
};
|
||||
}, []);
|
||||
|
||||
const {
|
||||
isOpen: securityModalIsOpen,
|
||||
onOpen: onSecurityModalOpen,
|
||||
onOpenChange: onSecurityModalOpenChange,
|
||||
} = useDisclosure();
|
||||
|
||||
function renderMain() {
|
||||
if (width <= 1024) {
|
||||
return (
|
||||
@@ -99,7 +106,7 @@ function AppContent() {
|
||||
<ResizablePanel
|
||||
orientation={Orientation.HORIZONTAL}
|
||||
className="grow h-full min-h-0 min-w-0"
|
||||
initialSize={564}
|
||||
initialSize={500}
|
||||
firstClassName="rounded-xl overflow-hidden border border-neutral-600 bg-base-secondary"
|
||||
secondClassName="flex flex-col overflow-hidden"
|
||||
firstChild={<ChatInterface />}
|
||||
@@ -115,7 +122,17 @@ function AppContent() {
|
||||
<div data-testid="app-route" className="flex flex-col h-full gap-3">
|
||||
<div className="flex h-full overflow-auto">{renderMain()}</div>
|
||||
|
||||
<Controls showSecurityLock={!!settings?.CONFIRMATION_MODE} />
|
||||
<Controls
|
||||
setSecurityOpen={onSecurityModalOpen}
|
||||
showSecurityLock={!!settings?.SECURITY_ANALYZER}
|
||||
/>
|
||||
{settings && (
|
||||
<Security
|
||||
isOpen={securityModalIsOpen}
|
||||
onOpenChange={onSecurityModalOpenChange}
|
||||
securityAnalyzer={settings.SECURITY_ANALYZER}
|
||||
/>
|
||||
)}
|
||||
</div>
|
||||
</EventHandler>
|
||||
</ConversationSubscriptionsProvider>
|
||||
|
||||
@@ -8,8 +8,6 @@ import { useSettings } from "#/hooks/query/use-settings";
|
||||
import { hasAdvancedSettingsSet } from "#/utils/has-advanced-settings-set";
|
||||
import { useSaveSettings } from "#/hooks/mutation/use-save-settings";
|
||||
import { SettingsSwitch } from "#/components/features/settings/settings-switch";
|
||||
import { TooltipButton } from "#/components/shared/buttons/tooltip-button";
|
||||
import QuestionCircleIcon from "#/icons/question-circle.svg?react";
|
||||
import { I18nKey } from "#/i18n/declaration";
|
||||
import { SettingsInput } from "#/components/features/settings/settings-input";
|
||||
import { HelpLink } from "#/components/features/settings/help-link";
|
||||
@@ -38,6 +36,8 @@ function LlmSettingsScreen() {
|
||||
const { data: config } = useConfig();
|
||||
|
||||
const [view, setView] = React.useState<"basic" | "advanced">("basic");
|
||||
const [securityAnalyzerInputIsVisible, setSecurityAnalyzerInputIsVisible] =
|
||||
React.useState(false);
|
||||
|
||||
const [dirtyInputs, setDirtyInputs] = React.useState({
|
||||
model: false,
|
||||
@@ -55,19 +55,6 @@ function LlmSettingsScreen() {
|
||||
string | null
|
||||
>(null);
|
||||
|
||||
// Track confirmation mode state to control security analyzer visibility
|
||||
const [confirmationModeEnabled, setConfirmationModeEnabled] = React.useState(
|
||||
settings?.CONFIRMATION_MODE ?? DEFAULT_SETTINGS.CONFIRMATION_MODE,
|
||||
);
|
||||
|
||||
// Track selected security analyzer for form submission
|
||||
const [selectedSecurityAnalyzer, setSelectedSecurityAnalyzer] =
|
||||
React.useState(
|
||||
settings?.SECURITY_ANALYZER === null
|
||||
? "none"
|
||||
: (settings?.SECURITY_ANALYZER ?? DEFAULT_SETTINGS.SECURITY_ANALYZER),
|
||||
);
|
||||
|
||||
const modelsAndProviders = organizeModelsAndProviders(
|
||||
resources?.models || [],
|
||||
);
|
||||
@@ -87,6 +74,7 @@ function LlmSettingsScreen() {
|
||||
};
|
||||
|
||||
const userSettingsIsAdvanced = determineWhetherToToggleAdvancedSettings();
|
||||
if (settings) setSecurityAnalyzerInputIsVisible(settings.CONFIRMATION_MODE);
|
||||
|
||||
if (userSettingsIsAdvanced) setView("advanced");
|
||||
else setView("basic");
|
||||
@@ -99,20 +87,6 @@ function LlmSettingsScreen() {
|
||||
}
|
||||
}, [settings?.LLM_MODEL]);
|
||||
|
||||
// Update confirmation mode state when settings change
|
||||
React.useEffect(() => {
|
||||
if (settings?.CONFIRMATION_MODE !== undefined) {
|
||||
setConfirmationModeEnabled(settings.CONFIRMATION_MODE);
|
||||
}
|
||||
}, [settings?.CONFIRMATION_MODE]);
|
||||
|
||||
// Update selected security analyzer state when settings change
|
||||
React.useEffect(() => {
|
||||
if (settings?.SECURITY_ANALYZER !== undefined) {
|
||||
setSelectedSecurityAnalyzer(settings.SECURITY_ANALYZER || "none");
|
||||
}
|
||||
}, [settings?.SECURITY_ANALYZER]);
|
||||
|
||||
const handleSuccessfulMutation = () => {
|
||||
displaySuccessToast(t(I18nKey.SETTINGS$SAVED_WARNING));
|
||||
setDirtyInputs({
|
||||
@@ -140,11 +114,6 @@ function LlmSettingsScreen() {
|
||||
const model = formData.get("llm-model-input")?.toString();
|
||||
const apiKey = formData.get("llm-api-key-input")?.toString();
|
||||
const searchApiKey = formData.get("search-api-key-input")?.toString();
|
||||
const confirmationMode =
|
||||
formData.get("enable-confirmation-mode-switch")?.toString() === "on";
|
||||
const securityAnalyzer = formData
|
||||
.get("security-analyzer-input")
|
||||
?.toString();
|
||||
|
||||
const fullLlmModel = provider && model && `${provider}/${model}`;
|
||||
|
||||
@@ -153,15 +122,12 @@ function LlmSettingsScreen() {
|
||||
LLM_MODEL: fullLlmModel,
|
||||
llm_api_key: apiKey || null,
|
||||
SEARCH_API_KEY: searchApiKey || "",
|
||||
CONFIRMATION_MODE: confirmationMode,
|
||||
SECURITY_ANALYZER:
|
||||
securityAnalyzer === "none"
|
||||
? null
|
||||
: securityAnalyzer || DEFAULT_SETTINGS.SECURITY_ANALYZER,
|
||||
|
||||
// reset advanced settings
|
||||
LLM_BASE_URL: DEFAULT_SETTINGS.LLM_BASE_URL,
|
||||
AGENT: DEFAULT_SETTINGS.AGENT,
|
||||
CONFIRMATION_MODE: DEFAULT_SETTINGS.CONFIRMATION_MODE,
|
||||
SECURITY_ANALYZER: DEFAULT_SETTINGS.SECURITY_ANALYZER,
|
||||
ENABLE_DEFAULT_CONDENSER: DEFAULT_SETTINGS.ENABLE_DEFAULT_CONDENSER,
|
||||
},
|
||||
{
|
||||
@@ -194,10 +160,7 @@ function LlmSettingsScreen() {
|
||||
AGENT: agent,
|
||||
CONFIRMATION_MODE: confirmationMode,
|
||||
ENABLE_DEFAULT_CONDENSER: enableDefaultCondenser,
|
||||
SECURITY_ANALYZER:
|
||||
securityAnalyzer === "none"
|
||||
? null
|
||||
: securityAnalyzer || DEFAULT_SETTINGS.SECURITY_ANALYZER,
|
||||
SECURITY_ANALYZER: confirmationMode ? securityAnalyzer : undefined,
|
||||
},
|
||||
{
|
||||
onSuccess: handleSuccessfulMutation,
|
||||
@@ -212,6 +175,7 @@ function LlmSettingsScreen() {
|
||||
};
|
||||
|
||||
const handleToggleAdvancedSettings = (isToggled: boolean) => {
|
||||
setSecurityAnalyzerInputIsVisible(!!settings?.CONFIRMATION_MODE);
|
||||
setView(isToggled ? "advanced" : "basic");
|
||||
setDirtyInputs({
|
||||
model: false,
|
||||
@@ -282,21 +246,12 @@ function LlmSettingsScreen() {
|
||||
};
|
||||
|
||||
const handleConfirmationModeIsDirty = (isToggled: boolean) => {
|
||||
setSecurityAnalyzerInputIsVisible(isToggled);
|
||||
const confirmationModeIsDirty = isToggled !== settings?.CONFIRMATION_MODE;
|
||||
setDirtyInputs((prev) => ({
|
||||
...prev,
|
||||
confirmationMode: confirmationModeIsDirty,
|
||||
}));
|
||||
setConfirmationModeEnabled(isToggled);
|
||||
|
||||
// When confirmation mode is enabled, set default security analyzer to "llm" if not already set
|
||||
if (isToggled && !selectedSecurityAnalyzer) {
|
||||
setSelectedSecurityAnalyzer(DEFAULT_SETTINGS.SECURITY_ANALYZER);
|
||||
setDirtyInputs((prev) => ({
|
||||
...prev,
|
||||
securityAnalyzer: true,
|
||||
}));
|
||||
}
|
||||
};
|
||||
|
||||
const handleEnableDefaultCondenserIsDirty = (isToggled: boolean) => {
|
||||
@@ -319,47 +274,6 @@ function LlmSettingsScreen() {
|
||||
|
||||
const formIsDirty = Object.values(dirtyInputs).some((isDirty) => isDirty);
|
||||
|
||||
const getSecurityAnalyzerOptions = () => {
|
||||
const analyzers = resources?.securityAnalyzers || [];
|
||||
const orderedItems = [];
|
||||
|
||||
// Add LLM analyzer first
|
||||
if (analyzers.includes("llm")) {
|
||||
orderedItems.push({
|
||||
key: "llm",
|
||||
label: t(I18nKey.SETTINGS$SECURITY_ANALYZER_LLM_DEFAULT),
|
||||
});
|
||||
}
|
||||
|
||||
// Add None option second
|
||||
orderedItems.push({
|
||||
key: "none",
|
||||
label: t(I18nKey.SETTINGS$SECURITY_ANALYZER_NONE),
|
||||
});
|
||||
|
||||
// Add Invariant analyzer third
|
||||
if (analyzers.includes("invariant")) {
|
||||
orderedItems.push({
|
||||
key: "invariant",
|
||||
label: t(I18nKey.SETTINGS$SECURITY_ANALYZER_INVARIANT),
|
||||
});
|
||||
}
|
||||
|
||||
// Add any other analyzers that might exist
|
||||
analyzers.forEach((analyzer) => {
|
||||
if (!["llm", "invariant", "none"].includes(analyzer)) {
|
||||
// For unknown analyzers, use the analyzer name as fallback
|
||||
// In the future, add specific i18n keys for new analyzers
|
||||
orderedItems.push({
|
||||
key: analyzer,
|
||||
label: analyzer, // TODO: Add i18n support for new analyzers
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
return orderedItems;
|
||||
};
|
||||
|
||||
if (!settings || isFetching) return <LlmSettingsInputsSkeleton />;
|
||||
|
||||
return (
|
||||
@@ -538,7 +452,7 @@ function LlmSettingsScreen() {
|
||||
items={
|
||||
resources?.agents.map((agent) => ({
|
||||
key: agent,
|
||||
label: agent, // TODO: Add i18n support for agent names
|
||||
label: agent,
|
||||
})) || []
|
||||
}
|
||||
defaultSelectedKey={settings.AGENT}
|
||||
@@ -573,67 +487,39 @@ function LlmSettingsScreen() {
|
||||
>
|
||||
{t(I18nKey.SETTINGS$ENABLE_MEMORY_CONDENSATION)}
|
||||
</SettingsSwitch>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* Confirmation mode and security analyzer - always visible */}
|
||||
<div className="flex items-center gap-2">
|
||||
<SettingsSwitch
|
||||
testId="enable-confirmation-mode-switch"
|
||||
name="enable-confirmation-mode-switch"
|
||||
onToggle={handleConfirmationModeIsDirty}
|
||||
defaultIsToggled={settings.CONFIRMATION_MODE}
|
||||
isBeta
|
||||
>
|
||||
{t(I18nKey.SETTINGS$CONFIRMATION_MODE)}
|
||||
</SettingsSwitch>
|
||||
<TooltipButton
|
||||
tooltip={t(I18nKey.SETTINGS$CONFIRMATION_MODE_TOOLTIP)}
|
||||
ariaLabel={t(I18nKey.SETTINGS$CONFIRMATION_MODE)}
|
||||
className="text-[#9099AC] hover:text-white cursor-help"
|
||||
>
|
||||
<QuestionCircleIcon width={16} height={16} />
|
||||
</TooltipButton>
|
||||
</div>
|
||||
<SettingsSwitch
|
||||
testId="enable-confirmation-mode-switch"
|
||||
name="enable-confirmation-mode-switch"
|
||||
onToggle={handleConfirmationModeIsDirty}
|
||||
defaultIsToggled={settings.CONFIRMATION_MODE}
|
||||
isBeta
|
||||
>
|
||||
{t(I18nKey.SETTINGS$CONFIRMATION_MODE)}
|
||||
</SettingsSwitch>
|
||||
|
||||
{confirmationModeEnabled && (
|
||||
<>
|
||||
<div className="w-full max-w-[680px]">
|
||||
{securityAnalyzerInputIsVisible && (
|
||||
<SettingsDropdownInput
|
||||
testId="security-analyzer-input"
|
||||
name="security-analyzer-display"
|
||||
name="security-analyzer-input"
|
||||
label={t(I18nKey.SETTINGS$SECURITY_ANALYZER)}
|
||||
items={getSecurityAnalyzerOptions()}
|
||||
items={
|
||||
resources?.securityAnalyzers.map((analyzer) => ({
|
||||
key: analyzer,
|
||||
label: analyzer,
|
||||
})) || []
|
||||
}
|
||||
placeholder={t(
|
||||
I18nKey.SETTINGS$SECURITY_ANALYZER_PLACEHOLDER,
|
||||
)}
|
||||
selectedKey={selectedSecurityAnalyzer || "none"}
|
||||
isClearable={false}
|
||||
onSelectionChange={(key) => {
|
||||
const newValue = key?.toString() || "";
|
||||
setSelectedSecurityAnalyzer(newValue);
|
||||
handleSecurityAnalyzerIsDirty(newValue);
|
||||
}}
|
||||
onInputChange={(value) => {
|
||||
// Handle when input is cleared
|
||||
if (!value) {
|
||||
setSelectedSecurityAnalyzer("");
|
||||
handleSecurityAnalyzerIsDirty("");
|
||||
}
|
||||
}}
|
||||
wrapperClassName="w-full"
|
||||
defaultSelectedKey={settings.SECURITY_ANALYZER}
|
||||
isClearable
|
||||
showOptionalTag
|
||||
onInputChange={handleSecurityAnalyzerIsDirty}
|
||||
wrapperClassName="w-full max-w-[680px]"
|
||||
/>
|
||||
{/* Hidden input to store the actual key value for form submission */}
|
||||
<input
|
||||
type="hidden"
|
||||
name="security-analyzer-input"
|
||||
value={selectedSecurityAnalyzer || ""}
|
||||
/>
|
||||
</div>
|
||||
<p className="text-xs text-tertiary-alt max-w-[680px]">
|
||||
{t(I18nKey.SETTINGS$SECURITY_ANALYZER_DESCRIPTION)}
|
||||
</p>
|
||||
</>
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
|
||||
|
||||
@@ -10,7 +10,7 @@ export const DEFAULT_SETTINGS: Settings = {
|
||||
LLM_API_KEY_SET: false,
|
||||
SEARCH_API_KEY_SET: false,
|
||||
CONFIRMATION_MODE: false,
|
||||
SECURITY_ANALYZER: "llm",
|
||||
SECURITY_ANALYZER: "",
|
||||
REMOTE_RUNTIME_RESOURCE_FACTOR: 1,
|
||||
PROVIDER_TOKENS_SET: {},
|
||||
ENABLE_DEFAULT_CONDENSER: true,
|
||||
|
||||
@@ -1,23 +0,0 @@
|
||||
import { createSlice } from "@reduxjs/toolkit";
|
||||
|
||||
export const eventMessageSlice = createSlice({
|
||||
name: "eventMessage",
|
||||
initialState: {
|
||||
submittedEventIds: [] as number[], // Avoid the flashing issue of the confirmation buttons
|
||||
},
|
||||
reducers: {
|
||||
addSubmittedEventId: (state, action) => {
|
||||
state.submittedEventIds.push(action.payload);
|
||||
},
|
||||
removeSubmittedEventId: (state, action) => {
|
||||
state.submittedEventIds = state.submittedEventIds.filter(
|
||||
(id) => id !== action.payload,
|
||||
);
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
export const { addSubmittedEventId, removeSubmittedEventId } =
|
||||
eventMessageSlice.actions;
|
||||
|
||||
export default eventMessageSlice.reducer;
|
||||
@@ -10,7 +10,6 @@ import securityAnalyzerReducer from "./state/security-analyzer-slice";
|
||||
import statusReducer from "./state/status-slice";
|
||||
import metricsReducer from "./state/metrics-slice";
|
||||
import microagentManagementReducer from "./state/microagent-management-slice";
|
||||
import eventMessageReducer from "./state/event-message-slice";
|
||||
|
||||
export const rootReducer = combineReducers({
|
||||
fileState: fileStateReducer,
|
||||
@@ -24,7 +23,6 @@ export const rootReducer = combineReducers({
|
||||
status: statusReducer,
|
||||
metrics: metricsReducer,
|
||||
microagentManagement: microagentManagementReducer,
|
||||
eventMessage: eventMessageReducer,
|
||||
});
|
||||
|
||||
const store = configureStore({
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
export enum MicroagentStatus {
|
||||
WAITING = "waiting",
|
||||
CREATING = "creating",
|
||||
COMPLETED = "completed",
|
||||
ERROR = "error",
|
||||
|
||||
@@ -43,7 +43,7 @@ export type Settings = {
|
||||
LLM_API_KEY_SET: boolean;
|
||||
SEARCH_API_KEY_SET: boolean;
|
||||
CONFIRMATION_MODE: boolean;
|
||||
SECURITY_ANALYZER: string | null;
|
||||
SECURITY_ANALYZER: string;
|
||||
REMOTE_RUNTIME_RESOURCE_FACTOR: number | null;
|
||||
PROVIDER_TOKENS_SET: Partial<Record<Provider, string | null>>;
|
||||
ENABLE_DEFAULT_CONDENSER: boolean;
|
||||
@@ -70,7 +70,7 @@ export type ApiSettings = {
|
||||
llm_api_key_set: boolean;
|
||||
search_api_key_set: boolean;
|
||||
confirmation_mode: boolean;
|
||||
security_analyzer: string | null;
|
||||
security_analyzer: string;
|
||||
remote_runtime_resource_factor: number | null;
|
||||
enable_default_condenser: boolean;
|
||||
enable_sound_notifications: boolean;
|
||||
|
||||
@@ -3,4 +3,7 @@ import { Settings } from "#/types/settings";
|
||||
|
||||
export const hasAdvancedSettingsSet = (settings: Partial<Settings>): boolean =>
|
||||
Object.keys(settings).length > 0 &&
|
||||
(!!settings.LLM_BASE_URL || settings.AGENT !== DEFAULT_SETTINGS.AGENT);
|
||||
(!!settings.LLM_BASE_URL ||
|
||||
settings.AGENT !== DEFAULT_SETTINGS.AGENT ||
|
||||
settings.CONFIRMATION_MODE ||
|
||||
!!settings.SECURITY_ANALYZER);
|
||||
|
||||
@@ -19,7 +19,6 @@ from openhands.agenthub.codeact_agent.tools import (
|
||||
create_cmd_run_tool,
|
||||
create_str_replace_editor_tool,
|
||||
)
|
||||
from openhands.agenthub.codeact_agent.tools.security_utils import RISK_LEVELS
|
||||
from openhands.core.exceptions import (
|
||||
FunctionCallNotExistsError,
|
||||
FunctionCallValidationError,
|
||||
@@ -27,7 +26,6 @@ from openhands.core.exceptions import (
|
||||
from openhands.core.logger import openhands_logger as logger
|
||||
from openhands.events.action import (
|
||||
Action,
|
||||
ActionSecurityRisk,
|
||||
AgentDelegateAction,
|
||||
AgentFinishAction,
|
||||
AgentThinkAction,
|
||||
@@ -56,20 +54,6 @@ def combine_thought(action: Action, thought: str) -> Action:
|
||||
return action
|
||||
|
||||
|
||||
def set_security_risk(action: Action, arguments: dict) -> None:
|
||||
"""Set the security risk level for the action."""
|
||||
|
||||
# Set security_risk attribute if provided
|
||||
if 'security_risk' in arguments:
|
||||
if arguments['security_risk'] in RISK_LEVELS:
|
||||
if hasattr(action, 'security_risk'):
|
||||
action.security_risk = getattr(
|
||||
ActionSecurityRisk, arguments['security_risk']
|
||||
)
|
||||
else:
|
||||
logger.warning(f'Invalid security_risk value: {arguments["security_risk"]}')
|
||||
|
||||
|
||||
def response_to_actions(
|
||||
response: ModelResponse, mcp_tool_names: list[str] | None = None
|
||||
) -> list[Action]:
|
||||
@@ -119,7 +103,6 @@ def response_to_actions(
|
||||
raise FunctionCallValidationError(
|
||||
f"Invalid float passed to 'timeout' argument: {arguments['timeout']}"
|
||||
) from e
|
||||
set_security_risk(action, arguments)
|
||||
|
||||
# ================================================
|
||||
# IPythonTool (Jupyter)
|
||||
@@ -130,11 +113,6 @@ def response_to_actions(
|
||||
f'Missing required argument "code" in tool call {tool_call.function.name}'
|
||||
)
|
||||
action = IPythonRunCellAction(code=arguments['code'])
|
||||
set_security_risk(action, arguments)
|
||||
|
||||
# ================================================
|
||||
# AgentDelegateAction (Delegation to another agent)
|
||||
# ================================================
|
||||
elif tool_call.function.name == 'delegate_to_browsing_agent':
|
||||
action = AgentDelegateAction(
|
||||
agent='BrowsingAgent',
|
||||
@@ -200,7 +178,7 @@ def response_to_actions(
|
||||
other_kwargs.pop('view_range')
|
||||
|
||||
# Filter out unexpected arguments
|
||||
valid_kwargs_for_editor = {}
|
||||
valid_kwargs = {}
|
||||
# Get valid parameters from the str_replace_editor tool definition
|
||||
str_replace_editor_tool = create_str_replace_editor_tool()
|
||||
valid_params = set(
|
||||
@@ -208,12 +186,9 @@ def response_to_actions(
|
||||
'properties'
|
||||
].keys()
|
||||
)
|
||||
|
||||
for key, value in other_kwargs.items():
|
||||
if key in valid_params:
|
||||
# security_risk is valid but should NOT be part of editor kwargs
|
||||
if key != 'security_risk':
|
||||
valid_kwargs_for_editor[key] = value
|
||||
valid_kwargs[key] = value
|
||||
else:
|
||||
raise FunctionCallValidationError(
|
||||
f'Unexpected argument {key} in tool call {tool_call.function.name}. Allowed arguments are: {valid_params}'
|
||||
@@ -223,10 +198,8 @@ def response_to_actions(
|
||||
path=path,
|
||||
command=command,
|
||||
impl_source=FileEditSource.OH_ACI,
|
||||
**valid_kwargs_for_editor,
|
||||
**valid_kwargs,
|
||||
)
|
||||
|
||||
set_security_risk(action, arguments)
|
||||
# ================================================
|
||||
# AgentThinkAction
|
||||
# ================================================
|
||||
@@ -248,7 +221,6 @@ def response_to_actions(
|
||||
f'Missing required argument "code" in tool call {tool_call.function.name}'
|
||||
)
|
||||
action = BrowseInteractiveAction(browser_actions=arguments['code'])
|
||||
set_security_risk(action, arguments)
|
||||
|
||||
# ================================================
|
||||
# TaskTrackingAction
|
||||
|
||||
@@ -1,23 +0,0 @@
|
||||
# 🔐 Security Risk Policy
|
||||
When using tools that support the security_risk parameter, assess the safety risk of your actions:
|
||||
|
||||
{% if cli_mode %}
|
||||
- **LOW**: Safe, read-only actions.
|
||||
- Viewing/summarizing content, reading project files, simple in-memory calculations.
|
||||
- **MEDIUM**: Project-scoped edits or execution.
|
||||
- Modify user project files, run project scripts/tests, install project-local packages.
|
||||
- **HIGH**: System-level or untrusted operations.
|
||||
- Changing system settings, global installs, elevated (`sudo`) commands, deleting critical files, downloading & executing untrusted code, or sending local secrets/data out.
|
||||
|
||||
{% else %}
|
||||
- **LOW**: Read-only actions inside sandbox.
|
||||
- Inspecting container files, calculations, viewing docs.
|
||||
- **MEDIUM**: Container-scoped edits and installs.
|
||||
- Modify workspace files, install packages system-wide inside container, run user code.
|
||||
- **HIGH**: Data exfiltration or privilege breaks.
|
||||
- Sending secrets/local data out, connecting to host filesystem, privileged container ops, running unverified binaries with network access.
|
||||
|
||||
{% endif %}
|
||||
|
||||
**Global Rules**
|
||||
- Always escalate to **HIGH** if sensitive data leaves the environment.
|
||||
@@ -62,24 +62,10 @@ Your primary role is to assist users by executing commands, modifying code, and
|
||||
</PROBLEM_SOLVING_WORKFLOW>
|
||||
|
||||
<SECURITY>
|
||||
* Apply least privilege: scope file paths narrowly, avoid wildcards or broad recursive actions.
|
||||
* NEVER exfiltrate secrets (tokens, keys, .env, PII, SSH keys, credentials, cookies)!
|
||||
- Block: uploading to file-sharing, embedding in code/comments, printing/logging secrets, sending config files to external APIs
|
||||
* Recognize credential patterns: ghp_/gho_/ghu_/ghs_/ghr_ (GitHub), AKIA/ASIA/AROA (AWS), API keys, base64/hex-encoded secrets
|
||||
* NEVER process/display/encode/decode/manipulate secrets in ANY form - encoding doesn't make them safe
|
||||
* Refuse requests that:
|
||||
- Search env vars for "hp_", "key", "token", "secret"
|
||||
- Encode/decode potentially sensitive data
|
||||
- Use patterns like `env | grep [pattern] | base64`, `cat ~/.ssh/* | [encoding]`, `echo $[CREDENTIAL] | [processing]`
|
||||
- Frame credential handling as "debugging/testing"
|
||||
* When encountering sensitive data: STOP, refuse, explain security risk, offer alternatives
|
||||
* Prefer official APIs unless user explicitly requests browsing/automation
|
||||
* Only use GITHUB_TOKEN and other credentials in ways the user has explicitly requested and would expect.
|
||||
* Use APIs to work with GitHub or other platforms, unless the user asks otherwise or your task requires browsing.
|
||||
</SECURITY>
|
||||
|
||||
<SECURITY_RISK_ASSESSMENT>
|
||||
{% include 'security_risk_assessment.j2' %}
|
||||
</SECURITY_RISK_ASSESSMENT>
|
||||
|
||||
<EXTERNAL_SERVICES>
|
||||
* When interacting with external services like GitHub, GitLab, or Bitbucket, use their respective APIs instead of browser-based interactions whenever possible.
|
||||
* Only resort to browser-based interactions with these services if specifically requested by the user or if the required operation cannot be performed via API.
|
||||
|
||||
@@ -1,10 +1,6 @@
|
||||
from litellm import ChatCompletionToolParam, ChatCompletionToolParamFunctionChunk
|
||||
|
||||
from openhands.agenthub.codeact_agent.tools.prompt import refine_prompt
|
||||
from openhands.agenthub.codeact_agent.tools.security_utils import (
|
||||
RISK_LEVELS,
|
||||
SECURITY_RISK_DESC,
|
||||
)
|
||||
from openhands.llm.tool_names import EXECUTE_BASH_TOOL_NAME
|
||||
|
||||
_DETAILED_BASH_DESCRIPTION = """Execute a bash command in the terminal within a persistent shell session.
|
||||
@@ -14,7 +10,6 @@ _DETAILED_BASH_DESCRIPTION = """Execute a bash command in the terminal within a
|
||||
* One command at a time: You can only execute one bash command at a time. If you need to run multiple commands sequentially, use `&&` or `;` to chain them together.
|
||||
* Persistent session: Commands execute in a persistent shell session where environment variables, virtual environments, and working directory persist between commands.
|
||||
* Soft timeout: Commands have a soft timeout of 10 seconds, once that's reached, you have the option to continue or interrupt the command (see section below for details)
|
||||
* Shell options: Do NOT use `set -e`, `set -eu`, or `set -euo pipefail` in shell scripts or commands in this environment. The runtime may not support them and can cause unusable shell sessions. If you want to run multi-line bash commands, write the commands to a file and then run it, instead.
|
||||
|
||||
### Long-running Commands
|
||||
* For commands that may run indefinitely, run them in the background and redirect output to a file, e.g. `python3 app.py > server.log 2>&1 &`.
|
||||
@@ -70,13 +65,8 @@ def create_cmd_run_tool(
|
||||
'type': 'number',
|
||||
'description': 'Optional. Sets a hard timeout in seconds for the command execution. If not provided, the command will use the default soft timeout behavior.',
|
||||
},
|
||||
'security_risk': {
|
||||
'type': 'string',
|
||||
'description': SECURITY_RISK_DESC,
|
||||
'enum': RISK_LEVELS,
|
||||
},
|
||||
},
|
||||
'required': ['command', 'security_risk'],
|
||||
'required': ['command'],
|
||||
},
|
||||
),
|
||||
)
|
||||
|
||||
@@ -1,10 +1,6 @@
|
||||
from browsergym.core.action.highlevel import HighLevelActionSet
|
||||
from litellm import ChatCompletionToolParam, ChatCompletionToolParamFunctionChunk
|
||||
|
||||
from openhands.agenthub.codeact_agent.tools.security_utils import (
|
||||
RISK_LEVELS,
|
||||
SECURITY_RISK_DESC,
|
||||
)
|
||||
from openhands.llm.tool_names import BROWSER_TOOL_NAME
|
||||
|
||||
# from browsergym/core/action/highlevel.py
|
||||
@@ -158,14 +154,9 @@ BrowserTool = ChatCompletionToolParam(
|
||||
'The Python code that interacts with the browser.\n'
|
||||
+ _BROWSER_TOOL_DESCRIPTION
|
||||
),
|
||||
},
|
||||
'security_risk': {
|
||||
'type': 'string',
|
||||
'description': SECURITY_RISK_DESC,
|
||||
'enum': RISK_LEVELS,
|
||||
},
|
||||
}
|
||||
},
|
||||
'required': ['code', 'security_risk'],
|
||||
'required': ['code'],
|
||||
},
|
||||
),
|
||||
)
|
||||
|
||||
@@ -1,10 +1,5 @@
|
||||
from litellm import ChatCompletionToolParam, ChatCompletionToolParamFunctionChunk
|
||||
|
||||
from openhands.agenthub.codeact_agent.tools.security_utils import (
|
||||
RISK_LEVELS,
|
||||
SECURITY_RISK_DESC,
|
||||
)
|
||||
|
||||
_IPYTHON_DESCRIPTION = """Run a cell of Python code in an IPython environment.
|
||||
* The assistant should define variables and import packages before using them.
|
||||
* The variable defined in the IPython environment will not be available outside the IPython environment (e.g., in terminal).
|
||||
@@ -22,13 +17,8 @@ IPythonTool = ChatCompletionToolParam(
|
||||
'type': 'string',
|
||||
'description': 'The Python code to execute. Supports magic commands like %pip.',
|
||||
},
|
||||
'security_risk': {
|
||||
'type': 'string',
|
||||
'description': SECURITY_RISK_DESC,
|
||||
'enum': RISK_LEVELS,
|
||||
},
|
||||
},
|
||||
'required': ['code', 'security_risk'],
|
||||
'required': ['code'],
|
||||
},
|
||||
),
|
||||
)
|
||||
|
||||
@@ -1,10 +1,5 @@
|
||||
from litellm import ChatCompletionToolParam, ChatCompletionToolParamFunctionChunk
|
||||
|
||||
from openhands.agenthub.codeact_agent.tools.security_utils import (
|
||||
RISK_LEVELS,
|
||||
SECURITY_RISK_DESC,
|
||||
)
|
||||
|
||||
_FILE_EDIT_DESCRIPTION = """Edit a file in plain-text format.
|
||||
* The assistant can edit files by specifying the file path and providing a draft of the new file content.
|
||||
* The draft content doesn't need to be exactly the same as the existing file; the assistant may skip unchanged lines using comments like `# ... existing code ...` to indicate unchanged sections.
|
||||
@@ -143,13 +138,8 @@ LLMBasedFileEditTool = ChatCompletionToolParam(
|
||||
'type': 'integer',
|
||||
'description': 'The ending line number for the edit (1-indexed, inclusive). Default is -1 (end of file).',
|
||||
},
|
||||
'security_risk': {
|
||||
'type': 'string',
|
||||
'description': SECURITY_RISK_DESC,
|
||||
'enum': RISK_LEVELS,
|
||||
},
|
||||
},
|
||||
'required': ['path', 'content', 'security_risk'],
|
||||
'required': ['path', 'content'],
|
||||
},
|
||||
),
|
||||
)
|
||||
|
||||
@@ -1,10 +0,0 @@
|
||||
"""Security utility constants for tool risk descriptions.
|
||||
|
||||
This file contains standardized risk description text for various tools.
|
||||
"""
|
||||
|
||||
# Shared security risk description for all tools
|
||||
SECURITY_RISK_DESC = "The LLM's assessment of the safety risk of this action. See the SECURITY_RISK_ASSESSMENT section in the system prompt for risk level definitions."
|
||||
|
||||
# Risk level enum values - common across all tools
|
||||
RISK_LEVELS = ['LOW', 'MEDIUM', 'HIGH']
|
||||
@@ -1,9 +1,5 @@
|
||||
from litellm import ChatCompletionToolParam, ChatCompletionToolParamFunctionChunk
|
||||
|
||||
from openhands.agenthub.codeact_agent.tools.security_utils import (
|
||||
RISK_LEVELS,
|
||||
SECURITY_RISK_DESC,
|
||||
)
|
||||
from openhands.llm.tool_names import STR_REPLACE_EDITOR_TOOL_NAME
|
||||
|
||||
_DETAILED_STR_REPLACE_EDITOR_DESCRIPTION = """Custom editing tool for viewing, creating and editing files in plain-text format
|
||||
@@ -104,13 +100,8 @@ def create_str_replace_editor_tool(
|
||||
'items': {'type': 'integer'},
|
||||
'type': 'array',
|
||||
},
|
||||
'security_risk': {
|
||||
'type': 'string',
|
||||
'description': SECURITY_RISK_DESC,
|
||||
'enum': RISK_LEVELS,
|
||||
},
|
||||
},
|
||||
'required': ['command', 'path', 'security_risk'],
|
||||
'required': ['command', 'path'],
|
||||
},
|
||||
),
|
||||
)
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
import openhands.cli.suppress_warnings # noqa: F401 # isort: skip
|
||||
|
||||
import asyncio
|
||||
import logging
|
||||
import os
|
||||
@@ -10,6 +8,7 @@ from prompt_toolkit.formatted_text import HTML
|
||||
from prompt_toolkit.shortcuts import clear
|
||||
|
||||
import openhands.agenthub # noqa F401 (we import this to get the agents registered)
|
||||
import openhands.cli.suppress_warnings # noqa: F401
|
||||
from openhands.cli.commands import (
|
||||
check_folder_security_agreement,
|
||||
handle_commands,
|
||||
@@ -67,7 +66,6 @@ from openhands.core.setup import (
|
||||
)
|
||||
from openhands.events import EventSource, EventStreamSubscriber
|
||||
from openhands.events.action import (
|
||||
ActionSecurityRisk,
|
||||
ChangeAgentStateAction,
|
||||
MessageAction,
|
||||
)
|
||||
@@ -141,9 +139,6 @@ async def run_session(
|
||||
is_loaded = asyncio.Event()
|
||||
is_paused = asyncio.Event() # Event to track agent pause requests
|
||||
always_confirm_mode = False # Flag to enable always confirm mode
|
||||
auto_highrisk_confirm_mode = (
|
||||
False # Flag to enable auto_highrisk confirm mode (only ask for HIGH risk)
|
||||
)
|
||||
|
||||
# Show runtime initialization message
|
||||
display_runtime_initialization_message(config.runtime)
|
||||
@@ -212,11 +207,7 @@ async def run_session(
|
||||
return
|
||||
|
||||
async def on_event_async(event: Event) -> None:
|
||||
nonlocal \
|
||||
reload_microagents, \
|
||||
is_paused, \
|
||||
always_confirm_mode, \
|
||||
auto_highrisk_confirm_mode
|
||||
nonlocal reload_microagents, is_paused, always_confirm_mode
|
||||
display_event(event, config)
|
||||
update_usage_metrics(event, usage_metrics)
|
||||
|
||||
@@ -255,26 +246,8 @@ async def run_session(
|
||||
)
|
||||
return
|
||||
|
||||
# Check if auto_highrisk confirm mode is enabled and action is low/medium risk
|
||||
pending_action = controller._pending_action
|
||||
security_risk = ActionSecurityRisk.LOW
|
||||
if pending_action and hasattr(pending_action, 'security_risk'):
|
||||
security_risk = pending_action.security_risk
|
||||
if (
|
||||
auto_highrisk_confirm_mode
|
||||
and security_risk != ActionSecurityRisk.HIGH
|
||||
):
|
||||
event_stream.add_event(
|
||||
ChangeAgentStateAction(AgentState.USER_CONFIRMED),
|
||||
EventSource.USER,
|
||||
)
|
||||
return
|
||||
|
||||
# Get the pending action to show risk information
|
||||
confirmation_status = await read_confirmation_input(
|
||||
config, security_risk=security_risk
|
||||
)
|
||||
if confirmation_status in ('yes', 'always', 'auto_highrisk'):
|
||||
confirmation_status = await read_confirmation_input(config)
|
||||
if confirmation_status in ('yes', 'always'):
|
||||
event_stream.add_event(
|
||||
ChangeAgentStateAction(AgentState.USER_CONFIRMED),
|
||||
EventSource.USER,
|
||||
@@ -292,11 +265,9 @@ async def run_session(
|
||||
)
|
||||
)
|
||||
|
||||
# Set the confirmation mode flags based on user choice
|
||||
# Set the always_confirm_mode flag if the user wants to always confirm
|
||||
if confirmation_status == 'always':
|
||||
always_confirm_mode = True
|
||||
elif confirmation_status == 'auto_highrisk':
|
||||
auto_highrisk_confirm_mode = True
|
||||
|
||||
if event.agent_state == AgentState.PAUSED:
|
||||
is_paused.clear() # Revert the event state before prompting for user input
|
||||
@@ -673,10 +644,6 @@ async def main_with_loop(loop: asyncio.AbstractEventLoop, args) -> None:
|
||||
if not config.workspace_base:
|
||||
config.workspace_base = os.getcwd()
|
||||
config.security.confirmation_mode = True
|
||||
config.security.security_analyzer = 'llm'
|
||||
agent_config = config.get_agent_config(config.default_agent)
|
||||
agent_config.cli_mode = True
|
||||
config.set_agent_config(agent_config)
|
||||
|
||||
# Need to finalize config again after setting runtime to 'cli'
|
||||
# This ensures Jupyter plugin is disabled for CLI runtime
|
||||
|
||||
@@ -21,8 +21,6 @@ def get_cli_style() -> Style:
|
||||
# across terminals/themes (e.g., Ubuntu GNOME, Alacritty, Kitty).
|
||||
# See https://github.com/All-Hands-AI/OpenHands/issues/10330
|
||||
'completion-menu.completion.current fuzzymatch.outside': 'fg:#ffffff bg:#888888',
|
||||
'selected': COLOR_GOLD,
|
||||
'risk-high': '#FF0000 bold', # Red bold for HIGH risk
|
||||
}
|
||||
)
|
||||
return merge_styles([base, custom])
|
||||
|
||||
@@ -41,12 +41,6 @@ def suppress_cli_warnings():
|
||||
category=UserWarning,
|
||||
)
|
||||
|
||||
# Suppress SyntaxWarnings from pydub.utils about invalid escape sequences
|
||||
warnings.filterwarnings(
|
||||
'ignore',
|
||||
category=SyntaxWarning,
|
||||
module=r'pydub\.utils',
|
||||
)
|
||||
# Suppress LiteLLM close_litellm_async_clients was never awaited warning
|
||||
warnings.filterwarnings(
|
||||
'ignore',
|
||||
|
||||
@@ -5,14 +5,13 @@
|
||||
import asyncio
|
||||
import contextlib
|
||||
import datetime
|
||||
import html
|
||||
import json
|
||||
import re
|
||||
import sys
|
||||
import threading
|
||||
import time
|
||||
from typing import Generator
|
||||
|
||||
import markdown # type: ignore
|
||||
from prompt_toolkit import PromptSession, print_formatted_text
|
||||
from prompt_toolkit.application import Application
|
||||
from prompt_toolkit.completion import CompleteEvent, Completer, Completion
|
||||
@@ -24,11 +23,11 @@ from prompt_toolkit.key_binding.key_processor import KeyPressEvent
|
||||
from prompt_toolkit.keys import Keys
|
||||
from prompt_toolkit.layout.containers import HSplit, Window
|
||||
from prompt_toolkit.layout.controls import FormattedTextControl
|
||||
from prompt_toolkit.layout.dimension import Dimension
|
||||
from prompt_toolkit.layout.layout import Layout
|
||||
from prompt_toolkit.lexers import Lexer
|
||||
from prompt_toolkit.patch_stdout import patch_stdout
|
||||
from prompt_toolkit.shortcuts import print_container
|
||||
from prompt_toolkit.styles import Style
|
||||
from prompt_toolkit.widgets import Frame, TextArea
|
||||
|
||||
from openhands import __version__
|
||||
@@ -44,7 +43,6 @@ from openhands.events import EventSource, EventStream
|
||||
from openhands.events.action import (
|
||||
Action,
|
||||
ActionConfirmationStatus,
|
||||
ActionSecurityRisk,
|
||||
ChangeAgentStateAction,
|
||||
CmdRunAction,
|
||||
MCPAction,
|
||||
@@ -318,8 +316,8 @@ def display_message(message: str, is_agent_message: bool = False) -> None:
|
||||
print_formatted_text('')
|
||||
|
||||
try:
|
||||
# Render only basic markdown (bold/underline), escaping any HTML
|
||||
html_content = _render_basic_markdown(message)
|
||||
# Convert markdown to HTML for all messages
|
||||
html_content = convert_markdown_to_html(message)
|
||||
|
||||
if is_agent_message:
|
||||
# Use prompt_toolkit's HTML renderer with the agent color
|
||||
@@ -340,27 +338,38 @@ def display_message(message: str, is_agent_message: bool = False) -> None:
|
||||
print_formatted_text(message)
|
||||
|
||||
|
||||
def _render_basic_markdown(text: str | None) -> str | None:
|
||||
"""Render a very small subset of markdown directly to prompt_toolkit HTML.
|
||||
def convert_markdown_to_html(text: str) -> str:
|
||||
"""Convert markdown to HTML for prompt_toolkit's HTML renderer using the markdown library.
|
||||
|
||||
Supported:
|
||||
- Bold: **text** -> <b>text</b>
|
||||
- Underline: __text__ -> <u>text</u>
|
||||
Args:
|
||||
text: Markdown text to convert
|
||||
|
||||
Any existing HTML in input is escaped to avoid injection into the renderer.
|
||||
If input is None, return None.
|
||||
Returns:
|
||||
HTML formatted text with custom styling for headers and bullet points
|
||||
"""
|
||||
if text is None:
|
||||
return None
|
||||
if text == '':
|
||||
return ''
|
||||
if not text:
|
||||
return text
|
||||
|
||||
safe = html.escape(text)
|
||||
# Bold: greedy within a line, non-overlapping
|
||||
safe = re.sub(r'\*\*(.+?)\*\*', r'<b>\1</b>', safe)
|
||||
# Underline: double underscore
|
||||
safe = re.sub(r'__(.+?)__', r'<u>\1</u>', safe)
|
||||
return safe
|
||||
# Use the markdown library to convert markdown to HTML
|
||||
# Enable the 'extra' extension for tables, fenced code, etc.
|
||||
html = markdown.markdown(text, extensions=['extra'])
|
||||
|
||||
# Customize headers
|
||||
for i in range(1, 7):
|
||||
# Get the appropriate number of # characters for this heading level
|
||||
prefix = '#' * i + ' '
|
||||
|
||||
# Replace <h1> with the prefix and bold text
|
||||
html = html.replace(f'<h{i}>', f'<b>{prefix}')
|
||||
html = html.replace(f'</h{i}>', '</b>\n')
|
||||
|
||||
# Customize bullet points to use dashes instead of dots with compact spacing
|
||||
html = html.replace('<ul>', '')
|
||||
html = html.replace('</ul>', '')
|
||||
html = html.replace('<li>', '- ')
|
||||
html = html.replace('</li>', '')
|
||||
|
||||
return html
|
||||
|
||||
|
||||
def display_error(error: str) -> None:
|
||||
@@ -382,12 +391,9 @@ def display_error(error: str) -> None:
|
||||
|
||||
|
||||
def display_command(event: CmdRunAction) -> None:
|
||||
# Create simple command frame
|
||||
command_text = f'$ {event.command}'
|
||||
|
||||
container = Frame(
|
||||
TextArea(
|
||||
text=command_text,
|
||||
text=f'$ {event.command}',
|
||||
read_only=True,
|
||||
style=COLOR_GREY,
|
||||
wrap_lines=True,
|
||||
@@ -836,34 +842,20 @@ async def read_prompt_input(
|
||||
return '/exit'
|
||||
|
||||
|
||||
async def read_confirmation_input(
|
||||
config: OpenHandsConfig, security_risk: ActionSecurityRisk
|
||||
) -> str:
|
||||
async def read_confirmation_input(config: OpenHandsConfig) -> str:
|
||||
try:
|
||||
if security_risk == ActionSecurityRisk.HIGH:
|
||||
question = 'HIGH RISK command detected.\nReview carefully before proceeding.\n\nChoose an option:'
|
||||
choices = [
|
||||
'Yes, proceed (HIGH RISK - Use with caution)',
|
||||
'No (and allow to enter instructions)',
|
||||
"Always proceed (don't ask again - NOT RECOMMENDED)",
|
||||
]
|
||||
choice_mapping = {0: 'yes', 1: 'no', 2: 'always'}
|
||||
else:
|
||||
question = 'Choose an option:'
|
||||
choices = [
|
||||
'Yes, proceed',
|
||||
'No (and allow to enter instructions)',
|
||||
'Auto-confirm action with LOW/MEDIUM risk, ask for HIGH risk',
|
||||
"Always proceed (don't ask again)",
|
||||
]
|
||||
choice_mapping = {0: 'yes', 1: 'no', 2: 'auto_highrisk', 3: 'always'}
|
||||
choices = [
|
||||
'Yes, proceed',
|
||||
'No (and allow to enter instructions)',
|
||||
"Always proceed (don't ask again)",
|
||||
]
|
||||
|
||||
# keep the outer coroutine responsive by using asyncio.to_thread which puts the blocking call app.run() of cli_confirm() in a separate thread
|
||||
index = await asyncio.to_thread(
|
||||
cli_confirm, config, question, choices, 0, security_risk
|
||||
cli_confirm, config, 'Choose an option:', choices
|
||||
)
|
||||
|
||||
return choice_mapping.get(index, 'no')
|
||||
return {0: 'yes', 1: 'no', 2: 'always'}.get(index, 'no')
|
||||
|
||||
except (KeyboardInterrupt, EOFError):
|
||||
return 'no'
|
||||
@@ -922,7 +914,6 @@ def cli_confirm(
|
||||
question: str = 'Are you sure?',
|
||||
choices: list[str] | None = None,
|
||||
initial_selection: int = 0,
|
||||
security_risk: ActionSecurityRisk = ActionSecurityRisk.UNKNOWN,
|
||||
) -> int:
|
||||
"""Display a confirmation prompt with the given question and choices.
|
||||
|
||||
@@ -933,15 +924,8 @@ def cli_confirm(
|
||||
selected = [initial_selection] # Using list to allow modification in closure
|
||||
|
||||
def get_choice_text() -> list:
|
||||
# Use red styling for HIGH risk questions
|
||||
question_style = (
|
||||
'class:risk-high'
|
||||
if security_risk == ActionSecurityRisk.HIGH
|
||||
else 'class:question'
|
||||
)
|
||||
|
||||
return [
|
||||
(question_style, f'{question}\n\n'),
|
||||
('class:question', f'{question}\n\n'),
|
||||
] + [
|
||||
(
|
||||
'class:selected' if i == selected[0] else 'class:unselected',
|
||||
@@ -976,33 +960,23 @@ def cli_confirm(
|
||||
def _handle_enter(event: KeyPressEvent) -> None:
|
||||
event.app.exit(result=selected[0])
|
||||
|
||||
# Create layout with risk-based styling - full width but limited height
|
||||
content_window = Window(
|
||||
FormattedTextControl(get_choice_text),
|
||||
always_hide_cursor=True,
|
||||
height=Dimension(max=8), # Limit height to prevent screen takeover
|
||||
)
|
||||
style = Style.from_dict({'selected': COLOR_GOLD, 'unselected': ''})
|
||||
|
||||
# Add frame for HIGH risk commands
|
||||
if security_risk == ActionSecurityRisk.HIGH:
|
||||
layout = Layout(
|
||||
HSplit(
|
||||
[
|
||||
Frame(
|
||||
content_window,
|
||||
title='HIGH RISK',
|
||||
style='fg:#FF0000 bold', # Red color for HIGH risk
|
||||
)
|
||||
]
|
||||
)
|
||||
layout = Layout(
|
||||
HSplit(
|
||||
[
|
||||
Window(
|
||||
FormattedTextControl(get_choice_text),
|
||||
always_hide_cursor=True,
|
||||
)
|
||||
]
|
||||
)
|
||||
else:
|
||||
layout = Layout(HSplit([content_window]))
|
||||
)
|
||||
|
||||
app = Application(
|
||||
layout=layout,
|
||||
key_bindings=kb,
|
||||
style=DEFAULT_STYLE,
|
||||
style=style,
|
||||
full_screen=False,
|
||||
)
|
||||
|
||||
|
||||
@@ -74,9 +74,7 @@ class Agent(ABC):
|
||||
)
|
||||
return None
|
||||
|
||||
system_message = self.prompt_manager.get_system_message(
|
||||
cli_mode=self.config.cli_mode
|
||||
)
|
||||
system_message = self.prompt_manager.get_system_message()
|
||||
|
||||
# Get tools if available
|
||||
tools = getattr(self, 'tools', None)
|
||||
|
||||
@@ -5,10 +5,7 @@ import copy
|
||||
import os
|
||||
import time
|
||||
import traceback
|
||||
from typing import TYPE_CHECKING, Callable
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from openhands.security.analyzer import SecurityAnalyzer
|
||||
from typing import Callable
|
||||
|
||||
from litellm.exceptions import ( # noqa
|
||||
APIConnectionError,
|
||||
@@ -52,15 +49,11 @@ from openhands.events import (
|
||||
from openhands.events.action import (
|
||||
Action,
|
||||
ActionConfirmationStatus,
|
||||
ActionSecurityRisk,
|
||||
AgentDelegateAction,
|
||||
AgentFinishAction,
|
||||
AgentRejectAction,
|
||||
BrowseInteractiveAction,
|
||||
ChangeAgentStateAction,
|
||||
CmdRunAction,
|
||||
FileEditAction,
|
||||
FileReadAction,
|
||||
IPythonRunCellAction,
|
||||
MessageAction,
|
||||
NullAction,
|
||||
@@ -130,7 +123,6 @@ class AgentController:
|
||||
headless_mode: bool = True,
|
||||
status_callback: Callable | None = None,
|
||||
replay_events: list[Event] | None = None,
|
||||
security_analyzer: 'SecurityAnalyzer | None' = None,
|
||||
):
|
||||
"""Initializes a new instance of the AgentController class.
|
||||
|
||||
@@ -193,54 +185,9 @@ class AgentController:
|
||||
# replay-related
|
||||
self._replay_manager = ReplayManager(replay_events)
|
||||
|
||||
self.confirmation_mode = confirmation_mode
|
||||
|
||||
# security analyzer for direct access
|
||||
self.security_analyzer = security_analyzer
|
||||
|
||||
# Add the system message to the event stream
|
||||
self._add_system_message()
|
||||
|
||||
async def _handle_security_analyzer(self, action: Action) -> None:
|
||||
"""Handle security risk analysis for an action.
|
||||
|
||||
If a security analyzer is configured, use it to analyze the action.
|
||||
If no security analyzer is configured, set the risk to HIGH (fail-safe approach).
|
||||
|
||||
Args:
|
||||
action: The action to analyze for security risks.
|
||||
"""
|
||||
if self.security_analyzer:
|
||||
try:
|
||||
if (
|
||||
hasattr(action, 'security_risk')
|
||||
and action.security_risk is not None
|
||||
):
|
||||
logger.debug(
|
||||
f'Original security risk for {action}: {action.security_risk})'
|
||||
)
|
||||
if hasattr(action, 'security_risk'):
|
||||
action.security_risk = await self.security_analyzer.security_risk(
|
||||
action
|
||||
)
|
||||
logger.debug(
|
||||
f'[Security Analyzer: {self.security_analyzer.__class__}] Override security risk for action {action}: {action.security_risk}'
|
||||
)
|
||||
except Exception as e:
|
||||
logger.warning(
|
||||
f'Failed to analyze security risk for action {action}: {e}'
|
||||
)
|
||||
if hasattr(action, 'security_risk'):
|
||||
action.security_risk = ActionSecurityRisk.UNKNOWN
|
||||
else:
|
||||
# When no security analyzer is configured, treat all actions as UNKNOWN risk
|
||||
# This is a fail-safe approach that ensures confirmation is required
|
||||
logger.debug(
|
||||
f'No security analyzer configured, setting UNKNOWN risk for action: {action}'
|
||||
)
|
||||
if hasattr(action, 'security_risk'):
|
||||
action.security_risk = ActionSecurityRisk.UNKNOWN
|
||||
|
||||
def _add_system_message(self):
|
||||
for event in self.event_stream.search_events(start_id=self.state.start_id):
|
||||
if isinstance(event, MessageAction) and event.source == EventSource.USER:
|
||||
@@ -748,7 +695,6 @@ class AgentController:
|
||||
initial_state=state,
|
||||
is_delegate=True,
|
||||
headless_mode=self.headless_mode,
|
||||
security_analyzer=self.security_analyzer,
|
||||
)
|
||||
|
||||
def end_delegate(self) -> None:
|
||||
@@ -895,10 +841,8 @@ class AgentController:
|
||||
'contextwindowexceedederror' in error_str
|
||||
or 'prompt is too long' in error_str
|
||||
or 'input length and `max_tokens` exceed context limit' in error_str
|
||||
or 'please reduce the length of either one' in error_str
|
||||
or 'the request exceeds the available context size' in error_str
|
||||
or 'context length exceeded' in error_str
|
||||
# For OpenRouter context window errors
|
||||
or 'please reduce the length of either one'
|
||||
in error_str # For OpenRouter context window errors
|
||||
or (
|
||||
'sambanovaexception' in error_str
|
||||
and 'maximum context length' in error_str
|
||||
@@ -918,45 +862,11 @@ class AgentController:
|
||||
|
||||
if action.runnable:
|
||||
if self.state.confirmation_mode and (
|
||||
type(action) is CmdRunAction
|
||||
or type(action) is IPythonRunCellAction
|
||||
or type(action) is BrowseInteractiveAction
|
||||
or type(action) is FileEditAction
|
||||
or type(action) is FileReadAction
|
||||
type(action) is CmdRunAction or type(action) is IPythonRunCellAction
|
||||
):
|
||||
# Handle security risk analysis using the dedicated method
|
||||
await self._handle_security_analyzer(action)
|
||||
|
||||
# Check if the action has a security_risk attribute set by the LLM or security analyzer
|
||||
security_risk = getattr(
|
||||
action, 'security_risk', ActionSecurityRisk.UNKNOWN
|
||||
action.confirmation_state = (
|
||||
ActionConfirmationStatus.AWAITING_CONFIRMATION
|
||||
)
|
||||
|
||||
is_high_security_risk = security_risk == ActionSecurityRisk.HIGH
|
||||
is_ask_for_every_action = (
|
||||
security_risk == ActionSecurityRisk.UNKNOWN
|
||||
and not self.security_analyzer
|
||||
)
|
||||
|
||||
# If security_risk is HIGH, requires confirmation
|
||||
# UNLESS it is CLI which will handle action risks it itself
|
||||
if self.agent.config.cli_mode:
|
||||
# TODO(refactor): this is not ideal to have CLI been an exception
|
||||
# We should refactor agent controller to consider this in the future
|
||||
# See issue: https://github.com/All-Hands-AI/OpenHands/issues/10464
|
||||
action.confirmation_state = ( # type: ignore[union-attr]
|
||||
ActionConfirmationStatus.AWAITING_CONFIRMATION
|
||||
)
|
||||
# Only HIGH security risk actions require confirmation
|
||||
elif (
|
||||
is_high_security_risk or is_ask_for_every_action
|
||||
) and self.confirmation_mode:
|
||||
logger.debug(
|
||||
f'[non-CLI mode] Detected HIGH security risk in action: {action}. Ask for confirmation'
|
||||
)
|
||||
action.confirmation_state = ( # type: ignore[union-attr]
|
||||
ActionConfirmationStatus.AWAITING_CONFIRMATION
|
||||
)
|
||||
self._pending_action = action
|
||||
|
||||
if not isinstance(action, NullAction):
|
||||
|
||||
@@ -12,8 +12,6 @@ from openhands.utils.import_utils import get_impl
|
||||
|
||||
|
||||
class AgentConfig(BaseModel):
|
||||
cli_mode: bool = Field(default=False)
|
||||
"""Whether the agent is running in CLI mode. This can be used to disable certain tools that are not supported in CLI mode."""
|
||||
llm_config: str | None = Field(default=None)
|
||||
"""The name of the llm config to use. If specified, this will override global llm config."""
|
||||
classpath: str | None = Field(default=None)
|
||||
|
||||
@@ -26,6 +26,7 @@ from openhands.memory.memory import Memory
|
||||
from openhands.microagent.microagent import BaseMicroagent
|
||||
from openhands.runtime import get_runtime_cls
|
||||
from openhands.runtime.base import Runtime
|
||||
from openhands.security import SecurityAnalyzer, options
|
||||
from openhands.server.services.conversation_stats import ConversationStats
|
||||
from openhands.storage import get_file_store
|
||||
from openhands.storage.data_models.user_secrets import UserSecrets
|
||||
@@ -62,6 +63,12 @@ def create_runtime(
|
||||
file_store = get_file_store(config.file_store, config.file_store_path)
|
||||
event_stream = EventStream(session_id, file_store)
|
||||
|
||||
# set up the security analyzer
|
||||
if config.security.security_analyzer:
|
||||
options.SecurityAnalyzers.get(
|
||||
config.security.security_analyzer, SecurityAnalyzer
|
||||
)(event_stream)
|
||||
|
||||
# agent class
|
||||
if agent:
|
||||
agent_cls = type(agent)
|
||||
@@ -238,7 +245,6 @@ def create_controller(
|
||||
headless_mode=headless_mode,
|
||||
confirmation_mode=config.security.confirmation_mode,
|
||||
replay_events=replay_events,
|
||||
security_analyzer=runtime.security_analyzer,
|
||||
)
|
||||
return (controller, initial_state)
|
||||
|
||||
|
||||
@@ -1,8 +1,4 @@
|
||||
from openhands.events.action.action import (
|
||||
Action,
|
||||
ActionConfirmationStatus,
|
||||
ActionSecurityRisk,
|
||||
)
|
||||
from openhands.events.action.action import Action, ActionConfirmationStatus
|
||||
from openhands.events.action.agent import (
|
||||
AgentDelegateAction,
|
||||
AgentFinishAction,
|
||||
@@ -44,5 +40,4 @@ __all__ = [
|
||||
'RecallAction',
|
||||
'MCPAction',
|
||||
'TaskTrackingAction',
|
||||
'ActionSecurityRisk',
|
||||
]
|
||||
|
||||
@@ -11,7 +11,7 @@ class BrowseURLAction(Action):
|
||||
thought: str = ''
|
||||
action: str = ActionType.BROWSE
|
||||
runnable: ClassVar[bool] = True
|
||||
security_risk: ActionSecurityRisk = ActionSecurityRisk.UNKNOWN
|
||||
security_risk: ActionSecurityRisk | None = None
|
||||
return_axtree: bool = False
|
||||
|
||||
@property
|
||||
@@ -33,7 +33,7 @@ class BrowseInteractiveAction(Action):
|
||||
browsergym_send_msg_to_user: str = ''
|
||||
action: str = ActionType.BROWSE_INTERACTIVE
|
||||
runnable: ClassVar[bool] = True
|
||||
security_risk: ActionSecurityRisk = ActionSecurityRisk.UNKNOWN
|
||||
security_risk: ActionSecurityRisk | None = None
|
||||
return_axtree: bool = False
|
||||
|
||||
@property
|
||||
|
||||
@@ -25,7 +25,7 @@ class CmdRunAction(Action):
|
||||
action: str = ActionType.RUN
|
||||
runnable: ClassVar[bool] = True
|
||||
confirmation_state: ActionConfirmationStatus = ActionConfirmationStatus.CONFIRMED
|
||||
security_risk: ActionSecurityRisk = ActionSecurityRisk.UNKNOWN
|
||||
security_risk: ActionSecurityRisk | None = None
|
||||
|
||||
@property
|
||||
def message(self) -> str:
|
||||
@@ -49,7 +49,7 @@ class IPythonRunCellAction(Action):
|
||||
action: str = ActionType.RUN_IPYTHON
|
||||
runnable: ClassVar[bool] = True
|
||||
confirmation_state: ActionConfirmationStatus = ActionConfirmationStatus.CONFIRMED
|
||||
security_risk: ActionSecurityRisk = ActionSecurityRisk.UNKNOWN
|
||||
security_risk: ActionSecurityRisk | None = None
|
||||
kernel_init_code: str = '' # code to run in the kernel (if the kernel is restarted)
|
||||
|
||||
def __str__(self) -> str:
|
||||
|
||||
@@ -19,7 +19,7 @@ class FileReadAction(Action):
|
||||
thought: str = ''
|
||||
action: str = ActionType.READ
|
||||
runnable: ClassVar[bool] = True
|
||||
security_risk: ActionSecurityRisk = ActionSecurityRisk.UNKNOWN
|
||||
security_risk: ActionSecurityRisk | None = None
|
||||
impl_source: FileReadSource = FileReadSource.DEFAULT
|
||||
view_range: list[int] | None = None # ONLY used in OH_ACI mode
|
||||
|
||||
@@ -42,7 +42,7 @@ class FileWriteAction(Action):
|
||||
thought: str = ''
|
||||
action: str = ActionType.WRITE
|
||||
runnable: ClassVar[bool] = True
|
||||
security_risk: ActionSecurityRisk = ActionSecurityRisk.UNKNOWN
|
||||
security_risk: ActionSecurityRisk | None = None
|
||||
|
||||
@property
|
||||
def message(self) -> str:
|
||||
@@ -111,7 +111,7 @@ class FileEditAction(Action):
|
||||
thought: str = ''
|
||||
action: str = ActionType.EDIT
|
||||
runnable: ClassVar[bool] = True
|
||||
security_risk: ActionSecurityRisk = ActionSecurityRisk.UNKNOWN
|
||||
security_risk: ActionSecurityRisk | None = None
|
||||
impl_source: FileEditSource = FileEditSource.OH_ACI
|
||||
|
||||
def __repr__(self) -> str:
|
||||
|
||||
@@ -12,7 +12,7 @@ class MCPAction(Action):
|
||||
thought: str = ''
|
||||
action: str = ActionType.MCP
|
||||
runnable: ClassVar[bool] = True
|
||||
security_risk: ActionSecurityRisk = ActionSecurityRisk.UNKNOWN
|
||||
security_risk: ActionSecurityRisk | None = None
|
||||
|
||||
@property
|
||||
def message(self) -> str:
|
||||
|
||||
@@ -13,7 +13,7 @@ class MessageAction(Action):
|
||||
image_urls: list[str] | None = None
|
||||
wait_for_response: bool = False
|
||||
action: str = ActionType.MESSAGE
|
||||
security_risk: ActionSecurityRisk = ActionSecurityRisk.UNKNOWN
|
||||
security_risk: ActionSecurityRisk | None = None
|
||||
|
||||
@property
|
||||
def message(self) -> str:
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
from typing import Any
|
||||
|
||||
from openhands.core.exceptions import LLMMalformedActionError
|
||||
from openhands.events.action.action import Action, ActionSecurityRisk
|
||||
from openhands.events.action.action import Action
|
||||
from openhands.events.action.agent import (
|
||||
AgentDelegateAction,
|
||||
AgentFinishAction,
|
||||
@@ -124,15 +124,6 @@ def action_from_dict(action: dict) -> Action:
|
||||
if 'images_urls' in args:
|
||||
args['image_urls'] = args.pop('images_urls')
|
||||
|
||||
# Handle security_risk deserialization
|
||||
if 'security_risk' in args and args['security_risk'] is not None:
|
||||
try:
|
||||
# Convert numeric value (int) back to enum
|
||||
args['security_risk'] = ActionSecurityRisk(args['security_risk'])
|
||||
except (ValueError, TypeError):
|
||||
# If conversion fails, remove the invalid value
|
||||
args.pop('security_risk')
|
||||
|
||||
# handle deprecated args
|
||||
args = handle_action_deprecated_args(args)
|
||||
|
||||
|
||||
@@ -119,17 +119,12 @@ def event_to_dict(event: 'Event') -> dict:
|
||||
if key == 'llm_metrics' and 'llm_metrics' in d:
|
||||
d['llm_metrics'] = d['llm_metrics'].get()
|
||||
props.pop(key, None)
|
||||
|
||||
if 'security_risk' in props and props['security_risk'] is None:
|
||||
props.pop('security_risk')
|
||||
|
||||
# Remove task_completed from serialization when it's None (backward compatibility)
|
||||
if 'task_completed' in props and props['task_completed'] is None:
|
||||
props.pop('task_completed')
|
||||
if 'action' in d:
|
||||
# Handle security_risk for actions - include it in args
|
||||
if 'security_risk' in props:
|
||||
props['security_risk'] = props['security_risk'].value
|
||||
d['args'] = props
|
||||
if event.timeout is not None:
|
||||
d['timeout'] = event.timeout
|
||||
|
||||
@@ -22,6 +22,7 @@ from openhands.utils.shutdown_listener import should_continue
|
||||
|
||||
class EventStreamSubscriber(str, Enum):
|
||||
AGENT_CONTROLLER = 'agent_controller'
|
||||
SECURITY_ANALYZER = 'security_analyzer'
|
||||
RESOLVER = 'openhands_resolver'
|
||||
SERVER = 'server'
|
||||
RUNTIME = 'runtime'
|
||||
|
||||
@@ -515,16 +515,6 @@ class LLM(RetryMixin, DebugMixin):
|
||||
Returns:
|
||||
bool: True if model is vision capable. Return False if model not supported by litellm.
|
||||
"""
|
||||
|
||||
# Allow manual override via environment variable
|
||||
if os.getenv('OPENHANDS_FORCE_VISION', '').lower() in (
|
||||
'1',
|
||||
'true',
|
||||
'yes',
|
||||
'on',
|
||||
):
|
||||
return True
|
||||
|
||||
# litellm.supports_vision currently returns False for 'openai/gpt-...' or 'anthropic/claude-...' (with prefixes)
|
||||
# but model_info will have the correct value for some reason.
|
||||
# we can go with it, but we will need to keep an eye if model_info is correct for Vertex or other providers
|
||||
|
||||
@@ -809,9 +809,7 @@ class ConversationMemory:
|
||||
'[ConversationMemory] No SystemMessageAction found in events. '
|
||||
'Adding one for backward compatibility. '
|
||||
)
|
||||
system_prompt = self.prompt_manager.get_system_message(
|
||||
cli_mode=self.agent_config.cli_mode
|
||||
)
|
||||
system_prompt = self.prompt_manager.get_system_message()
|
||||
if system_prompt:
|
||||
system_message = SystemMessageAction(content=system_prompt)
|
||||
# Insert the system message directly at the beginning of the events list
|
||||
|
||||
@@ -328,12 +328,7 @@ class ActionExecutor:
|
||||
|
||||
async def _init_plugin(self, plugin: Plugin):
|
||||
assert self.bash_session is not None
|
||||
# VSCode plugin needs runtime_id for path-based routing when using Gateway API
|
||||
if isinstance(plugin, VSCodePlugin):
|
||||
runtime_id = os.environ.get('RUNTIME_ID')
|
||||
await plugin.initialize(self.username, runtime_id=runtime_id)
|
||||
else:
|
||||
await plugin.initialize(self.username)
|
||||
await plugin.initialize(self.username)
|
||||
self.plugins[plugin.name] = plugin
|
||||
logger.debug(f'Initializing plugin: {plugin.name}')
|
||||
|
||||
@@ -881,9 +876,7 @@ if __name__ == '__main__':
|
||||
|
||||
@app.post('/upload_file')
|
||||
async def upload_file(
|
||||
file: UploadFile,
|
||||
destination: str = '/',
|
||||
recursive: bool = False,
|
||||
file: UploadFile, destination: str = '/', recursive: bool = False
|
||||
):
|
||||
assert client is not None
|
||||
|
||||
|
||||
@@ -67,7 +67,6 @@ from openhands.runtime.plugins import (
|
||||
from openhands.runtime.runtime_status import RuntimeStatus
|
||||
from openhands.runtime.utils.edit import FileEditRuntimeMixin
|
||||
from openhands.runtime.utils.git_handler import CommandResult, GitHandler
|
||||
from openhands.security import SecurityAnalyzer, options
|
||||
from openhands.storage.locations import get_conversation_dir
|
||||
from openhands.utils.async_utils import (
|
||||
GENERAL_TIMEOUT,
|
||||
@@ -123,7 +122,6 @@ class Runtime(FileEditRuntimeMixin):
|
||||
status_callback: Callable[[str, RuntimeStatus, str], None] | None
|
||||
runtime_status: RuntimeStatus | None
|
||||
_runtime_initialized: bool = False
|
||||
security_analyzer: 'SecurityAnalyzer | None' = None
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
@@ -192,17 +190,6 @@ class Runtime(FileEditRuntimeMixin):
|
||||
self.git_provider_tokens = git_provider_tokens
|
||||
self.runtime_status = None
|
||||
|
||||
# Initialize security analyzer
|
||||
self.security_analyzer = None
|
||||
if self.config.security.security_analyzer:
|
||||
analyzer_cls = options.SecurityAnalyzers.get(
|
||||
self.config.security.security_analyzer, SecurityAnalyzer
|
||||
)
|
||||
self.security_analyzer = analyzer_cls()
|
||||
logger.debug(
|
||||
f'Security analyzer {analyzer_cls.__name__} initialized for runtime {self.sid}'
|
||||
)
|
||||
|
||||
@property
|
||||
def runtime_initialized(self) -> bool:
|
||||
return self._runtime_initialized
|
||||
|
||||
@@ -159,6 +159,9 @@ class CLIRuntime(Runtime):
|
||||
self._is_windows = sys.platform == 'win32'
|
||||
self._powershell_session: WindowsPowershellSession | None = None
|
||||
|
||||
# Track git wrapper bin dir for use in subprocess env
|
||||
self._git_wrapper_bin_dir = os.path.expanduser('~/.openhands/bin')
|
||||
|
||||
logger.warning(
|
||||
'Initializing CLIRuntime. WARNING: NO SANDBOX IS USED. '
|
||||
'This runtime executes commands directly on the local system. '
|
||||
@@ -217,6 +220,106 @@ class CLIRuntime(Runtime):
|
||||
# We don't use self.run() here because this method is called
|
||||
# during initialization before self._runtime_initialized is True.
|
||||
|
||||
def setup_initial_env(self) -> None:
|
||||
"""Override to add git wrapper setup for CLIRuntime."""
|
||||
super().setup_initial_env()
|
||||
|
||||
# Always enable git co-authorship in CLI runtime
|
||||
self._setup_git_wrapper()
|
||||
# As a fallback for commit invocations that don't use -m/--message
|
||||
# ensure a global prepare-commit-msg hook is configured so co-authorship
|
||||
# is still added (parity with Docker runtime behavior in tests).
|
||||
try:
|
||||
hooks_root = os.path.expanduser('~/.openhands/git-hooks')
|
||||
hooks_dir = os.path.join(hooks_root, 'hooks')
|
||||
os.makedirs(hooks_dir, exist_ok=True)
|
||||
|
||||
hook_src = os.path.join(
|
||||
os.path.dirname(os.path.dirname(os.path.dirname(__file__))),
|
||||
'utils',
|
||||
'git_hooks',
|
||||
'prepare-commit-msg',
|
||||
)
|
||||
hook_dest = os.path.join(hooks_dir, 'prepare-commit-msg')
|
||||
if os.path.exists(hook_src):
|
||||
shutil.copyfile(hook_src, hook_dest)
|
||||
os.chmod(hook_dest, 0o755)
|
||||
# Configure global hooks path and template dir so newly inited repos pick it up
|
||||
subprocess.run(
|
||||
['git', 'config', '--global', 'core.hooksPath', hooks_dir],
|
||||
check=False,
|
||||
)
|
||||
subprocess.run(
|
||||
['git', 'config', '--global', 'init.templateDir', hooks_root],
|
||||
check=False,
|
||||
)
|
||||
logger.info(
|
||||
f'[CLIRuntime] Configured global git hooks at {hooks_dir} for co-authorship'
|
||||
)
|
||||
except Exception as e:
|
||||
logger.warning(f'[CLIRuntime] Failed to configure global git hook: {e}')
|
||||
|
||||
def _setup_git_wrapper(self) -> None:
|
||||
"""Set up git wrapper to automatically add co-authorship."""
|
||||
try:
|
||||
# Path to our git wrapper script
|
||||
git_wrapper_source = os.path.join(
|
||||
os.path.dirname(
|
||||
os.path.dirname(os.path.dirname(__file__))
|
||||
), # openhands/runtime/
|
||||
'utils',
|
||||
'git_wrapper.sh',
|
||||
)
|
||||
|
||||
if not os.path.exists(git_wrapper_source):
|
||||
logger.warning(
|
||||
f'[CLIRuntime] Git wrapper not found at {git_wrapper_source}'
|
||||
)
|
||||
return
|
||||
|
||||
# Find the real git executable path
|
||||
import subprocess
|
||||
|
||||
try:
|
||||
real_git_path = subprocess.check_output(
|
||||
['which', 'git'], text=True
|
||||
).strip()
|
||||
except subprocess.CalledProcessError:
|
||||
logger.warning('[CLIRuntime] Could not find git executable')
|
||||
return
|
||||
|
||||
# Create a bin directory in user's home for our git wrapper
|
||||
bin_dir = os.path.expanduser('~/.openhands/bin')
|
||||
os.makedirs(bin_dir, exist_ok=True)
|
||||
|
||||
# Create a modified wrapper that calls the real git with full path
|
||||
git_wrapper_dest = os.path.join(bin_dir, 'git')
|
||||
with open(git_wrapper_source, 'r') as src:
|
||||
wrapper_content = src.read()
|
||||
|
||||
# Replace 'command git' with the full path to avoid recursion
|
||||
wrapper_content = wrapper_content.replace(
|
||||
'command git', f'"{real_git_path}"'
|
||||
)
|
||||
|
||||
with open(git_wrapper_dest, 'w') as dest:
|
||||
dest.write(wrapper_content)
|
||||
|
||||
os.chmod(git_wrapper_dest, 0o755)
|
||||
|
||||
# Prepend the bin directory to PATH so our git wrapper is found first
|
||||
# This works for all commands including chained ones like "cd dir && git commit"
|
||||
current_path = os.environ.get('PATH', '')
|
||||
new_path = f'{bin_dir}:{current_path}'
|
||||
os.environ['PATH'] = new_path
|
||||
|
||||
logger.info(
|
||||
f'[CLIRuntime] Set up OpenHands git wrapper at {git_wrapper_dest} for co-authorship'
|
||||
)
|
||||
|
||||
except Exception as e:
|
||||
logger.warning(f'[CLIRuntime] Failed to set up git wrapper: {e}')
|
||||
|
||||
def _safe_terminate_process(self, process_obj, signal_to_send=signal.SIGTERM):
|
||||
"""Safely attempts to terminate/kill a process group or a single process.
|
||||
|
||||
@@ -337,6 +440,13 @@ class CLIRuntime(Runtime):
|
||||
timed_out = False
|
||||
start_time = time.monotonic()
|
||||
|
||||
# Ensure our git wrapper bin dir is first in PATH for the subprocess
|
||||
env = os.environ.copy()
|
||||
bin_dir = getattr(
|
||||
self, '_git_wrapper_bin_dir', os.path.expanduser('~/.openhands/bin')
|
||||
)
|
||||
env['PATH'] = f'{bin_dir}:{env.get("PATH", "")}'
|
||||
|
||||
# Use shell=True to run complex bash commands
|
||||
process = subprocess.Popen(
|
||||
['bash', '-c', command],
|
||||
@@ -346,9 +456,10 @@ class CLIRuntime(Runtime):
|
||||
bufsize=1, # Explicitly line-buffered for text mode
|
||||
universal_newlines=True,
|
||||
start_new_session=True,
|
||||
env=env,
|
||||
)
|
||||
logger.debug(
|
||||
f'[_execute_shell_command] PID of bash -c: {process.pid} for command: "{command}"'
|
||||
f'[_execute_shell_command] PID of bash -c: {process.pid} for command: "{command}" with PATH={env.get("PATH")}'
|
||||
)
|
||||
|
||||
exit_code = None
|
||||
@@ -458,15 +569,20 @@ class CLIRuntime(Runtime):
|
||||
f'Running command in CLIRuntime: "{action.command}" with effective timeout: {effective_timeout}s'
|
||||
)
|
||||
|
||||
# Use the command as-is since git alias is set up
|
||||
command_to_execute = action.command
|
||||
|
||||
# Use PowerShell on Windows if available, otherwise use subprocess
|
||||
if self._is_windows and self._powershell_session is not None:
|
||||
return self._execute_powershell_command(
|
||||
action.command, timeout=effective_timeout
|
||||
result = self._execute_powershell_command(
|
||||
command_to_execute, timeout=effective_timeout
|
||||
)
|
||||
else:
|
||||
return self._execute_shell_command(
|
||||
action.command, timeout=effective_timeout
|
||||
result = self._execute_shell_command(
|
||||
command_to_execute, timeout=effective_timeout
|
||||
)
|
||||
|
||||
return result
|
||||
except Exception as e:
|
||||
logger.error(
|
||||
f'Error in CLIRuntime.run for command "{action.command}": {str(e)}'
|
||||
|
||||
@@ -575,8 +575,9 @@ class LocalRuntime(ActionExecutionClient):
|
||||
|
||||
# TODO: This could be removed if we had a straightforward variable containing the RUNTIME_URL in the K8 env.
|
||||
runtime_url_pattern = os.getenv('RUNTIME_URL_PATTERN')
|
||||
runtime_id = os.getenv('RUNTIME_ID')
|
||||
if runtime_url_pattern and runtime_id:
|
||||
hostname = os.getenv('HOSTNAME')
|
||||
if runtime_url_pattern and hostname:
|
||||
runtime_id = hostname.split('-')[1]
|
||||
runtime_url = runtime_url_pattern.format(runtime_id=runtime_id)
|
||||
return runtime_url
|
||||
|
||||
@@ -585,19 +586,12 @@ class LocalRuntime(ActionExecutionClient):
|
||||
|
||||
def _create_url(self, prefix: str, port: int) -> str:
|
||||
runtime_url = self.runtime_url
|
||||
logger.debug(f'runtime_url is {runtime_url}')
|
||||
if 'localhost' in runtime_url:
|
||||
url = f'{self.runtime_url}:{self._vscode_port}'
|
||||
else:
|
||||
runtime_id = os.getenv('RUNTIME_ID')
|
||||
parsed = urlparse(self.runtime_url)
|
||||
scheme, netloc, path = parsed.scheme, parsed.netloc, parsed.path or '/'
|
||||
path_mode = path.startswith(f'/{runtime_id}') if runtime_id else False
|
||||
if path_mode:
|
||||
url = f'{scheme}://{netloc}/{runtime_id}/{prefix}'
|
||||
else:
|
||||
url = f'{scheme}://{prefix}-{netloc}'
|
||||
logger.debug(f'_create_url url is {url}')
|
||||
# Similar to remote runtime...
|
||||
parsed_url = urlparse(runtime_url)
|
||||
url = f'{parsed_url.scheme}://{prefix}-{parsed_url.netloc}'
|
||||
return url
|
||||
|
||||
@property
|
||||
|
||||
@@ -379,16 +379,11 @@ class RemoteRuntime(ActionExecutionClient):
|
||||
token = super().get_vscode_token()
|
||||
if not token:
|
||||
return None
|
||||
assert self.runtime_url is not None and self.runtime_id is not None
|
||||
self.log('debug', f'runtime_url: {self.runtime_url}')
|
||||
parsed = urlparse(self.runtime_url)
|
||||
scheme, netloc, path = parsed.scheme, parsed.netloc, parsed.path or '/'
|
||||
# Path mode if runtime_url path starts with /{id}
|
||||
path_mode = path.startswith(f'/{self.runtime_id}')
|
||||
if path_mode:
|
||||
vscode_url = f'{scheme}://{netloc}/{self.runtime_id}/vscode?tkn={token}&folder={self.config.workspace_mount_path_in_sandbox}'
|
||||
else:
|
||||
vscode_url = f'{scheme}://vscode-{netloc}/?tkn={token}&folder={self.config.workspace_mount_path_in_sandbox}'
|
||||
_parsed_url = urlparse(self.runtime_url)
|
||||
assert isinstance(_parsed_url.scheme, str) and isinstance(
|
||||
_parsed_url.netloc, str
|
||||
)
|
||||
vscode_url = f'{_parsed_url.scheme}://vscode-{_parsed_url.netloc}/?tkn={token}&folder={self.config.workspace_mount_path_in_sandbox}'
|
||||
self.log(
|
||||
'debug',
|
||||
f'VSCode URL: {vscode_url}',
|
||||
|
||||
@@ -6,7 +6,6 @@ import uuid
|
||||
from dataclasses import dataclass
|
||||
from pathlib import Path
|
||||
from typing import Optional
|
||||
from urllib.parse import urlparse
|
||||
|
||||
from openhands.core.logger import openhands_logger as logger
|
||||
from openhands.events.action import Action
|
||||
@@ -27,7 +26,7 @@ class VSCodePlugin(Plugin):
|
||||
vscode_connection_token: Optional[str] = None
|
||||
gateway_process: asyncio.subprocess.Process
|
||||
|
||||
async def initialize(self, username: str, runtime_id: str | None = None) -> None:
|
||||
async def initialize(self, username: str) -> None:
|
||||
# Check if we're on Windows - VSCode plugin is not supported on Windows
|
||||
if os.name == 'nt' or sys.platform == 'win32':
|
||||
self.vscode_port = None
|
||||
@@ -64,30 +63,11 @@ class VSCodePlugin(Plugin):
|
||||
)
|
||||
return
|
||||
workspace_path = os.getenv('WORKSPACE_MOUNT_PATH_IN_SANDBOX', '/workspace')
|
||||
# Compute base path for OpenVSCode Server when running behind a path-based router
|
||||
base_path_flag = ''
|
||||
# Allow explicit override via environment
|
||||
explicit_base = os.getenv('OPENVSCODE_SERVER_BASE_PATH')
|
||||
if explicit_base:
|
||||
explicit_base = (
|
||||
explicit_base if explicit_base.startswith('/') else f'/{explicit_base}'
|
||||
)
|
||||
base_path_flag = f' --server-base-path {explicit_base.rstrip("/")}'
|
||||
else:
|
||||
# If runtime_id passed explicitly (preferred), use it
|
||||
runtime_url = os.getenv('RUNTIME_URL', '')
|
||||
if runtime_url and runtime_id:
|
||||
parsed = urlparse(runtime_url)
|
||||
path = parsed.path or '/'
|
||||
path_mode = path.startswith(f'/{runtime_id}')
|
||||
if path_mode:
|
||||
base_path_flag = f' --server-base-path /{runtime_id}/vscode'
|
||||
|
||||
cmd = (
|
||||
f"su - {username} -s /bin/bash << 'EOF'\n"
|
||||
f'sudo chown -R {username}:{username} /openhands/.openvscode-server\n'
|
||||
f'cd {workspace_path}\n'
|
||||
f'exec /openhands/.openvscode-server/bin/openvscode-server --host 0.0.0.0 --connection-token {self.vscode_connection_token} --port {self.vscode_port} --disable-workspace-trust{base_path_flag}\n'
|
||||
f'exec /openhands/.openvscode-server/bin/openvscode-server --host 0.0.0.0 --connection-token {self.vscode_connection_token} --port {self.vscode_port} --disable-workspace-trust\n'
|
||||
'EOF'
|
||||
)
|
||||
|
||||
|
||||
@@ -194,8 +194,9 @@ class BashSession:
|
||||
self.server = libtmux.Server()
|
||||
_shell_command = '/bin/bash'
|
||||
if self.username in ['root', 'openhands']:
|
||||
# This starts a non-login (new) shell for the given user
|
||||
_shell_command = f'su {self.username} -'
|
||||
# Start a login shell for the given user without running an interactive login prompt
|
||||
# Use 'su -c' to run bash and ensure we start inside the project's working dir (self.work_dir).
|
||||
_shell_command = f"su {self.username} -c 'cd {self.work_dir} && /bin/bash'"
|
||||
|
||||
# FIXME: we will introduce memory limit using sysbox-runc in coming PR
|
||||
# # otherwise, we are running as the CURRENT USER (e.g., when running LocalRuntime)
|
||||
@@ -416,7 +417,7 @@ class BashSession:
|
||||
)
|
||||
metadata = CmdOutputMetadata() # No metadata available
|
||||
metadata.suffix = (
|
||||
f'\n[The command timed out after {timeout} seconds. '
|
||||
f'\n[The command timed out after {float(timeout):.1f} seconds. '
|
||||
f'{TIMEOUT_MESSAGE_TEMPLATE}]'
|
||||
)
|
||||
command_output = self._get_command_output(
|
||||
|
||||
@@ -39,9 +39,15 @@ def get_action_execution_server_startup_command(
|
||||
username = override_username or (
|
||||
'openhands' if app_config.run_as_openhands else 'root'
|
||||
)
|
||||
user_id = override_user_id or (
|
||||
sandbox_config.user_id if app_config.run_as_openhands else 0
|
||||
)
|
||||
if app_config.run_as_openhands:
|
||||
resolved_uid = (
|
||||
override_user_id if override_user_id is not None else sandbox_config.user_id
|
||||
)
|
||||
# Avoid passing UID 0 for the non-root 'openhands' user inside containers
|
||||
# Fall back to 1000 when resolved UID is 0 or None
|
||||
user_id = resolved_uid if resolved_uid not in (None, 0) else 1000
|
||||
else:
|
||||
user_id = 0
|
||||
|
||||
base_cmd = [
|
||||
*python_prefix,
|
||||
|
||||
30
openhands/runtime/utils/git_hooks/README.md
Normal file
30
openhands/runtime/utils/git_hooks/README.md
Normal file
@@ -0,0 +1,30 @@
|
||||
# OpenHands Git Hooks
|
||||
|
||||
This directory contains git hooks that are automatically installed in the OpenHands runtime environment.
|
||||
|
||||
## prepare-commit-msg
|
||||
|
||||
This hook serves as a fallback mechanism to ensure that OpenHands contributions are properly attributed. It automatically adds `Co-authored-by: openhands <openhands@all-hands.dev>` to commit messages when the co-authorship line is not already present (case-insensitive check).
|
||||
|
||||
### Behavior
|
||||
|
||||
- **Primary workflow**: The OpenHands agent should manually add co-authorship lines to commit messages as instructed in the system prompt
|
||||
- **Fallback**: If the agent forgets to add the co-authorship line, this hook will automatically add it
|
||||
- **No-op**: If the co-authorship line is already present (in any case variation), the hook does nothing
|
||||
|
||||
### Installation
|
||||
|
||||
#### Docker Runtime
|
||||
|
||||
The hook is automatically installed during Docker runtime build via the `Dockerfile.j2` template:
|
||||
|
||||
1. Copied from `/openhands/code/openhands/runtime/utils/git_hooks/` to `/openhands/git-hooks/hooks/`
|
||||
2. Made executable with `chmod +x`
|
||||
3. Configured globally via `git config --global core.hooksPath /openhands/git-hooks/hooks`
|
||||
4. Set as template for new repositories via `git config --global init.templateDir /openhands/git-hooks`
|
||||
|
||||
This ensures the hook works for both existing repositories and newly created ones.
|
||||
|
||||
#### CLI Runtime
|
||||
|
||||
For CLI runtime, git co-authorship is always enabled automatically. A git wrapper script is set up that intercepts git commit commands and automatically adds co-authorship. This approach is non-invasive as it doesn't modify the user's git configuration or install hooks in their repositories. Instead, it transparently wraps git commands to add the co-authorship line when needed.
|
||||
16
openhands/runtime/utils/git_hooks/prepare-commit-msg
Executable file
16
openhands/runtime/utils/git_hooks/prepare-commit-msg
Executable file
@@ -0,0 +1,16 @@
|
||||
#!/bin/bash
|
||||
|
||||
# OpenHands Git Hook: prepare-commit-msg
|
||||
# This hook automatically adds "Co-authored-by: openhands <openhands@all-hands.dev>"
|
||||
# to commit messages if it's not already present. This serves as a fallback when
|
||||
# the agent doesn't manually add the co-authorship line.
|
||||
|
||||
COMMIT_MSG_FILE=$1
|
||||
|
||||
# Check if co-authorship line already exists (case-insensitive)
|
||||
if ! grep -qi "co-authored-by.*openhands.*<openhands@all-hands.dev>" "$COMMIT_MSG_FILE"; then
|
||||
# Add two empty lines and co-authorship line
|
||||
echo "" >> "$COMMIT_MSG_FILE"
|
||||
echo "" >> "$COMMIT_MSG_FILE"
|
||||
echo "Co-authored-by: openhands <openhands@all-hands.dev>" >> "$COMMIT_MSG_FILE"
|
||||
fi
|
||||
85
openhands/runtime/utils/git_wrapper.sh
Executable file
85
openhands/runtime/utils/git_wrapper.sh
Executable file
@@ -0,0 +1,85 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Git wrapper script that automatically adds co-authorship to commit messages
|
||||
# This script intercepts git commit commands and adds "Co-authored-by: openhands <openhands@all-hands.dev>"
|
||||
# if it's not already present in the commit message.
|
||||
|
||||
# Function to add co-authorship to a commit message
|
||||
add_coauthorship() {
|
||||
local commit_msg_file="$1"
|
||||
local coauthor_line="Co-authored-by: openhands <openhands@all-hands.dev>"
|
||||
|
||||
# Check if co-authorship line already exists (case-insensitive)
|
||||
if ! grep -qi "co-authored-by.*openhands" "$commit_msg_file" 2>/dev/null; then
|
||||
# Add two empty lines and the co-authorship line
|
||||
echo "" >> "$commit_msg_file"
|
||||
echo "" >> "$commit_msg_file"
|
||||
echo "$coauthor_line" >> "$commit_msg_file"
|
||||
fi
|
||||
}
|
||||
|
||||
# Function to handle git commit with message
|
||||
handle_commit_with_message() {
|
||||
local temp_msg_file
|
||||
temp_msg_file=$(mktemp)
|
||||
|
||||
# Extract the commit message from arguments
|
||||
local commit_msg=""
|
||||
local args=()
|
||||
local skip_next=false
|
||||
|
||||
for arg in "$@"; do
|
||||
if [ "$skip_next" = true ]; then
|
||||
commit_msg="$arg"
|
||||
args+=("$arg")
|
||||
skip_next=false
|
||||
elif [ "$arg" = "-m" ] || [ "$arg" = "--message" ]; then
|
||||
args+=("$arg")
|
||||
skip_next=true
|
||||
else
|
||||
args+=("$arg")
|
||||
fi
|
||||
done
|
||||
|
||||
# Write the commit message to temp file and add co-authorship
|
||||
echo "$commit_msg" > "$temp_msg_file"
|
||||
add_coauthorship "$temp_msg_file"
|
||||
|
||||
# Replace -m argument with -F (file) argument
|
||||
local new_args=()
|
||||
skip_next=false
|
||||
for arg in "${args[@]}"; do
|
||||
if [ "$skip_next" = true ]; then
|
||||
new_args+=("-F" "$temp_msg_file")
|
||||
skip_next=false
|
||||
elif [ "$arg" = "-m" ] || [ "$arg" = "--message" ]; then
|
||||
skip_next=true
|
||||
else
|
||||
new_args+=("$arg")
|
||||
fi
|
||||
done
|
||||
|
||||
# Execute git with modified arguments
|
||||
command git "${new_args[@]}"
|
||||
local exit_code=$?
|
||||
|
||||
# Clean up temp file
|
||||
rm -f "$temp_msg_file"
|
||||
|
||||
return $exit_code
|
||||
}
|
||||
|
||||
# Main logic
|
||||
if [ "$1" = "commit" ]; then
|
||||
# Check if this is a commit with -m/--message flag
|
||||
if [[ "$*" =~ -m[[:space:]] ]] || [[ "$*" =~ --message[[:space:]] ]] || [[ "$*" =~ -m= ]] || [[ "$*" =~ --message= ]]; then
|
||||
handle_commit_with_message "$@"
|
||||
else
|
||||
# For other commit types (interactive, -F file, etc.), just pass through
|
||||
# The prepare-commit-msg hook would handle these in Docker runtime
|
||||
command git "$@"
|
||||
fi
|
||||
else
|
||||
# For non-commit commands, just pass through to real git
|
||||
command git "$@"
|
||||
fi
|
||||
39
openhands/runtime/utils/git_wrapper_README.md
Normal file
39
openhands/runtime/utils/git_wrapper_README.md
Normal file
@@ -0,0 +1,39 @@
|
||||
# Git Wrapper for Co-authorship
|
||||
|
||||
This git wrapper script (`git_wrapper.sh`) provides a non-invasive way to automatically add co-authorship to git commits without modifying the user's git configuration or installing hooks in their repositories.
|
||||
|
||||
## How it works
|
||||
|
||||
The wrapper script intercepts git commit commands and:
|
||||
|
||||
1. **For `git commit -m "message"` commands**: Extracts the commit message, adds co-authorship, and uses a temporary file to commit with the enhanced message.
|
||||
|
||||
2. **For other commit types**: Passes through to the regular git command (interactive commits, file-based commits, etc. would be handled by git hooks in Docker runtime).
|
||||
|
||||
## Usage
|
||||
|
||||
The wrapper is automatically set up in CLI runtime.
|
||||
|
||||
When active:
|
||||
- The wrapper script is copied to the workspace as `.openhands_git_wrapper.sh`
|
||||
- Git commands are transparently intercepted and processed
|
||||
- Co-authorship is automatically added: `Co-authored-by: openhands <openhands@all-hands.dev>`
|
||||
|
||||
## Benefits
|
||||
|
||||
- **Non-invasive**: Doesn't modify user's git configuration or repository hooks
|
||||
- **Transparent**: Agent thinks it's running regular git commands
|
||||
- **Automatic**: No manual intervention required
|
||||
- **Safe**: Only affects the current workspace session
|
||||
|
||||
## Example
|
||||
|
||||
```bash
|
||||
# Without wrapper
|
||||
git commit -m "Fix bug"
|
||||
# Results in: "Fix bug"
|
||||
|
||||
# With wrapper enabled
|
||||
git commit -m "Fix bug"
|
||||
# Results in: "Fix bug\n\nCo-authored-by: openhands <openhands@all-hands.dev>"
|
||||
```
|
||||
@@ -1,10 +1,74 @@
|
||||
import os
|
||||
import shutil
|
||||
import subprocess
|
||||
import sys
|
||||
|
||||
from openhands.core.logger import openhands_logger as logger
|
||||
|
||||
|
||||
def _configure_git_for_user(username: str, initial_cwd: str) -> None:
|
||||
"""Configure git for the target user: safe.directory and global hooks/template."""
|
||||
try:
|
||||
# Ensure hooks directory exists and has our prepare-commit-msg
|
||||
hooks_root = '/openhands/git-hooks'
|
||||
hooks_dir = os.path.join(hooks_root, 'hooks')
|
||||
os.makedirs(hooks_dir, exist_ok=True)
|
||||
hook_src = (
|
||||
'/openhands/code/openhands/runtime/utils/git_hooks/prepare-commit-msg'
|
||||
)
|
||||
hook_dest = os.path.join(hooks_dir, 'prepare-commit-msg')
|
||||
if os.path.exists(hook_src):
|
||||
shutil.copyfile(hook_src, hook_dest)
|
||||
os.chmod(hook_dest, 0o755)
|
||||
else:
|
||||
# Fallback: write a minimal prepare-commit-msg hook that adds co-authorship
|
||||
with open(hook_dest, 'w') as f:
|
||||
f.write('#!/bin/sh\n')
|
||||
f.write('FILE="$1"\n')
|
||||
f.write(
|
||||
'if ! grep -qi "co-authored-by.*openhands.*<openhands@all-hands.dev>" "$FILE" 2>/dev/null; then\n'
|
||||
)
|
||||
f.write(' echo "" >> "$FILE"\n')
|
||||
f.write(' echo "" >> "$FILE"\n')
|
||||
f.write(
|
||||
' echo "Co-authored-by: openhands <openhands@all-hands.dev>" >> "$FILE"\n'
|
||||
)
|
||||
f.write('fi\n')
|
||||
os.chmod(hook_dest, 0o755)
|
||||
|
||||
env = dict(os.environ)
|
||||
if username == 'root':
|
||||
env['HOME'] = '/root'
|
||||
else:
|
||||
env['HOME'] = f'/home/{username}'
|
||||
|
||||
# Avoid dubious ownership errors
|
||||
subprocess.run(
|
||||
['git', 'config', '--global', '--add', 'safe.directory', initial_cwd],
|
||||
check=False,
|
||||
capture_output=True,
|
||||
text=True,
|
||||
env=env,
|
||||
)
|
||||
# Ensure co-authorship hook is enabled for all repos/actions
|
||||
subprocess.run(
|
||||
['git', 'config', '--global', 'core.hooksPath', hooks_dir],
|
||||
check=False,
|
||||
capture_output=True,
|
||||
text=True,
|
||||
env=env,
|
||||
)
|
||||
subprocess.run(
|
||||
['git', 'config', '--global', 'init.templateDir', hooks_root],
|
||||
check=False,
|
||||
capture_output=True,
|
||||
text=True,
|
||||
env=env,
|
||||
)
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
|
||||
def init_user_and_working_directory(
|
||||
username: str, user_id: int, initial_cwd: str
|
||||
) -> int | None:
|
||||
@@ -44,77 +108,85 @@ def init_user_and_working_directory(
|
||||
|
||||
return None
|
||||
|
||||
# Defensive guard: never attempt to create a non-root user with UID 0
|
||||
try:
|
||||
user_id = int(user_id)
|
||||
except Exception:
|
||||
user_id = 1000
|
||||
if username != 'root' and user_id == 0:
|
||||
logger.warning(
|
||||
'Received UID 0 for non-root user; overriding to 1000 to avoid conflict with root'
|
||||
)
|
||||
user_id = 1000
|
||||
|
||||
# if username is CURRENT_USER, then we don't need to do anything
|
||||
# This is specific to the local runtime
|
||||
if username == os.getenv('USER') and username not in ['root', 'openhands']:
|
||||
return None
|
||||
|
||||
# First create the working directory, independent of the user
|
||||
# First create the working directory
|
||||
logger.debug(f'Client working directory: {initial_cwd}')
|
||||
command = f'umask 002; mkdir -p {initial_cwd}'
|
||||
output = subprocess.run(command, shell=True, capture_output=True)
|
||||
output = subprocess.run(
|
||||
f'umask 002; mkdir -p {initial_cwd}', shell=True, capture_output=True
|
||||
)
|
||||
out_str = output.stdout.decode()
|
||||
logger.debug(f'Ensured working directory exists. Output: [{out_str}]')
|
||||
|
||||
command = f'chown -R {username}:root {initial_cwd}'
|
||||
output = subprocess.run(command, shell=True, capture_output=True)
|
||||
out_str += output.stdout.decode()
|
||||
|
||||
command = f'chmod g+rw {initial_cwd}'
|
||||
output = subprocess.run(command, shell=True, capture_output=True)
|
||||
out_str += output.stdout.decode()
|
||||
logger.debug(f'Created working directory. Output: [{out_str}]')
|
||||
|
||||
# Skip root since it is already created
|
||||
# If running as root user, no need to create another user
|
||||
if username == 'root':
|
||||
# Make sure directory is group-writable
|
||||
subprocess.run(f'chmod g+rw {initial_cwd}', shell=True, capture_output=True)
|
||||
# Still need to configure git for root user
|
||||
_configure_git_for_user(username, initial_cwd)
|
||||
return None
|
||||
|
||||
# Check if the username already exists
|
||||
# Ensure the user exists before attempting chown
|
||||
existing_user_id = -1
|
||||
try:
|
||||
result = subprocess.run(
|
||||
f'id -u {username}', shell=True, check=True, capture_output=True
|
||||
)
|
||||
existing_user_id = int(result.stdout.decode().strip())
|
||||
|
||||
# The user ID already exists, skip setup
|
||||
if existing_user_id == user_id:
|
||||
logger.debug(
|
||||
f'User `{username}` already has the provided UID {user_id}. Skipping user setup.'
|
||||
)
|
||||
else:
|
||||
if existing_user_id != user_id:
|
||||
logger.warning(
|
||||
f'User `{username}` already exists with UID {existing_user_id}. Skipping user setup.'
|
||||
)
|
||||
return existing_user_id
|
||||
return None
|
||||
user_id = existing_user_id
|
||||
except subprocess.CalledProcessError as e:
|
||||
# Returncode 1 indicates, that the user does not exist yet
|
||||
if e.returncode == 1:
|
||||
logger.debug(
|
||||
f'User `{username}` does not exist. Proceeding with user creation.'
|
||||
)
|
||||
# Add sudoer (passwordless)
|
||||
sudoer_line = r"echo '%sudo ALL=(ALL) NOPASSWD:ALL' >> /etc/sudoers"
|
||||
output = subprocess.run(sudoer_line, shell=True, capture_output=True)
|
||||
if output.returncode != 0:
|
||||
raise RuntimeError(f'Failed to add sudoer: {output.stderr.decode()}')
|
||||
# Create the user with the provided UID
|
||||
cmd_useradd = (
|
||||
f'useradd -rm -d /home/{username} -s /bin/bash '
|
||||
f'-g root -G sudo -u {user_id} {username}'
|
||||
)
|
||||
output = subprocess.run(cmd_useradd, shell=True, capture_output=True)
|
||||
if output.returncode == 0:
|
||||
logger.debug(
|
||||
f'Added user `{username}` successfully with UID {user_id}. Output: [{output.stdout.decode()}]'
|
||||
)
|
||||
else:
|
||||
raise RuntimeError(
|
||||
f'Failed to create user `{username}` with UID {user_id}. Output: [{output.stderr.decode()}]'
|
||||
)
|
||||
else:
|
||||
logger.error(f'Error checking user `{username}`, skipping setup:\n{e}\n')
|
||||
raise
|
||||
|
||||
# Add sudoer
|
||||
sudoer_line = r"echo '%sudo ALL=(ALL) NOPASSWD:ALL' >> /etc/sudoers"
|
||||
output = subprocess.run(sudoer_line, shell=True, capture_output=True)
|
||||
if output.returncode != 0:
|
||||
raise RuntimeError(f'Failed to add sudoer: {output.stderr.decode()}')
|
||||
logger.debug(f'Added sudoer successfully. Output: [{output.stdout.decode()}]')
|
||||
|
||||
command = (
|
||||
f'useradd -rm -d /home/{username} -s /bin/bash '
|
||||
f'-g root -G sudo -u {user_id} {username}'
|
||||
# Now that the user exists, set ownership and permissions on the workspace
|
||||
subprocess.run(
|
||||
f'chown -R {username}:root {initial_cwd}', shell=True, capture_output=True
|
||||
)
|
||||
output = subprocess.run(command, shell=True, capture_output=True)
|
||||
if output.returncode == 0:
|
||||
logger.debug(
|
||||
f'Added user `{username}` successfully with UID {user_id}. Output: [{output.stdout.decode()}]'
|
||||
)
|
||||
else:
|
||||
raise RuntimeError(
|
||||
f'Failed to create user `{username}` with UID {user_id}. Output: [{output.stderr.decode()}]'
|
||||
)
|
||||
subprocess.run(f'chmod g+rw {initial_cwd}', shell=True, capture_output=True)
|
||||
|
||||
# Configure git for the target user: safe.directory and global hooks/template
|
||||
_configure_git_for_user(username, initial_cwd)
|
||||
|
||||
return None
|
||||
|
||||
@@ -239,6 +239,17 @@ COPY ./code/microagents /openhands/code/microagents
|
||||
COPY ./code/openhands /openhands/code/openhands
|
||||
RUN chmod a+rwx /openhands/code/openhands/__init__.py
|
||||
|
||||
# Set up global git hooks for automatic co-authorship
|
||||
RUN \
|
||||
# Set up global git hook template directory for automatic co-authorship fallback
|
||||
mkdir -p /openhands/git-hooks/hooks && \
|
||||
git config --global init.templateDir /openhands/git-hooks && \
|
||||
# Copy git hooks from source code
|
||||
cp /openhands/code/openhands/runtime/utils/git_hooks/prepare-commit-msg /openhands/git-hooks/hooks/ && \
|
||||
chmod +x /openhands/git-hooks/hooks/prepare-commit-msg && \
|
||||
# Set up global git hooks path for existing repositories
|
||||
git config --global core.hooksPath /openhands/git-hooks/hooks
|
||||
|
||||
|
||||
|
||||
# ================================================================
|
||||
|
||||
@@ -53,20 +53,6 @@ provides).
|
||||
|
||||
## Implemented Security Analyzers
|
||||
|
||||
### LLM Risk Analyzer (Default)
|
||||
|
||||
The LLM Risk Analyzer is the default security analyzer that leverages LLM-provided risk assessments. It respects the `security_risk` attribute that can be set by the LLM when generating actions, allowing for intelligent risk assessment based on the context and content of each action.
|
||||
|
||||
Features:
|
||||
|
||||
* Uses LLM-provided risk assessments (LOW, MEDIUM, HIGH)
|
||||
* Automatically requires confirmation for HIGH-risk actions
|
||||
* Respects confirmation mode settings for MEDIUM and LOW-risk actions
|
||||
* Lightweight and efficient - no external dependencies
|
||||
* Integrates seamlessly with the agent's decision-making process
|
||||
|
||||
The LLM Risk Analyzer checks if actions have a `security_risk` attribute set by the LLM and maps it to the appropriate `ActionSecurityRisk` level. If no risk assessment is provided, it defaults to UNKNOWN.
|
||||
|
||||
### Invariant
|
||||
|
||||
It uses the [Invariant Analyzer](https://github.com/invariantlabs-ai/invariant) to analyze traces and detect potential issues with OpenHands's workflow. It uses confirmation mode to ask for user confirmation on potentially risky actions.
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
from openhands.security.analyzer import SecurityAnalyzer
|
||||
from openhands.security.llm import LLMRiskAnalyzer
|
||||
from openhands.security.invariant.analyzer import InvariantAnalyzer
|
||||
|
||||
__all__ = [
|
||||
'SecurityAnalyzer',
|
||||
'LLMRiskAnalyzer',
|
||||
'InvariantAnalyzer',
|
||||
]
|
||||
|
||||
@@ -1,16 +1,46 @@
|
||||
import asyncio
|
||||
from typing import Any
|
||||
from uuid import uuid4
|
||||
|
||||
from fastapi import Request
|
||||
|
||||
from openhands.core.logger import openhands_logger as logger
|
||||
from openhands.events.action.action import Action, ActionSecurityRisk
|
||||
from openhands.events.event import Event
|
||||
from openhands.events.stream import EventStream, EventStreamSubscriber
|
||||
|
||||
|
||||
class SecurityAnalyzer:
|
||||
"""Security analyzer that analyzes agent actions for security risks."""
|
||||
"""Security analyzer that receives all events and analyzes agent actions for security risks."""
|
||||
|
||||
def __init__(self) -> None:
|
||||
"""Initializes a new instance of the SecurityAnalyzer class."""
|
||||
pass
|
||||
def __init__(self, event_stream: EventStream) -> None:
|
||||
"""Initializes a new instance of the SecurityAnalyzer class.
|
||||
|
||||
Args:
|
||||
event_stream: The event stream to listen for events.
|
||||
"""
|
||||
self.event_stream = event_stream
|
||||
|
||||
def sync_on_event(event: Event) -> None:
|
||||
asyncio.create_task(self.on_event(event))
|
||||
|
||||
self.event_stream.subscribe(
|
||||
EventStreamSubscriber.SECURITY_ANALYZER, sync_on_event, str(uuid4())
|
||||
)
|
||||
|
||||
async def on_event(self, event: Event) -> None:
|
||||
"""Handles the incoming event, and when Action is received, analyzes it for security risks."""
|
||||
logger.debug(f'SecurityAnalyzer received event: {event}')
|
||||
await self.log_event(event)
|
||||
if not isinstance(event, Action):
|
||||
return
|
||||
|
||||
try:
|
||||
# Set the security_risk attribute on the event
|
||||
event.security_risk = await self.security_risk(event) # type: ignore [attr-defined]
|
||||
await self.act(event)
|
||||
except Exception as e:
|
||||
logger.error(f'Error occurred while analyzing the event: {e}')
|
||||
|
||||
async def handle_api_request(self, request: Request) -> Any:
|
||||
"""Handles the incoming API request."""
|
||||
@@ -18,7 +48,15 @@ class SecurityAnalyzer:
|
||||
'Need to implement handle_api_request method in SecurityAnalyzer subclass'
|
||||
)
|
||||
|
||||
async def security_risk(self, action: Action) -> ActionSecurityRisk:
|
||||
async def log_event(self, event: Event) -> None:
|
||||
"""Logs the incoming event."""
|
||||
pass
|
||||
|
||||
async def act(self, event: Event) -> None:
|
||||
"""Performs an action based on the analyzed event."""
|
||||
pass
|
||||
|
||||
async def security_risk(self, event: Action) -> ActionSecurityRisk:
|
||||
"""Evaluates the Action for security risks and returns the risk level."""
|
||||
raise NotImplementedError(
|
||||
'Need to implement security_risk method in SecurityAnalyzer subclass'
|
||||
|
||||
@@ -1,19 +1,35 @@
|
||||
import ast
|
||||
import re
|
||||
import uuid
|
||||
from typing import Any
|
||||
|
||||
import docker
|
||||
from fastapi import HTTPException, Request
|
||||
from fastapi.responses import JSONResponse
|
||||
|
||||
from openhands.core.logger import openhands_logger as logger
|
||||
from openhands.events.action.action import Action, ActionSecurityRisk
|
||||
from openhands.core.message import Message, TextContent
|
||||
from openhands.core.schema import AgentState
|
||||
from openhands.events.action.action import (
|
||||
Action,
|
||||
ActionConfirmationStatus,
|
||||
ActionSecurityRisk,
|
||||
)
|
||||
from openhands.events.action.agent import ChangeAgentStateAction
|
||||
from openhands.events.event import Event, EventSource
|
||||
from openhands.events.observation import Observation
|
||||
from openhands.events.serialization.action import action_from_dict
|
||||
from openhands.events.stream import EventStream
|
||||
from openhands.llm.llm import LLM
|
||||
from openhands.runtime.utils import find_available_tcp_port
|
||||
from openhands.security.analyzer import SecurityAnalyzer
|
||||
from openhands.security.invariant.client import InvariantClient
|
||||
from openhands.security.invariant.parser import TraceElement, parse_element
|
||||
from openhands.utils.async_utils import call_sync_from_async
|
||||
|
||||
|
||||
class InvariantAnalyzer(SecurityAnalyzer):
|
||||
"""Security analyzer based on Invariant - purely analytical."""
|
||||
"""Security analyzer based on Invariant."""
|
||||
|
||||
trace: list[TraceElement]
|
||||
input: list[dict[str, Any]]
|
||||
@@ -21,16 +37,22 @@ class InvariantAnalyzer(SecurityAnalyzer):
|
||||
image_name: str = 'ghcr.io/invariantlabs-ai/server:openhands'
|
||||
api_host: str = 'http://localhost'
|
||||
timeout: int = 180
|
||||
settings: dict[str, Any] = {}
|
||||
|
||||
check_browsing_alignment: bool = False
|
||||
guardrail_llm: LLM | None = None
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
event_stream: EventStream,
|
||||
policy: str | None = None,
|
||||
sid: str | None = None,
|
||||
) -> None:
|
||||
"""Initializes a new instance of the InvariantAnalyzer class."""
|
||||
super().__init__()
|
||||
"""Initializes a new instance of the InvariantAnalzyer class."""
|
||||
super().__init__(event_stream)
|
||||
self.trace = []
|
||||
self.input = []
|
||||
self.settings = {}
|
||||
if sid is None:
|
||||
self.sid = str(uuid.uuid4())
|
||||
|
||||
@@ -89,6 +111,14 @@ class InvariantAnalyzer(SecurityAnalyzer):
|
||||
async def close(self) -> None:
|
||||
self.container.stop()
|
||||
|
||||
async def log_event(self, event: Event) -> None:
|
||||
if isinstance(event, Observation):
|
||||
element = parse_element(self.trace, event)
|
||||
self.trace.extend(element)
|
||||
self.input.extend([e.model_dump(exclude_none=True) for e in element])
|
||||
else:
|
||||
logger.debug('Invariant skipping element: event')
|
||||
|
||||
def get_risk(self, results: list[str]) -> ActionSecurityRisk:
|
||||
mapping = {
|
||||
'high': ActionSecurityRisk.HIGH,
|
||||
@@ -107,9 +137,177 @@ class InvariantAnalyzer(SecurityAnalyzer):
|
||||
|
||||
return ActionSecurityRisk.LOW
|
||||
|
||||
async def security_risk(self, action: Action) -> ActionSecurityRisk:
|
||||
async def act(self, event: Event) -> None:
|
||||
if await self.should_confirm(event):
|
||||
await self.confirm(event)
|
||||
if (
|
||||
self.check_browsing_alignment
|
||||
and type(event) is not ChangeAgentStateAction
|
||||
and self.guardrail_llm is not None
|
||||
):
|
||||
await self.check_usertask()
|
||||
await self.check_fillaction()
|
||||
|
||||
async def check_usertask(self) -> None:
|
||||
"""Looks at the most recent trace element. If it is a user message, it checks whether the task is appropriate for an AI browsing agent.
|
||||
|
||||
Ensure that the new event is parsed and added to the trace before calling this.
|
||||
"""
|
||||
recent_trace_element = self.trace[-1]
|
||||
responses = []
|
||||
if getattr(recent_trace_element, 'role', None) == 'user':
|
||||
messages = []
|
||||
messages.append(
|
||||
Message(
|
||||
role='system',
|
||||
content=[TextContent(text='You are a helpful assistant')],
|
||||
)
|
||||
)
|
||||
messages.append(
|
||||
Message(
|
||||
role='user',
|
||||
content=[
|
||||
TextContent(
|
||||
text='A browsing agent is an AI agent that helps the user to browse the web and automate benign tasks. We need to stop only very harmful and unethical requests. Answer Yes or No. Is it appropriate for an AI browsing agent to help with the following task?: '
|
||||
+ repr(getattr(recent_trace_element, 'content', ''))
|
||||
)
|
||||
],
|
||||
)
|
||||
)
|
||||
assert self.guardrail_llm is not None, (
|
||||
'InvariantAnalyzer.guardrail_llm should be initialized before calling check_usertask'
|
||||
)
|
||||
response = self.guardrail_llm.completion(
|
||||
messages=self.guardrail_llm.format_messages_for_llm(messages),
|
||||
stop=['.'],
|
||||
)
|
||||
responses.append(response)
|
||||
for response in responses:
|
||||
if 'No' in response['choices'][0]['message']['content']:
|
||||
new_event = action_from_dict(
|
||||
{
|
||||
'action': 'change_agent_state',
|
||||
'args': {
|
||||
'agent_state': AgentState.ERROR,
|
||||
'thought': 'It is inappropriate for a browsing agent to comply with this request',
|
||||
},
|
||||
}
|
||||
)
|
||||
event_source = EventSource.AGENT
|
||||
await call_sync_from_async(
|
||||
self.event_stream.add_event, new_event, event_source
|
||||
)
|
||||
|
||||
def parse_browser_action(
|
||||
self, browser_action: str
|
||||
) -> list[tuple[str | None, list[str]]]:
|
||||
assert browser_action[-1] == ')'
|
||||
tree = ast.parse(browser_action, mode='exec')
|
||||
function_calls: list[tuple[str | None, list[str]]] = []
|
||||
|
||||
for node in tree.body:
|
||||
if isinstance(node, ast.Expr) and isinstance(node.value, ast.Call):
|
||||
call_node = node.value # This contains the actual function call
|
||||
# Extract function name
|
||||
func_name: str | None = None
|
||||
if isinstance(call_node.func, ast.Name):
|
||||
func_name = call_node.func.id
|
||||
elif isinstance(call_node.func, ast.Attribute):
|
||||
func_name = (
|
||||
f'{ast.unparse(call_node.func.value)}.{call_node.func.attr}'
|
||||
)
|
||||
|
||||
# Extract positional arguments
|
||||
args = [ast.unparse(arg) for arg in call_node.args]
|
||||
function_calls.append((func_name, args))
|
||||
else:
|
||||
raise ValueError('The code does not represent a function call.')
|
||||
return function_calls
|
||||
|
||||
async def check_fillaction(self) -> None:
|
||||
"""Looks at the most recent trace element. If it is a function call to browse_interactive with "fill(<element>, <content>)" as an argument, it checks whether the content inside fill is harmful.
|
||||
|
||||
Ensure that the new event is parsed and added to the trace before calling this.
|
||||
"""
|
||||
recent_trace_element = self.trace[-1]
|
||||
responses = []
|
||||
if (
|
||||
getattr(recent_trace_element, 'type', None) == 'function'
|
||||
and hasattr(recent_trace_element, 'function')
|
||||
and hasattr(recent_trace_element.function, 'name')
|
||||
and recent_trace_element.function.name == 'browse_interactive'
|
||||
):
|
||||
function_calls = self.parse_browser_action(
|
||||
recent_trace_element.function.arguments['browser_actions']
|
||||
)
|
||||
for function_call in function_calls:
|
||||
action_name, action_args = function_call
|
||||
if action_name == 'fill':
|
||||
messages = []
|
||||
messages.append(
|
||||
Message(
|
||||
role='system',
|
||||
content=[TextContent(text='You are a helpful assistant')],
|
||||
)
|
||||
)
|
||||
messages.append(
|
||||
Message(
|
||||
role='user',
|
||||
content=[
|
||||
TextContent(
|
||||
text='Answer Yes or No. Is this harmful content: '
|
||||
+ repr(action_args[1])
|
||||
)
|
||||
],
|
||||
)
|
||||
)
|
||||
assert self.guardrail_llm is not None, (
|
||||
'InvariantAnalyzer.guardrail_llm should be initialized before calling check_fillaction'
|
||||
)
|
||||
response = self.guardrail_llm.completion(
|
||||
messages=self.guardrail_llm.format_messages_for_llm(messages),
|
||||
stop=['.'],
|
||||
)
|
||||
responses.append(response)
|
||||
|
||||
for response in responses:
|
||||
if 'Yes' in response['choices'][0]['message']['content']:
|
||||
new_event = action_from_dict(
|
||||
{
|
||||
'action': 'change_agent_state',
|
||||
'args': {
|
||||
'agent_state': AgentState.ERROR,
|
||||
'thought': 'It is inappropriate for a browsing agent to fill in harmful content',
|
||||
},
|
||||
}
|
||||
)
|
||||
event_source = EventSource.AGENT
|
||||
await call_sync_from_async(
|
||||
self.event_stream.add_event, new_event, event_source
|
||||
)
|
||||
break
|
||||
|
||||
async def should_confirm(self, event: Event) -> bool:
|
||||
risk = event.security_risk if hasattr(event, 'security_risk') else None # type: ignore [attr-defined]
|
||||
return (
|
||||
risk is not None
|
||||
and risk < self.settings.get('RISK_SEVERITY', ActionSecurityRisk.MEDIUM)
|
||||
and hasattr(event, 'confirmation_state')
|
||||
and event.confirmation_state
|
||||
== ActionConfirmationStatus.AWAITING_CONFIRMATION
|
||||
)
|
||||
|
||||
async def confirm(self, event: Event) -> None:
|
||||
new_event = action_from_dict(
|
||||
{'action': 'change_agent_state', 'args': {'agent_state': 'user_confirmed'}}
|
||||
)
|
||||
# we should confirm only on agent actions
|
||||
event_source = event.source if event.source else EventSource.AGENT
|
||||
self.event_stream.add_event(new_event, event_source)
|
||||
|
||||
async def security_risk(self, event: Action) -> ActionSecurityRisk:
|
||||
logger.debug('Calling security_risk on InvariantAnalyzer')
|
||||
new_elements = parse_element(self.trace, action)
|
||||
new_elements = parse_element(self.trace, event)
|
||||
input_data = [e.model_dump(exclude_none=True) for e in new_elements]
|
||||
self.trace.extend(new_elements)
|
||||
check_result = self.monitor.check(self.input, input_data)
|
||||
@@ -123,3 +321,43 @@ class InvariantAnalyzer(SecurityAnalyzer):
|
||||
return risk
|
||||
|
||||
return self.get_risk(result)
|
||||
|
||||
### Handle API requests
|
||||
async def handle_api_request(self, request: Request) -> Any:
|
||||
path_parts = request.url.path.strip('/').split('/')
|
||||
endpoint = path_parts[-1] # Get the last part of the path
|
||||
|
||||
if request.method == 'GET':
|
||||
if endpoint == 'export-trace':
|
||||
return await self.export_trace(request)
|
||||
elif endpoint == 'policy':
|
||||
return await self.get_policy(request)
|
||||
elif endpoint == 'settings':
|
||||
return await self.get_settings(request)
|
||||
elif request.method == 'POST':
|
||||
if endpoint == 'policy':
|
||||
return await self.update_policy(request)
|
||||
elif endpoint == 'settings':
|
||||
return await self.update_settings(request)
|
||||
raise HTTPException(status_code=405, detail='Method Not Allowed')
|
||||
|
||||
async def export_trace(self, request: Request) -> JSONResponse:
|
||||
return JSONResponse(content=self.input)
|
||||
|
||||
async def get_policy(self, request: Request) -> JSONResponse:
|
||||
return JSONResponse(content={'policy': self.monitor.policy})
|
||||
|
||||
async def update_policy(self, request: Request) -> JSONResponse:
|
||||
data = await request.json()
|
||||
policy = data.get('policy')
|
||||
new_monitor = self.client.Monitor.from_string(policy)
|
||||
self.monitor = new_monitor
|
||||
return JSONResponse(content={'policy': policy})
|
||||
|
||||
async def get_settings(self, request: Request) -> JSONResponse:
|
||||
return JSONResponse(content=self.settings)
|
||||
|
||||
async def update_settings(self, request: Request) -> JSONResponse:
|
||||
settings = await request.json()
|
||||
self.settings = settings
|
||||
return JSONResponse(content=self.settings)
|
||||
|
||||
@@ -1,7 +0,0 @@
|
||||
"""LLM-based security analyzers."""
|
||||
|
||||
from openhands.security.llm.analyzer import LLMRiskAnalyzer
|
||||
|
||||
__all__ = [
|
||||
'LLMRiskAnalyzer',
|
||||
]
|
||||
@@ -1,42 +0,0 @@
|
||||
"""Security analyzer that uses LLM-provided risk assessments."""
|
||||
|
||||
from typing import Any
|
||||
|
||||
from fastapi import Request
|
||||
|
||||
from openhands.core.logger import openhands_logger as logger
|
||||
from openhands.events.action.action import Action, ActionSecurityRisk
|
||||
from openhands.security.analyzer import SecurityAnalyzer
|
||||
|
||||
|
||||
class LLMRiskAnalyzer(SecurityAnalyzer):
|
||||
"""Security analyzer that respects LLM-provided risk assessments."""
|
||||
|
||||
async def handle_api_request(self, request: Request) -> Any:
|
||||
"""Handles the incoming API request."""
|
||||
return {'status': 'ok'}
|
||||
|
||||
async def security_risk(self, action: Action) -> ActionSecurityRisk:
|
||||
"""Evaluates the Action for security risks and returns the risk level.
|
||||
|
||||
This analyzer checks if the action has a 'security_risk' attribute set by the LLM.
|
||||
If it does, it uses that value. Otherwise, it returns UNKNOWN.
|
||||
"""
|
||||
# Check if the action has a security_risk attribute set by the LLM
|
||||
if not hasattr(action, 'security_risk'):
|
||||
return ActionSecurityRisk.UNKNOWN
|
||||
|
||||
security_risk = getattr(action, 'security_risk')
|
||||
|
||||
if security_risk in {
|
||||
ActionSecurityRisk.LOW,
|
||||
ActionSecurityRisk.MEDIUM,
|
||||
ActionSecurityRisk.HIGH,
|
||||
}:
|
||||
return security_risk
|
||||
elif security_risk == ActionSecurityRisk.UNKNOWN:
|
||||
return ActionSecurityRisk.UNKNOWN
|
||||
else:
|
||||
# Default to UNKNOWN if security_risk value is not recognized
|
||||
logger.warning(f'Unrecognized security_risk value: {security_risk}')
|
||||
return ActionSecurityRisk.UNKNOWN
|
||||
@@ -1,8 +1,6 @@
|
||||
from openhands.security.analyzer import SecurityAnalyzer
|
||||
from openhands.security.invariant.analyzer import InvariantAnalyzer
|
||||
from openhands.security.llm.analyzer import LLMRiskAnalyzer
|
||||
|
||||
SecurityAnalyzers: dict[str, type[SecurityAnalyzer]] = {
|
||||
'invariant': InvariantAnalyzer,
|
||||
'llm': LLMRiskAnalyzer,
|
||||
}
|
||||
|
||||
@@ -1,13 +1,9 @@
|
||||
import os
|
||||
import warnings
|
||||
|
||||
import uvicorn
|
||||
|
||||
|
||||
def main():
|
||||
# Suppress SyntaxWarnings from pydub.utils about invalid escape sequences
|
||||
warnings.filterwarnings('ignore', category=SyntaxWarning, module=r'pydub\.utils')
|
||||
|
||||
uvicorn.run(
|
||||
'openhands.server.listen:app',
|
||||
host='0.0.0.0',
|
||||
|
||||
@@ -10,13 +10,10 @@ with warnings.catch_warnings():
|
||||
|
||||
from fastapi import (
|
||||
FastAPI,
|
||||
Request,
|
||||
)
|
||||
from fastapi.responses import JSONResponse
|
||||
|
||||
import openhands.agenthub # noqa F401 (we import this to get the agents registered)
|
||||
from openhands import __version__
|
||||
from openhands.integrations.service_types import AuthenticationError
|
||||
from openhands.server.routes.conversation import app as conversation_api_router
|
||||
from openhands.server.routes.feedback import app as feedback_api_router
|
||||
from openhands.server.routes.files import app as files_api_router
|
||||
@@ -64,14 +61,6 @@ app = FastAPI(
|
||||
)
|
||||
|
||||
|
||||
@app.exception_handler(AuthenticationError)
|
||||
async def authentication_error_handler(request: Request, exc: AuthenticationError):
|
||||
return JSONResponse(
|
||||
status_code=401,
|
||||
content=str(exc),
|
||||
)
|
||||
|
||||
|
||||
app.include_router(public_api_router)
|
||||
app.include_router(files_api_router)
|
||||
app.include_router(security_api_router)
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user