(config, options = {})
| 1007 | * @returns {Record<string, string>} Environment variables for agent-server |
| 1008 | */ |
| 1009 | export function buildAgentServerEnv(config, options = {}) { |
| 1010 | const { vscodeBasePath = null, env = process.env, verbose = false } = options; |
| 1011 | const conversationRuntimeEnv = Object.fromEntries( |
| 1012 | [ |
| 1013 | "OH_CONVERSATION_RUNTIME", |
| 1014 | "OH_CONVERSATION_RUNTIME_SELECTABLE", |
| 1015 | "OH_CONVERSATION_IMAGE", |
| 1016 | "OH_CONVERSATION_IMAGE_HAS_BROWSER", |
| 1017 | "OH_CONVERSATION_CONTAINER_MEMORY", |
| 1018 | "OH_CONVERSATION_CONTAINER_CPUS", |
| 1019 | "OH_CONVERSATION_CONTAINER_PIDS_LIMIT", |
| 1020 | "OH_CONVERSATION_CONTAINER_STARTUP_TIMEOUT", |
| 1021 | ] |
| 1022 | .filter((key) => env[key] !== undefined) |
| 1023 | .map((key) => [key, env[key]]), |
| 1024 | ); |
| 1025 | return { |
| 1026 | ...buildAgentServerTelemetryEnv(env), |
| 1027 | ...buildBackendLogEnv({ verbose, env }), |
| 1028 | ...conversationRuntimeEnv, |
| 1029 | ...(env.VITE_ENABLE_BROWSER_TOOLS === "false" |
| 1030 | ? { OH_ENABLE_BROWSER: env.OH_ENABLE_BROWSER || "false" } |
| 1031 | : {}), |
| 1032 | // Force Python to use UTF-8 for all file I/O and streams. |
| 1033 | // |
| 1034 | // On Windows, Python defaults to the system ANSI codepage (e.g. cp1252). |
| 1035 | // The agent-server writes conversation metadata JSON that can contain |
| 1036 | // emoji (e.g. ✅ U+2705) which cp1252 cannot encode, producing: |
| 1037 | // UnicodeEncodeError: 'charmap' codec can't encode character '\u2705' |
| 1038 | // Setting PYTHONUTF8=1 enables Python's UTF-8 mode (PEP 540) for the |
| 1039 | // entire agent-server process, matching the behaviour on Linux/macOS |
| 1040 | // where the locale is already UTF-8. |
| 1041 | // This is a no-op on Linux/macOS where the locale is already UTF-8. |
| 1042 | PYTHONUTF8: "1", |
| 1043 | TMUX_TMPDIR: config.tmuxTmpDir, |
| 1044 | // Parent of stateDir (= ~/.openhands) so settings/secrets match Docker. |
| 1045 | OH_PERSISTENCE_DIR: path.dirname(config.stateDir), |
| 1046 | OH_CONVERSATIONS_PATH: config.conversationsPath, |
| 1047 | OH_BASH_EVENTS_DIR: config.bashEventsDir, |
| 1048 | OH_VSCODE_PORT: String(config.vscodePort), |
| 1049 | // Serve the editor under a path prefix on the canvas origin rather than on |
| 1050 | // its own published port. agent-server passes this to openvscode-server as |
| 1051 | // --server-base-path and includes it in the URL from /api/vscode/url, which |
| 1052 | // matches the ingress route the caller registers for the same prefix. |
| 1053 | // |
| 1054 | // Omitted unless the caller opts in — see the note on this function. |
| 1055 | ...(vscodeBasePath ? { OH_VSCODE_BASE_PATH: vscodeBasePath } : {}), |
| 1056 | OH_SECRET_KEY: config.secretKey, |
| 1057 | // Use OH_SESSION_API_KEYS_0 for agent-server V1 config format |
| 1058 | OH_SESSION_API_KEYS_0: config.sessionApiKey, |
| 1059 | // Alias for the agent-server's own URL. The agent-server itself sets |
| 1060 | // OH_INTERNAL_SERVER_URL at startup, but downstream consumers (the |
| 1061 | // OpenHands SDK boilerplate emitted by automation prompt/plugin |
| 1062 | // presets) read AGENT_SERVER_URL — the canonical SDK name. Mirror it |
| 1063 | // here so automation runs work without each tarball having to know |
| 1064 | // about the OH_-prefixed variant. |
| 1065 | // |
| 1066 | // We deliberately do NOT set a SESSION_API_KEY alias: the SDK's |
no test coverage detected