MCPcopy Create free account
hub / github.com/OpenHands/OpenHands / buildRuntimeServicesInfo

Function buildRuntimeServicesInfo

scripts/runtime-services-info.mjs:60–149  ·  view source on GitHub ↗
(options)

Source from the content-addressed store, hash-verified

58 * @returns {object} A JSON-serializable runtime services info object.
59 */
60export function buildRuntimeServicesInfo(options) {
61 const {
62 mode,
63 agentHostAlias = "localhost",
64 agentServerPort,
65 agentServerUrl,
66 ingressPort,
67 // Accept legacy `vitePort` for one release so external callers keep working.
68 vitePort,
69 frontendPort = vitePort,
70 frontendKind = "vite",
71 automation,
72 } = options;
73
74 // Prefer an explicit URL (containers reach the agent-server over a specific
75 // host/scheme), else derive it from the port. From the agent's POV the
76 // agent-server it's *inside* is on the loopback host, regardless of where
77 // the host machine is.
78 const agentServerUrlResolved =
79 agentServerUrl ??
80 (agentServerPort != null ? `http://localhost:${agentServerPort}` : null);
81 if (!agentServerUrlResolved) {
82 // Without this the URL becomes `http://localhost:undefined` and ends up
83 // verbatim in the agent's system prompt, which is worse than failing fast.
84 throw new Error(
85 "buildRuntimeServicesInfo: agentServerPort or agentServerUrl is required " +
86 "(otherwise the agent_server URL would be `http://localhost:undefined`).",
87 );
88 }
89
90 const services = {
91 agent_server: {
92 description:
93 "The OpenHands Agent Server this agent is running inside. " +
94 "Tool calls (terminal, file_editor, browser, etc.) execute here.",
95 url_from_agent: agentServerUrlResolved,
96 },
97 };
98
99 if (ingressPort !== undefined) {
100 services.ingress = {
101 description:
102 "Unified entry point. Routes /api/automation/* to the automation " +
103 "backend, /api/* and /sockets to the agent-server, and /* to the " +
104 "frontend.",
105 url_from_agent: `http://${agentHostAlias}:${ingressPort}`,
106 };
107 }
108
109 if (frontendPort !== undefined) {
110 services.frontend = {
111 kind: frontendKind,
112 description:
113 frontendKind === "static"
114 ? "Static-file server hosting the agent-canvas production build."
115 : "Vite dev server hosting the agent-canvas frontend.",
116 url_from_agent: `http://${agentHostAlias}:${frontendPort}`,
117 };

Callers 5

mainFunction · 0.90
dev-safe.test.tsFile · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected