Skip to content

Commit

Permalink
fix up iframe
Browse files Browse the repository at this point in the history
  • Loading branch information
rbren committed Jan 1, 2025
1 parent 6ebdf16 commit 6d078f8
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 25 deletions.
14 changes: 7 additions & 7 deletions frontend/src/components/layout/served-app-label.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,22 @@ import { useActiveHost } from "#/hooks/query/use-active-host";
export function ServedAppLabel() {
const { activeHost } = useActiveHost();

function openAppInNewTab() {
window.open(activeHost, "_blank");
}

return (
<div className="flex items-center justify-between w-full">
<div className="flex items-center gap-2">App</div>
{activeHost && (
<a
href={activeHost}
target="_blank"
rel="noreferrer"
<span

Check failure on line 15 in frontend/src/components/layout/served-app-label.tsx

View workflow job for this annotation

GitHub Actions / Lint frontend

Replace `⏎··········onClick={openAppInNewTab}⏎··········className="flex·items-center·gap-2"⏎········` with `·onClick={openAppInNewTab}·className="flex·items-center·gap-2"`
onClick={openAppInNewTab}
className="flex items-center gap-2"
>
<span className="text-green-500">Online</span>
<div className="flex items-center gap-1">
<FaExternalLinkAlt fill="#a3a3a3" />
<code className="text-xs">{activeHost.split(":").pop()}</code>
</div>
</a>
</span>
)}
</div>
);
Expand Down
31 changes: 17 additions & 14 deletions frontend/src/hooks/query/use-active-host.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,25 +26,28 @@ export const useActiveHost = () => {
});

const apps = useQueries({
queries: data.hosts.map((port) => ({
queryKey: [conversationId, "hosts", port],
queryFn: async () => axios.get(port),
queries: data.hosts.map((host) => ({
queryKey: [conversationId, "hosts", host],
queryFn: async () => {
console.log('querying host', host);

Check warning on line 32 in frontend/src/hooks/query/use-active-host.ts

View workflow job for this annotation

GitHub Actions / Lint frontend

Unexpected console statement

Check failure on line 32 in frontend/src/hooks/query/use-active-host.ts

View workflow job for this annotation

GitHub Actions / Lint frontend

Replace `'querying·host'` with `"querying·host"`
try {
await axios.get(host);
return host;
} catch (e) {
return '';

Check failure on line 37 in frontend/src/hooks/query/use-active-host.ts

View workflow job for this annotation

GitHub Actions / Lint frontend

Replace `''` with `""`
}
},
refetchInterval: 3000,
})),
});

const success = apps.map((app) => app.isSuccess);

React.useEffect(() => {
const successfulApp = apps.find((app) => app.isSuccess);
if (successfulApp) {
const index = apps.indexOf(successfulApp);
const port = data.hosts[index];
setActiveHost(port);
} else {
setActiveHost(null);
}
}, [success, data]);
console.log('apps', apps);

Check warning on line 45 in frontend/src/hooks/query/use-active-host.ts

View workflow job for this annotation

GitHub Actions / Lint frontend

Unexpected console statement

Check failure on line 45 in frontend/src/hooks/query/use-active-host.ts

View workflow job for this annotation

GitHub Actions / Lint frontend

Replace `'apps'` with `"apps"`
const successfulApp = apps.find((app) => app.data);
console.log('successfulApp', successfulApp);

Check warning on line 47 in frontend/src/hooks/query/use-active-host.ts

View workflow job for this annotation

GitHub Actions / Lint frontend

Unexpected console statement

Check failure on line 47 in frontend/src/hooks/query/use-active-host.ts

View workflow job for this annotation

GitHub Actions / Lint frontend

Replace `'successfulApp'` with `"successfulApp"`
// Here's the change - use empty string as fallback instead of null
setActiveHost(successfulApp?.data || '');

Check failure on line 49 in frontend/src/hooks/query/use-active-host.ts

View workflow job for this annotation

GitHub Actions / Lint frontend

Replace `''` with `""`
}, [apps]);

Check failure on line 50 in frontend/src/hooks/query/use-active-host.ts

View workflow job for this annotation

GitHub Actions / Lint frontend

The result of useQueries is not referentially stable, so don't pass it directly into the dependencies array of useEffect. Instead, destructure the return value of useQueries and pass the destructured values into the dependency array of useEffect

return { activeHost };
};
6 changes: 3 additions & 3 deletions frontend/src/routes/app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ function ServedApp() {

if (!activeHost) {
return (
<div className="flex items-center justify-center w-full h-full">
<span className="text-4xl text-neutral-400 font-bold">
Nothing to see here.
<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>
);
Expand Down
3 changes: 2 additions & 1 deletion openhands/agenthub/codeact_agent/prompts/system_prompt.j2
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ each of which has a corresponding port:
{% for host in runtime_info.available_hosts -%}
* {{ host }}
{% endfor %}
When starting a web server, use the corresponding ports.
When starting a web server, use the corresponding ports. You should also
set any options to allow iframes and CORS requests.
</RUNTIME_INFORMATION>
{% endif %}

0 comments on commit 6d078f8

Please sign in to comment.