import { spawn } from "node:child_process"; import { randomUUID } from "node:crypto"; import fs from "node:fs/promises"; import os from "node:os"; import path from "node:path";
type RunResult = {
code: number | null;
signal: string | null;
stdout: string;
stderr: string;
};
function pickAnthropicEnv(): { type: "oauth" | "api"; value: string } | null { const oauth = process.env.ANTHROPIC_OAUTH_TOKEN?.trim(); if (oauth) { return { type: "oauth", value: oauth };
} const api = process.env.ANTHROPIC_API_KEY?.trim(); if (api) { return { type: "api", value: api };
} returnnull;
}
console.log("== Run 1: create tool history (primary only)"); const toolPrompt = "Use the exec tool to create a file named zai-fallback-tool.txt with the content tool-ok. " + "Then use the read tool to display the file contents. Reply with just the file contents."; const run1 = await runCommand( "run1",
["openclaw", "agent", "--local", "--session-id", sessionId, "--message", toolPrompt],
envValidAnthropic,
); if (run1.code !== 0) {
process.exit(run1.code ?? 1);
}
const sessionFile = path.join(stateDir, "agents", "main", "sessions", `${sessionId}.jsonl`); const transcript = await fs.readFile(sessionFile, "utf8").catch(() => ""); if (!transcript.includes('"toolResult"')) {
console.warn("Warning: no toolResult entries detected in session history.");
}
console.log("== Run 2: force auth failover to Z.AI"); const followupPrompt = "What is the content of zai-fallback-tool.txt? Reply with just the contents."; const run2 = await runCommand( "run2",
["openclaw", "agent", "--local", "--session-id", sessionId, "--message", followupPrompt],
envInvalidAnthropic,
);
if (run2.code === 0) {
console.log("PASS: fallback succeeded.");
process.exit(0);
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.