(config, options = {})
| 788 | * @returns {Record<string, string>} Environment variables for agent-server |
| 789 | */ |
| 790 | export function buildAgentServerEnv(config, options = {}) { |
| 791 | const { vscodeBasePath = null, env = process.env } = options; |
| 792 | const conversationRuntimeEnv = Object.fromEntries( |
| 793 | [ |
| 794 | "OH_CONVERSATION_RUNTIME", |
| 795 | "OH_CONVERSATION_IMAGE", |
| 796 | "OH_CONVERSATION_CONTAINER_MEMORY", |
| 797 | "OH_CONVERSATION_CONTAINER_CPUS", |
| 798 | "OH_CONVERSATION_CONTAINER_PIDS_LIMIT", |
| 799 | "OH_CONVERSATION_CONTAINER_STARTUP_TIMEOUT", |
| 800 | ] |
| 801 | .filter((key) => env[key] !== undefined) |
| 802 | .map((key) => [key, env[key]]), |
| 803 | ); |
| 804 | return { |
| 805 | ...buildAgentServerTelemetryEnv(env), |
| 806 | ...conversationRuntimeEnv, |
| 807 | // Force Python to use UTF-8 for all file I/O and streams. |
| 808 | // |
| 809 | // On Windows, Python defaults to the system ANSI codepage (e.g. cp1252). |
| 810 | // The agent-server writes conversation metadata JSON that can contain |
| 811 | // emoji (e.g. ✅ U+2705) which cp1252 cannot encode, producing: |
| 812 | // UnicodeEncodeError: 'charmap' codec can't encode character '\u2705' |
| 813 | // Setting PYTHONUTF8=1 enables Python's UTF-8 mode (PEP 540) for the |
| 814 | // entire agent-server process, matching the behaviour on Linux/macOS |
| 815 | // where the locale is already UTF-8. |
| 816 | // This is a no-op on Linux/macOS where the locale is already UTF-8. |
| 817 | PYTHONUTF8: "1", |
| 818 | TMUX_TMPDIR: config.tmuxTmpDir, |
| 819 | // Parent of stateDir (= ~/.openhands) so settings/secrets match Docker. |
| 820 | OH_PERSISTENCE_DIR: path.dirname(config.stateDir), |
| 821 | OH_CONVERSATIONS_PATH: config.conversationsPath, |
| 822 | OH_BASH_EVENTS_DIR: config.bashEventsDir, |
| 823 | OH_VSCODE_PORT: String(config.vscodePort), |
| 824 | // Serve the editor under a path prefix on the canvas origin rather than on |
| 825 | // its own published port. agent-server passes this to openvscode-server as |
| 826 | // --server-base-path and includes it in the URL from /api/vscode/url, which |
| 827 | // matches the ingress route the caller registers for the same prefix. |
| 828 | // |
| 829 | // Omitted unless the caller opts in — see the note on this function. |
| 830 | ...(vscodeBasePath ? { OH_VSCODE_BASE_PATH: vscodeBasePath } : {}), |
| 831 | OH_SECRET_KEY: config.secretKey, |
| 832 | // Use OH_SESSION_API_KEYS_0 for agent-server V1 config format |
| 833 | OH_SESSION_API_KEYS_0: config.sessionApiKey, |
| 834 | // Alias for the agent-server's own URL. The agent-server itself sets |
| 835 | // OH_INTERNAL_SERVER_URL at startup, but downstream consumers (the |
| 836 | // OpenHands SDK boilerplate emitted by automation prompt/plugin |
| 837 | // presets) read AGENT_SERVER_URL — the canonical SDK name. Mirror it |
| 838 | // here so automation runs work without each tarball having to know |
| 839 | // about the OH_-prefixed variant. |
| 840 | // |
| 841 | // We deliberately do NOT set a SESSION_API_KEY alias: the SDK's |
| 842 | // sanitized_env() would strip it from bash subprocesses anyway, and |
| 843 | // a follow-up change to the automation preset reads |
| 844 | // OH_SESSION_API_KEYS_0 directly (which is already in env). |
| 845 | AGENT_SERVER_URL: config.backendBaseUrl, |
| 846 | // Let the agent-server resolve canvas_ui_tool when old persisted metadata |
| 847 | // requests that compatibility module during startup. |
no test coverage detected