Skip to content

Commit aa3c44e

Browse files
committed
style: apply vp check --fix formatting
1 parent 3ac3bba commit aa3c44e

9 files changed

Lines changed: 68 additions & 250 deletions

File tree

packages/commands/src/commands/config/agent/index.ts

Lines changed: 9 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,7 @@ import {
1010
import { emitResult, emitBare } from "bailian-cli-runtime";
1111
import { AGENTS, VALID_AGENT_NAMES, type WriteParams } from "./writers.ts";
1212
import { decodeTokenPlanKey } from "./decode-key.ts";
13-
import {
14-
resolveRegionBaseUrl,
15-
findLatestBackup,
16-
restoreLatestBackup,
17-
} from "./writers/utils.ts";
13+
import { resolveRegionBaseUrl, findLatestBackup, restoreLatestBackup } from "./writers/utils.ts";
1814

1915
const FLAGS = {
2016
agent: {
@@ -54,8 +50,7 @@ const FLAGS = {
5450
contextWindow: {
5551
type: "number",
5652
valueHint: "<tokens>",
57-
description:
58-
"OpenClaw only: model context window in tokens (default: 256000)",
53+
description: "OpenClaw only: model context window in tokens (default: 256000)",
5954
},
6055
wireApi: {
6156
type: "string",
@@ -85,27 +80,17 @@ export default defineCommand({
8580
],
8681
validate(flags) {
8782
if (flags.restore) {
88-
const writeFlags = [
89-
flags.baseUrl,
90-
flags.region,
91-
flags.apiKey,
92-
flags.key,
93-
flags.model,
94-
];
83+
const writeFlags = [flags.baseUrl, flags.region, flags.apiKey, flags.key, flags.model];
9584
if (writeFlags.some((value) => value !== undefined)) {
9685
return "--restore cannot be combined with --base-url/--region/--api-key/--key/--model";
9786
}
9887
return undefined;
9988
}
10089
if (!flags.model) return "--model is required";
101-
if (!flags.baseUrl && !flags.region)
102-
return "one of --base-url or --region is required";
103-
if (flags.baseUrl && flags.region)
104-
return "--base-url and --region are mutually exclusive";
105-
if (!flags.apiKey && !flags.key)
106-
return "one of --api-key or --key is required";
107-
if (flags.apiKey && flags.key)
108-
return "--api-key and --key are mutually exclusive";
90+
if (!flags.baseUrl && !flags.region) return "one of --base-url or --region is required";
91+
if (flags.baseUrl && flags.region) return "--base-url and --region are mutually exclusive";
92+
if (!flags.apiKey && !flags.key) return "one of --api-key or --key is required";
93+
if (flags.apiKey && flags.key) return "--api-key and --key are mutually exclusive";
10994
return undefined;
11095
},
11196
async run(ctx) {
@@ -146,8 +131,7 @@ export default defineCommand({
146131
if (!settings.quiet) {
147132
emitBare(`${agentDef.label} config restored from backup.`);
148133
for (const result of results) {
149-
if (result.backupPath)
150-
emitBare(` Restored: ${result.path} <- ${result.backupPath}`);
134+
if (result.backupPath) emitBare(` Restored: ${result.path} <- ${result.backupPath}`);
151135
else emitBare(` Skipped (no backup): ${result.path}`);
152136
}
153137
}
@@ -158,9 +142,7 @@ export default defineCommand({
158142
const model = flags.model!;
159143
// --region is a Token Plan convenience: convert it into a base URL and use
160144
// it exactly as --base-url would be.
161-
const baseUrl = flags.region
162-
? resolveRegionBaseUrl(flags.region)
163-
: flags.baseUrl!;
145+
const baseUrl = flags.region ? resolveRegionBaseUrl(flags.region) : flags.baseUrl!;
164146
// --key carries the web console's obfuscated form; decode it up front so
165147
// even --dry-run validates the token.
166148
const apiKey = flags.key ? decodeTokenPlanKey(flags.key) : flags.apiKey!;

packages/commands/src/commands/config/agent/writers/claude-code.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,7 @@ import {
99
} from "./utils.ts";
1010

1111
/** Fill a tier/default model env only when the user has not set it yet. */
12-
function setModelEnvIfAbsent(
13-
env: Record<string, string>,
14-
key: string,
15-
model: string,
16-
): void {
12+
function setModelEnvIfAbsent(env: Record<string, string>, key: string, model: string): void {
1713
const current = env[key];
1814
if (current === undefined || current.trim() === "") {
1915
env[key] = model;

packages/commands/src/commands/config/agent/writers/codex.ts

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,12 @@ import { homedir } from "os";
22
import { join } from "path";
33
import { existsSync, readFileSync } from "fs";
44
import { parse as parseToml, stringify as stringifyToml } from "smol-toml";
5-
import {
6-
backup,
7-
readJson,
8-
writeJsonAtomic,
9-
writeTextAtomic,
10-
type AgentDef,
11-
} from "./utils.ts";
5+
import { backup, readJson, writeJsonAtomic, writeTextAtomic, type AgentDef } from "./utils.ts";
126

137
const PROVIDER_KEY = "bailian-cli";
148

159
function configPaths(): string[] {
16-
return [
17-
join(homedir(), ".codex", "config.toml"),
18-
join(homedir(), ".codex", "auth.json"),
19-
];
10+
return [join(homedir(), ".codex", "config.toml"), join(homedir(), ".codex", "auth.json")];
2011
}
2112

2213
export default {
@@ -32,10 +23,7 @@ export default {
3223
let config: Record<string, unknown> = {};
3324
if (existsSync(configPath)) {
3425
try {
35-
config = parseToml(readFileSync(configPath, "utf-8")) as Record<
36-
string,
37-
unknown
38-
>;
26+
config = parseToml(readFileSync(configPath, "utf-8")) as Record<string, unknown>;
3927
} catch {
4028
config = {};
4129
}

packages/commands/src/commands/config/agent/writers/hermes.ts

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,7 @@ import { homedir } from "os";
22
import { join } from "path";
33
import { existsSync, readFileSync } from "fs";
44
import yaml from "yaml";
5-
import {
6-
backup,
7-
writeTextAtomic,
8-
isAnthropicEndpoint,
9-
type AgentDef,
10-
} from "./utils.ts";
5+
import { backup, writeTextAtomic, isAnthropicEndpoint, type AgentDef } from "./utils.ts";
116

127
function configPaths(): string[] {
138
return [join(homedir(), ".hermes", "config.yaml")];
@@ -24,8 +19,7 @@ export default {
2419
let config: Record<string, unknown> = {};
2520
if (existsSync(configPath)) {
2621
try {
27-
config = (yaml.parse(readFileSync(configPath, "utf-8")) ??
28-
{}) as Record<string, unknown>;
22+
config = (yaml.parse(readFileSync(configPath, "utf-8")) ?? {}) as Record<string, unknown>;
2923
} catch {
3024
config = {};
3125
}

packages/commands/src/commands/config/agent/writers/openclaw.ts

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,6 @@
11
import { homedir } from "os";
22
import { join } from "path";
3-
import {
4-
backup,
5-
readJson,
6-
writeJsonAtomic,
7-
isAnthropicEndpoint,
8-
type AgentDef,
9-
} from "./utils.ts";
3+
import { backup, readJson, writeJsonAtomic, isAnthropicEndpoint, type AgentDef } from "./utils.ts";
104

115
// Safe default when --context-window is not given: most Model Studio models
126
// offer ≥256K context; users can raise it per model via the flag.
@@ -22,9 +16,7 @@ function readPrimary(defaults: Record<string, unknown>): string | undefined {
2216
const model = defaults.model;
2317
if (!model || typeof model !== "object") return undefined;
2418
const primary = (model as Record<string, unknown>).primary;
25-
return typeof primary === "string" && primary.trim() !== ""
26-
? primary.trim()
27-
: undefined;
19+
return typeof primary === "string" && primary.trim() !== "" ? primary.trim() : undefined;
2820
}
2921

3022
export default {
@@ -43,9 +35,7 @@ export default {
4335
const models = (config.models ?? {}) as Record<string, unknown>;
4436
models.mode = "merge";
4537
const providers = (models.providers ?? {}) as Record<string, unknown>;
46-
const api = isAnthropicEndpoint(baseUrl)
47-
? "anthropic-messages"
48-
: "openai-completions";
38+
const api = isAnthropicEndpoint(baseUrl) ? "anthropic-messages" : "openai-completions";
4939
providers[PROVIDER_ID] = {
5040
baseUrl,
5141
apiKey,

packages/commands/src/commands/config/agent/writers/opencode.ts

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,6 @@
11
import { homedir } from "os";
22
import { join } from "path";
3-
import {
4-
backup,
5-
readJsonc,
6-
writeJsonAtomic,
7-
isAnthropicEndpoint,
8-
type AgentDef,
9-
} from "./utils.ts";
3+
import { backup, readJsonc, writeJsonAtomic, isAnthropicEndpoint, type AgentDef } from "./utils.ts";
104

115
function configPaths(): string[] {
126
return [join(homedir(), ".config", "opencode", "opencode.json")];
@@ -25,9 +19,7 @@ export default {
2519
if (!config.$schema) config.$schema = "https://opencode.ai/config.json";
2620

2721
const provider = (config.provider ?? {}) as Record<string, unknown>;
28-
const npm = isAnthropicEndpoint(baseUrl)
29-
? "@ai-sdk/anthropic"
30-
: "@ai-sdk/openai-compatible";
22+
const npm = isAnthropicEndpoint(baseUrl) ? "@ai-sdk/anthropic" : "@ai-sdk/openai-compatible";
3123
provider["bailian-cli"] = {
3224
npm,
3325
name: "Alibaba Cloud Model Studio",

packages/commands/src/commands/config/agent/writers/qwen-code.ts

Lines changed: 6 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,6 @@
11
import { homedir } from "os";
22
import { join } from "path";
3-
import {
4-
backup,
5-
readJson,
6-
writeJsonAtomic,
7-
isAnthropicEndpoint,
8-
type AgentDef,
9-
} from "./utils.ts";
3+
import { backup, readJson, writeJsonAtomic, isAnthropicEndpoint, type AgentDef } from "./utils.ts";
104

115
const ENV_KEY = "DASHSCOPE_API_KEY";
126

@@ -77,23 +71,15 @@ export default {
7771
string,
7872
Array<Record<string, unknown>>
7973
>;
80-
const entries = (providers[protocol] ?? []) as Array<
81-
Record<string, unknown>
82-
>;
83-
const owned = entries.find(
84-
(entry) => isBailianCliEntry(entry) && entry.id === model,
85-
);
86-
const conflicting = entries.find(
87-
(entry) => !isBailianCliEntry(entry) && entry.id === model,
88-
);
74+
const entries = (providers[protocol] ?? []) as Array<Record<string, unknown>>;
75+
const owned = entries.find((entry) => isBailianCliEntry(entry) && entry.id === model);
76+
const conflicting = entries.find((entry) => !isBailianCliEntry(entry) && entry.id === model);
8977

9078
if (owned) {
9179
owned.baseUrl = baseUrl;
9280
owned.envKey = ENV_KEY;
93-
const currentName =
94-
typeof owned.name === "string" ? owned.name.trim() : "";
95-
if (!currentName || currentName === "bailian-cli")
96-
owned.name = displayName(model);
81+
const currentName = typeof owned.name === "string" ? owned.name.trim() : "";
82+
if (!currentName || currentName === "bailian-cli") owned.name = displayName(model);
9783
} else if (conflicting) {
9884
const existingName =
9985
typeof conflicting.name === "string" && conflicting.name.length > 0

packages/commands/src/commands/config/agent/writers/utils.ts

Lines changed: 6 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -72,11 +72,7 @@ export function stripJsonc(text: string): string {
7272
}
7373
if (char === "/" && next === "*") {
7474
index += 2;
75-
while (
76-
index < text.length &&
77-
!(text[index] === "*" && text[index + 1] === "/")
78-
)
79-
index += 1;
75+
while (index < text.length && !(text[index] === "*" && text[index + 1] === "/")) index += 1;
8076
index += 2;
8177
continue;
8278
}
@@ -106,11 +102,7 @@ export function stripJsonc(text: string): string {
106102
if (char === '"') inString = true;
107103
if (char === ",") {
108104
let lookahead = index + 1;
109-
while (
110-
lookahead < uncommented.length &&
111-
/\s/.test(uncommented[lookahead])
112-
)
113-
lookahead += 1;
105+
while (lookahead < uncommented.length && /\s/.test(uncommented[lookahead])) lookahead += 1;
114106
if (uncommented[lookahead] === "}" || uncommented[lookahead] === "]") {
115107
index += 1;
116108
continue;
@@ -136,10 +128,7 @@ export function readJson(path: string): Record<string, unknown> {
136128
export function readJsonc(path: string): Record<string, unknown> {
137129
if (!existsSync(path)) return {};
138130
try {
139-
return JSON.parse(stripJsonc(readFileSync(path, "utf-8"))) as Record<
140-
string,
141-
unknown
142-
>;
131+
return JSON.parse(stripJsonc(readFileSync(path, "utf-8"))) as Record<string, unknown>;
143132
} catch {
144133
return {};
145134
}
@@ -179,8 +168,7 @@ export function findLatestBackup(path: string): string | undefined {
179168
const suffix = entry.slice(prefix.length);
180169
if (!/^\d+$/.test(suffix)) continue;
181170
const timestamp = Number(suffix);
182-
if (!latest || timestamp > latest.timestamp)
183-
latest = { name: entry, timestamp };
171+
if (!latest || timestamp > latest.timestamp) latest = { name: entry, timestamp };
184172
}
185173
return latest ? join(dir, latest.name) : undefined;
186174
}
@@ -225,10 +213,7 @@ export function resolveClaudeCodeBaseUrl(baseUrl: string): {
225213
}
226214

227215
if (trimmed.includes("/compatible-mode")) {
228-
const rewritten = trimmed.replace(
229-
/\/compatible-mode(?:\/v\d+)?/,
230-
"/apps/anthropic",
231-
);
216+
const rewritten = trimmed.replace(/\/compatible-mode(?:\/v\d+)?/, "/apps/anthropic");
232217
return { url: rewritten, rewrittenFrom: baseUrl.trim() };
233218
}
234219

@@ -239,10 +224,7 @@ export function resolveClaudeCodeBaseUrl(baseUrl: string): {
239224
host.includes("dashscope") ||
240225
host.includes("maas.aliyuncs.com") ||
241226
host.includes("token-plan");
242-
if (
243-
isDashScopeHost &&
244-
(parsed.pathname === "/" || parsed.pathname === "")
245-
) {
227+
if (isDashScopeHost && (parsed.pathname === "/" || parsed.pathname === "")) {
246228
return {
247229
url: `${parsed.origin}/apps/anthropic`,
248230
rewrittenFrom: baseUrl.trim(),

0 commit comments

Comments
 (0)