π OpenHands: AI-Driven Development
fix: advertise host services to Docker conversations (#17518)
Graham Neubig15e686078812
diff --git a/.pr/17518-before-after.png b/.pr/17518-before-after.pngnew file mode 100644index 0000000000..36627bb749Binary files /dev/null and b/.pr/17518-before-after.png differdiff --git a/__tests__/scripts/dev-with-automation.test.ts b/__tests__/scripts/dev-with-automation.test.tsindex 4b2840fd3d..d8b5cc93ee 100644--- a/__tests__/scripts/dev-with-automation.test.ts+++ b/__tests__/scripts/dev-with-automation.test.ts@@ -18,6 +18,7 @@ import {buildAgentServerAutomationEnv,buildAutomationCommand,buildAutomationTelemetryEnv,+ buildAutomationRuntimeServicesInfo,buildConfig,buildRouteArgs,buildViteBackendEnv,@@ -46,6 +47,48 @@ const repoRoot = path.resolve("../..",);+type RuntimeServicesInfo = {+ services: Record<string, { url_from_agent: string }>;+};++describe("buildAutomationRuntimeServicesInfo", () => {+ const config = {+ mode: "agent-canvas",+ agentServerPort: 18000,+ ingressPort: 8000,+ vitePort: 3001,+ autoBackendPort: 18001,+ launchFrontend: true,+ launchAutomation: true,+ };++ it("advertises host services through the Docker host gateway", () => {+ const info = buildAutomationRuntimeServicesInfo(config, {+ OH_CONVERSATION_RUNTIME: "docker",+ }) as RuntimeServicesInfo;+ expect(info.services.agent_server.url_from_agent).toBe(+ "http://localhost:18000",+ );+ expect(info.services.ingress.url_from_agent).toBe(+ "http://host.docker.internal:8000",+ );+ expect(info.services.automation.url_from_agent).toBe(+ "http://host.docker.internal:8000",+ );+ });++ it("keeps host services on localhost for local conversations", () => {+ const info = buildAutomationRuntimeServicesInfo(+ config,+ {},+ ) as RuntimeServicesInfo;+ expect(info.services.ingress.url_from_agent).toBe("http://localhost:8000");+ expect(info.services.automation.url_from_agent).toBe(+ "http://localhost:18001",+ );+ });+});+describe("buildAutomationCommand", () => {it("uses released PyPI version by default", () => {const cmd = buildAutomationCommand({});diff --git a/scripts/dev-with-automation.mjs b/scripts/dev-with-automation.mjsindex ff89676c2c..717dd540a6 100644--- a/scripts/dev-with-automation.mjs+++ b/scripts/dev-with-automation.mjs@@ -1132,10 +1132,12 @@ function startIngress(config) {* frontend connected to the backend can populate the agent's* `<RUNTIME_SERVICES>` system-prompt block.*/-export function buildAutomationRuntimeServicesInfo(config) {+export function buildAutomationRuntimeServicesInfo(config, env = process.env) {+ const dockerConversationRuntime = env.OH_CONVERSATION_RUNTIME === "docker";+ const agentHostAlias = config.agentHostAlias ?? getAgentHostAlias(env);return buildRuntimeServicesInfo({mode: config.mode ?? "dev:automation",- agentHostAlias: config.agentHostAlias ?? "localhost",+ agentHostAlias,agentServerPort: config.agentServerPort,ingressPort: config.ingressPort,frontendPort: config.launchFrontend ? config.vitePort : undefined,@@ -1144,11 +1146,19 @@ export function buildAutomationRuntimeServicesInfo(config) {// description shown to the agent matches reality.frontendKind: config.frontendKind ?? "vite",automation: config.launchAutomation- ? { port: config.autoBackendPort }+ ? dockerConversationRuntime+ ? { url: `http://${agentHostAlias}:${config.ingressPort}` }+ : { port: config.autoBackendPort }: undefined,});}+export function getAgentHostAlias(env = process.env) {+ return env.OH_CONVERSATION_RUNTIME === "docker"+ ? "host.docker.internal"+ : "localhost";+}+function startVite(config) {logService("vite", `Starting on port ${config.vitePort}...`, c.magenta);@@ -1402,7 +1412,7 @@ async function main(options = {}) {buildStaticFrontend,staticDir: staticDirOverride,// Hostname the agent uses to reach services running on the host.- agentHostAlias = "localhost",+ agentHostAlias = getAgentHostAlias(),// Human-readable label for the dev mode, surfaced in the agent's// <RUNTIME_SERVICES> system-prompt block.mode = "dev:automation",