(env = process.env)
| 502 | * @returns {{ command: string, args: string[], source: string }} |
| 503 | */ |
| 504 | export function buildAgentServerCommand(env = process.env) { |
| 505 | const localPath = env.OH_AGENT_SERVER_LOCAL_PATH; |
| 506 | const gitRef = env.OH_AGENT_SERVER_GIT_REF; |
| 507 | const version = env.OH_AGENT_SERVER_VERSION; |
| 508 | |
| 509 | const uvxArgs = buildUvxPythonArgs(env); |
| 510 | let source = ""; |
| 511 | |
| 512 | if (localPath) { |
| 513 | if (!path.isAbsolute(localPath)) { |
| 514 | throw new Error( |
| 515 | `OH_AGENT_SERVER_LOCAL_PATH must be an absolute path, got: ${localPath}`, |
| 516 | ); |
| 517 | } |
| 518 | uvxArgs.push( |
| 519 | "--reinstall", |
| 520 | "--from", |
| 521 | path.join(localPath, "openhands-agent-server"), |
| 522 | "--with-editable", |
| 523 | path.join(localPath, "openhands-sdk"), |
| 524 | "--with-editable", |
| 525 | path.join(localPath, "openhands-tools"), |
| 526 | "--with-editable", |
| 527 | path.join(localPath, "openhands-workspace"), |
| 528 | "--with", |
| 529 | AGENT_SERVER_POSTHOG_CONSTRAINT, |
| 530 | "agent-server", |
| 531 | ); |
| 532 | source = `local (${localPath})`; |
| 533 | } else if (gitRef) { |
| 534 | // Use git ref with subdirectory syntax for uv workspace monorepo. |
| 535 | // The software-agent-sdk repo has packages in subdirectories: |
| 536 | // openhands-agent-server/, openhands-sdk/, openhands-tools/, openhands-workspace/ |
| 537 | // All four must come from the same ref so inter-package APIs stay in sync. |
| 538 | // |
| 539 | // --reinstall is required because the git branch may carry the same version |
| 540 | // string as the current PyPI release (e.g. both "1.26.0"). Without it, uv |
| 541 | // silently reuses the cached PyPI wheels and the git ref is never actually |
| 542 | // used, even though it was explicitly requested. |
| 543 | const baseGitUrl = `git+${AGENT_SERVER_GIT_REPO}@${gitRef}`; |
| 544 | uvxArgs.push( |
| 545 | "--reinstall", |
| 546 | "--from", |
| 547 | `${baseGitUrl}#subdirectory=openhands-agent-server`, |
| 548 | "--with", |
| 549 | `${baseGitUrl}#subdirectory=openhands-sdk`, |
| 550 | "--with", |
| 551 | `${baseGitUrl}#subdirectory=openhands-tools`, |
| 552 | "--with", |
| 553 | `${baseGitUrl}#subdirectory=openhands-workspace`, |
| 554 | "--with", |
| 555 | AGENT_SERVER_POSTHOG_CONSTRAINT, |
| 556 | "agent-server", |
| 557 | ); |
| 558 | source = `git (${gitRef})`; |
| 559 | } else if (version) { |
| 560 | // Use specific PyPI version: uvx --from openhands-agent-server==version agent-server |
| 561 | // The package name differs from the executable name, so we need --from syntax |
no test coverage detected