Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
82 changes: 6 additions & 76 deletions extensions/metaclaw-openclaw/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -450,84 +450,14 @@ function runVenvSetupThenMaybeStart(api: OpenClawPluginApi, full: MetaClawPlugin

const installedVersion = versionCheck.status === 0 ? versionCheck.stdout.trim() : null;

if (installedVersion) {
// Check if PyPI has a newer version — quick pip index check
const indexCheck = spawnSync(venvPy, [
"-m", "pip", "index", "versions", full.pipInstallSpec.replace(/\[.*\]$/, ""),
"--index-url", "https://pypi.org/simple/",
"--extra-index-url", "https://pypi.tuna.tsinghua.edu.cn/simple/",
], { encoding: "utf8", timeout: 30_000 });

let latestVersion: string | null = null;
if (indexCheck.status === 0 && indexCheck.stdout) {
// Output format: "aiming-metaclaw (0.4.0)\nAvailable versions: ..."
const m = indexCheck.stdout.match(/\(([^)]+)\)/);
if (m) latestVersion = m[1];
}

if (!latestVersion || latestVersion === installedVersion) {
// Already up-to-date — skip pip, still run post-install steps
api.logger.debug?.(`metaclaw-openclaw: already up-to-date (${installedVersion})`);
installMetaclawWrapper(api, full.venvPath);
if (full.autoStartMetaclaw) {
trySpawnMetaclaw(api, full, venvPy);
}
return;
}

api.logger.info(
`metaclaw-openclaw: upgrade available (${installedVersion} → ${latestVersion}), updating…`,
);
// Already installed — run post-install steps
api.logger.debug?.(`metaclaw-openclaw: metaclaw already installed`);
installMetaclawWrapper(api, full.venvPath);
if (full.autoStartMetaclaw) {
trySpawnMetaclaw(api, full, venvPy);
}
return;

// Install or upgrade via pip
const args = [
"-m",
"pip",
"install",
"--upgrade",
"--quiet",
"--index-url", "https://pypi.org/simple/",
"--extra-index-url", "https://pypi.tuna.tsinghua.edu.cn/simple/",
...full.pipExtraArgs,
full.pipInstallSpec,
];
api.logger.info(installedVersion ? "metaclaw-openclaw: upgrading…" : "metaclaw-openclaw: installing…");

const pip = spawn(venvPy, args, {
shell: process.platform === "win32",
stdio: ["ignore", "pipe", "pipe"],
env: { ...process.env, PYTHONUNBUFFERED: "1" },
});

let errTail = "";
pip.stderr?.on("data", (chunk: Buffer) => {
errTail = (errTail + chunk.toString()).slice(-2000);
});
pip.stdout?.on("data", () => {});

pip.on("error", (err) => {
api.logger.warn(
`metaclaw-openclaw: could not run pip in venv (${String(err)}). Install Python 3.11+ and python3-venv, or install MetaClaw manually (see extension README).`,
);
if (full.autoStartMetaclaw) {
trySpawnMetaclaw(api, full, venvPy);
}
});

pip.on("close", (code) => {
if (code === 0) {
api.logger.info("metaclaw-openclaw: installed");
installMetaclawWrapper(api, full.venvPath);
} else {
api.logger.warn(
`metaclaw-openclaw: pip install exited ${code}. stderr tail:\n${errTail}`,
);
}
if (full.autoStartMetaclaw) {
setTimeout(() => trySpawnMetaclaw(api, full, venvPy), 800);
}
});
}

// ─── WeChat ──────────────────────────────────────────────────────────
Expand Down
13 changes: 13 additions & 0 deletions metaclaw/launcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,19 @@ def _setup_evolver_env(self, cfg):
def _configure_openclaw(self, cfg):
"""Auto-configure OpenClaw to use the MetaClaw proxy."""
model_id = cfg.llm_model_id or cfg.served_model_name or "metaclaw-model"

# Skip if already configured — avoid unnecessary gateway restarts
try:
cur = subprocess.run(
["openclaw", "config", "get", "agents.defaults.model.primary"],
capture_output=True, text=True, timeout=10,
)
if cur.returncode == 0 and f"metaclaw/{model_id}" in cur.stdout:
logger.info("[Launcher] openclaw already configured for metaclaw — skipping auto-config")
return
except Exception:
pass

provider_json = json.dumps({
"api": "openai-completions",
"baseUrl": f"http://127.0.0.1:{cfg.proxy_port}/v1",
Expand Down