Merge upstream/main into feature/glm-zai-providers
Resolve conflicts with Xiaomi MiMo provider addition (#3454). Both PRs added new providers to the same infrastructure files. Conflicts resolved by including both sets of changes: - docs/providers/index.md: Add Xiaomi link alongside GLM docs - src/cli/program/register.onboard.ts: Add all CLI flags - src/commands/auth-choice-options.ts: Add all auth choices and groups - src/commands/auth-choice.apply.api-providers.ts: Add all handlers - src/commands/onboard-auth.config-core.ts: Add all config imports - src/commands/onboard-auth.credentials.ts: Add all credentials functions - src/commands/onboard-auth.ts: Add all exports - src/commands/onboard-non-interactive/local/auth-choice.ts: Add all handlers - src/commands/onboard-types.ts: Add all types - src/infra/provider-usage.shared.ts: Add all provider labels - src/infra/provider-usage.types.ts: Add all provider IDs Generated with [Claude Code](https://claude.ai/code) via [Happy](https://happy.engineering) Co-Authored-By: Claude <noreply@anthropic.com> Co-Authored-By: Happy <yesreply@happy.engineering>
This commit is contained in:
commit
d8fa00e9f2
89 files changed
+1138
-251
No files matched your search
@@ -96,6 +96,33 @@ function resolveMinimaxApiKey(): string | undefined {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
function resolveXiaomiApiKey(): string | undefined {
|
||||
const envDirect = process.env.XIAOMI_API_KEY?.trim();
|
||||
if (envDirect) return envDirect;
|
||||
|
||||
const envResolved = resolveEnvApiKey("xiaomi");
|
||||
if (envResolved?.apiKey) return envResolved.apiKey;
|
||||
|
||||
const cfg = loadConfig();
|
||||
const key = getCustomProviderApiKey(cfg, "xiaomi");
|
||||
if (key) return key;
|
||||
|
||||
const store = ensureAuthProfileStore();
|
||||
const apiProfile = listProfilesForProvider(store, "xiaomi").find((id) => {
|
||||
const cred = store.profiles[id];
|
||||
return cred?.type === "api_key" || cred?.type === "token";
|
||||
});
|
||||
if (!apiProfile) return undefined;
|
||||
const cred = store.profiles[apiProfile];
|
||||
if (cred?.type === "api_key" && cred.key?.trim()) {
|
||||
return cred.key.trim();
|
||||
}
|
||||
if (cred?.type === "token" && cred.token?.trim()) {
|
||||
return cred.token.trim();
|
||||
}
|
||||
return undefined;
|
||||
}
|
||||
|
||||
async function resolveOAuthToken(params: {
|
||||
provider: UsageProviderId;
|
||||
agentDir?: string;
|
||||
@@ -199,6 +226,11 @@ export async function resolveProviderAuths(params: {
|
||||
if (apiKey) auths.push({ provider, token: apiKey });
|
||||
continue;
|
||||
}
|
||||
if (provider === "xiaomi") {
|
||||
const apiKey = resolveXiaomiApiKey();
|
||||
if (apiKey) auths.push({ provider, token: apiKey });
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!oauthProviders.includes(provider)) continue;
|
||||
const auth = await resolveOAuthToken({
|
||||
|
||||
@@ -66,6 +66,12 @@ export async function loadProviderUsageSummary(
|
||||
return await fetchCodexUsage(auth.token, auth.accountId, timeoutMs, fetchFn);
|
||||
case "minimax":
|
||||
return await fetchMinimaxUsage(auth.token, timeoutMs, fetchFn);
|
||||
case "xiaomi":
|
||||
return {
|
||||
provider: "xiaomi",
|
||||
displayName: PROVIDER_LABELS.xiaomi,
|
||||
windows: [],
|
||||
};
|
||||
case "zai":
|
||||
case "zai-coding":
|
||||
case "zhipu":
|
||||
|
||||
@@ -10,6 +10,7 @@ export const PROVIDER_LABELS: Record<UsageProviderId, string> = {
|
||||
"google-antigravity": "Antigravity",
|
||||
minimax: "MiniMax",
|
||||
"openai-codex": "Codex",
|
||||
xiaomi: "Xiaomi",
|
||||
zai: "Z.AI",
|
||||
"zai-coding": "Z.AI Coding",
|
||||
zhipu: "Zhipu AI",
|
||||
@@ -23,6 +24,7 @@ export const usageProviders: UsageProviderId[] = [
|
||||
"google-antigravity",
|
||||
"minimax",
|
||||
"openai-codex",
|
||||
"xiaomi",
|
||||
"zai",
|
||||
"zai-coding",
|
||||
"zhipu",
|
||||
|
||||
@@ -24,6 +24,7 @@ export type UsageProviderId =
|
||||
| "google-antigravity"
|
||||
| "minimax"
|
||||
| "openai-codex"
|
||||
| "xiaomi"
|
||||
| "zai"
|
||||
| "zai-coding"
|
||||
| "zhipu"
|
||||
|
||||
@@ -54,6 +54,8 @@ describe("ssh-config", () => {
|
||||
expect(config?.host).toBe("peters-mac-studio-1.sheep-coho.ts.net");
|
||||
expect(config?.port).toBe(2222);
|
||||
expect(config?.identityFiles).toEqual(["/tmp/id_ed25519"]);
|
||||
const args = spawnMock.mock.calls[0]?.[1] as string[] | undefined;
|
||||
expect(args?.slice(-2)).toEqual(["--", "me@alias"]);
|
||||
});
|
||||
|
||||
it("returns null when ssh -G fails", async () => {
|
||||
|
||||
@@ -58,7 +58,8 @@ export async function resolveSshConfig(
|
||||
args.push("-i", opts.identity.trim());
|
||||
}
|
||||
const userHost = target.user ? `${target.user}@${target.host}` : target.host;
|
||||
args.push(userHost);
|
||||
// Use "--" so userHost can't be parsed as an ssh option.
|
||||
args.push("--", userHost);
|
||||
|
||||
return await new Promise<SshResolvedConfig | null>((resolve) => {
|
||||
const child = spawn(sshPath, args, {
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
|
||||
import { parseSshTarget } from "./ssh-tunnel.js";
|
||||
|
||||
describe("parseSshTarget", () => {
|
||||
it("parses user@host:port targets", () => {
|
||||
expect(parseSshTarget("me@example.com:2222")).toEqual({
|
||||
user: "me",
|
||||
host: "example.com",
|
||||
port: 2222,
|
||||
});
|
||||
});
|
||||
|
||||
it("parses host-only targets with default port", () => {
|
||||
expect(parseSshTarget("example.com")).toEqual({
|
||||
user: undefined,
|
||||
host: "example.com",
|
||||
port: 22,
|
||||
});
|
||||
});
|
||||
|
||||
it("rejects hostnames that start with '-'", () => {
|
||||
expect(parseSshTarget("-V")).toBeNull();
|
||||
expect(parseSshTarget("me@-badhost")).toBeNull();
|
||||
expect(parseSshTarget("-oProxyCommand=echo")).toBeNull();
|
||||
});
|
||||
});
|
||||
@@ -41,10 +41,14 @@ export function parseSshTarget(raw: string): SshParsedTarget | null {
|
||||
const portRaw = hostPart.slice(colonIdx + 1).trim();
|
||||
const port = Number.parseInt(portRaw, 10);
|
||||
if (!host || !Number.isFinite(port) || port <= 0) return null;
|
||||
// Security: Reject hostnames starting with '-' to prevent argument injection
|
||||
if (host.startsWith("-")) return null;
|
||||
return { user: userPart, host, port };
|
||||
}
|
||||
|
||||
if (!hostPart) return null;
|
||||
// Security: Reject hostnames starting with '-' to prevent argument injection
|
||||
if (hostPart.startsWith("-")) return null;
|
||||
return { user: userPart, host: hostPart, port: 22 };
|
||||
}
|
||||
|
||||
@@ -134,7 +138,8 @@ export async function startSshPortForward(opts: {
|
||||
if (opts.identity?.trim()) {
|
||||
args.push("-i", opts.identity.trim());
|
||||
}
|
||||
args.push(userHost);
|
||||
// Security: Use '--' to prevent userHost from being interpreted as an option
|
||||
args.push("--", userHost);
|
||||
|
||||
const stderr: string[] = [];
|
||||
const child = spawn("/usr/bin/ssh", args, {
|
||||
|
||||
Reference in new issue
Block a user