-
Notifications
You must be signed in to change notification settings - Fork 5.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add port mappings support #5577
Merged
Merged
Changes from 49 commits
Commits
Show all changes
61 commits
Select commit
Hold shift + click to select a range
e41ca72
Add port mappings support to sandbox config
openhands-agent c7d3225
Add UI for served app
amanape 4bc7721
Merge branch 'main' into add-port-mappings
amanape 291c496
Create new property
amanape 9cee2c3
Merge branch 'main' into add-port-mappings
amanape 42876f3
Multi port support and extend base and remote runtimes
amanape a84f7e6
Merge and resolve
amanape 395527d
Adjustment and changes
amanape e68a658
Small edit
amanape 68215db
Add runtime-specific port mapping instructions to agent prompt
openhands-agent c03c1ad
Fix template modification to use file reading instead of non-existent…
openhands-agent 468b61c
Move prompt extension logic to PromptManager class
openhands-agent 7b4628b
Some fixes and improvements
amanape 80d92ae
Merge and resolve
amanape d3018c2
Improve jinja template handling
amanape 4b9a65a
Fix comments
amanape 0a23fd9
Mostly renaming
amanape 65a419f
Merge and resolve
amanape b1af1db
Address prompt handling
amanape 75ca147
Merge branch 'main' into add-port-mappings
amanape 0e700d1
Merge and resolve
amanape 0cef034
Address comments
amanape eac950a
Update instructions
amanape 301231b
Merge, resolve, and fix error
amanape c55fa09
Fix error
amanape c5b7382
merge and resolve
amanape a0d2efd
Rename
amanape 30f0b49
Merge branch 'main' into add-port-mappings
tofarr 6a3306e
Lint fix
tofarr 7aa527d
merge
amanape 020df3c
Merge branch 'main' into add-port-mappings
rbren ac973fa
make prompting clearer
rbren ff07644
handle errors
rbren 0130246
fix llm err handling
rbren 6ac55ca
Merge branch 'rb/fix-errs' into add-port-mappings
rbren d9814cf
json for dict configs
rbren a2ae2d9
fix prompt
rbren 37c671a
dynamic port mapping
rbren 8f67d2d
fix ports
rbren 108bce0
fix port initialization
rbren 6ebdf16
remove offline label
rbren 6d078f8
fix up iframe
rbren 3c6d5f8
change web_hosts api
rbren 7401215
fix frontend for new api
rbren 5122f83
delint
rbren aaa0b22
delint
rbren 33cbc1e
change to work_hosts
rbren 182071d
remove log
rbren 6bf627d
fix vscode
rbren 5ba5766
Merge branch 'main' into add-port-mappings
amanape 282f5b4
Add refresh button and small active indicator
amanape c98ceca
Allow editing path and create redirect button
amanape c951c36
Merge branch 'main' into add-port-mappings
amanape ea7691b
Allow to edit full URL
amanape cfcac55
Resolve merge conflicts with main
openhands-agent a99fb0e
Apply pre-commit fixes
openhands-agent c2ab895
Merge branch 'main' into add-port-mappings
rbren 5d51a35
change app port ranges
rbren 99489d7
Merge branch 'main' into add-port-mappings
rbren 1854883
Merge branch 'main' into add-port-mappings
amanape ae92c8f
Update openhands/runtime/impl/docker/docker_runtime.py
rbren File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import { FaExternalLinkAlt } from "react-icons/fa"; | ||
import { useActiveHost } from "#/hooks/query/use-active-host"; | ||
|
||
export function ServedAppLabel() { | ||
const { activeHost } = useActiveHost(); | ||
|
||
function openAppInNewTab() { | ||
if (!activeHost) return; | ||
window.open(activeHost, "_blank"); | ||
} | ||
|
||
return ( | ||
<div className="flex items-center justify-between w-full"> | ||
<div className="flex items-center gap-2">App</div> | ||
{activeHost && ( | ||
<span onClick={openAppInNewTab} className="flex items-center gap-2"> | ||
<div className="flex items-center gap-1"> | ||
<FaExternalLinkAlt fill="#a3a3a3" /> | ||
</div> | ||
</span> | ||
)} | ||
</div> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import { useQueries, useQuery } from "@tanstack/react-query"; | ||
import axios from "axios"; | ||
import React from "react"; | ||
import { useSelector } from "react-redux"; | ||
import { openHands } from "#/api/open-hands-axios"; | ||
import { RUNTIME_INACTIVE_STATES } from "#/types/agent-state"; | ||
import { RootState } from "#/store"; | ||
import { useConversation } from "#/context/conversation-context"; | ||
|
||
export const useActiveHost = () => { | ||
const { curAgentState } = useSelector((state: RootState) => state.agent); | ||
const [activeHost, setActiveHost] = React.useState<string | null>(null); | ||
|
||
const { conversationId } = useConversation(); | ||
|
||
const { data } = useQuery({ | ||
queryKey: [conversationId, "hosts"], | ||
queryFn: async () => { | ||
const response = await openHands.get<{ hosts: string[] }>( | ||
`/api/conversations/${conversationId}/web-hosts`, | ||
); | ||
return { hosts: Object.keys(response.data.hosts) }; | ||
}, | ||
enabled: !RUNTIME_INACTIVE_STATES.includes(curAgentState), | ||
initialData: { hosts: [] }, | ||
}); | ||
|
||
const apps = useQueries({ | ||
queries: data.hosts.map((host) => ({ | ||
queryKey: [conversationId, "hosts", host], | ||
queryFn: async () => { | ||
try { | ||
await axios.get(host); | ||
return host; | ||
} catch (e) { | ||
return ""; | ||
} | ||
}, | ||
refetchInterval: 3000, | ||
})), | ||
}); | ||
|
||
const appsData = apps.map((app) => app.data); | ||
|
||
React.useEffect(() => { | ||
const successfulApp = appsData.find((app) => app); | ||
setActiveHost(successfulApp || ""); | ||
}, [appsData]); | ||
|
||
return { activeHost }; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { useActiveHost } from "#/hooks/query/use-active-host"; | ||
|
||
function ServedApp() { | ||
const { activeHost } = useActiveHost(); | ||
|
||
if (!activeHost) { | ||
return ( | ||
<div className="flex items-center justify-center w-full h-full p-10"> | ||
<span className="text-neutral-400 font-bold"> | ||
If you tell OpenHands to start a web server, the app will appear here. | ||
</span> | ||
</div> | ||
); | ||
} | ||
|
||
return ( | ||
<iframe title="Served App" src={activeHost} className="w-full h-full" /> | ||
); | ||
} | ||
|
||
export default ServedApp; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,9 +3,21 @@ You are OpenHands agent, a helpful AI assistant that can interact with a compute | |
* If user provides a path, you should NOT assume it's relative to the current working directory. Instead, you should explore the file system to find the file before working on it. | ||
* When configuring git credentials, use "openhands" as the user.name and "[email protected]" as the user.email by default, unless explicitly instructed otherwise. | ||
* The assistant MUST NOT include comments in the code unless they are necessary to describe non-obvious behavior. | ||
{{ runtime_info }} | ||
</IMPORTANT> | ||
{% if repo_instructions %} | ||
{% if repo_instructions -%} | ||
<REPOSITORY_INSTRUCTIONS> | ||
{{ repo_instructions }} | ||
</REPOSITORY_INSTRUCTIONS> | ||
{% endif %} | ||
{% if runtime_info and runtime_info.available_hosts -%} | ||
<RUNTIME_INFORMATION> | ||
The user has access to the following hosts for accessing a web application, | ||
each of which has a corresponding port: | ||
{% for host, port in runtime_info.available_hosts.items() -%} | ||
* {{ host }} (port {{ port }}) | ||
{% endfor %} | ||
When starting a web server, use the corresponding ports. You should also | ||
set any options to allow iframes and CORS requests. | ||
</RUNTIME_INFORMATION> | ||
{% endif %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems this would return two identical ports?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
huh...it doesn't, but now that you say it I don't know why....
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's grabbing random ports, so there's a 1-in-10k chance of a collision. Will fix