mirror of
http://192.168.0.88:13333/lywsvip/openclaw-zero-token.git
synced 2026-05-08 00:02:20 +08:00
Major upgrade from e26988a38 to upstream v2026.3.28 (f9b107928).
Key changes:
- Upstream src/, ui/, extensions/ (89 bundled extensions)
- Zero-token web providers preserved in src/zero-token/
- AskOnce plugin restored and registered as CLI command
- Added missing packages: @anthropic-ai/vertex-sdk, @modelcontextprotocol/sdk
- Fixed tsconfig rootDir, skipLibCheck for plugin-sdk DTS build
- Added askonce to bundled plugin metadata and package.json exports
- Fixed AskOnce CLI command registration (missing commands metadata)
- Restored AskOnce adapter imports (correct 5-level relative paths)
- Removed stale migration artifacts from root directory
59 lines
1.7 KiB
TypeScript
59 lines
1.7 KiB
TypeScript
import type { Command } from "commander";
|
|
import { hasFlag } from "../argv.js";
|
|
|
|
const jsonModeSymbol = Symbol("openclaw.cli.jsonMode");
|
|
|
|
type JsonMode = "output" | "parse-only";
|
|
type JsonModeCommand = Command & {
|
|
[jsonModeSymbol]?: JsonMode;
|
|
};
|
|
|
|
function commandDefinesJsonOption(command: Command): boolean {
|
|
return command.options.some((option) => option.long === "--json");
|
|
}
|
|
|
|
function getDeclaredCommandJsonMode(command: Command): JsonMode | null {
|
|
for (let current: Command | null = command; current; current = current.parent ?? null) {
|
|
const metadata = (current as JsonModeCommand)[jsonModeSymbol];
|
|
if (metadata) {
|
|
return metadata;
|
|
}
|
|
if (commandDefinesJsonOption(current)) {
|
|
return "output";
|
|
}
|
|
}
|
|
return null;
|
|
}
|
|
|
|
function commandSelectedJsonFlag(command: Command, argv: string[]): boolean {
|
|
const commandWithGlobals = command as Command & {
|
|
optsWithGlobals?: <T extends Record<string, unknown>>() => T;
|
|
};
|
|
if (typeof commandWithGlobals.optsWithGlobals === "function") {
|
|
const resolved = commandWithGlobals.optsWithGlobals<Record<string, unknown>>().json;
|
|
if (resolved === true) {
|
|
return true;
|
|
}
|
|
}
|
|
return hasFlag(argv, "--json");
|
|
}
|
|
|
|
export function setCommandJsonMode(command: Command, mode: JsonMode): Command {
|
|
(command as JsonModeCommand)[jsonModeSymbol] = mode;
|
|
return command;
|
|
}
|
|
|
|
export function getCommandJsonMode(
|
|
command: Command,
|
|
argv: string[] = process.argv,
|
|
): JsonMode | null {
|
|
if (!commandSelectedJsonFlag(command, argv)) {
|
|
return null;
|
|
}
|
|
return getDeclaredCommandJsonMode(command);
|
|
}
|
|
|
|
export function isCommandJsonOutputMode(command: Command, argv: string[] = process.argv): boolean {
|
|
return getCommandJsonMode(command, argv) === "output";
|
|
}
|