style: apply oxfmt to minimax provider and tests
This commit is contained in:
parent
e46931f300
commit
b9335e6b06
@ -4,10 +4,7 @@ import {
|
|||||||
DEFAULT_COPILOT_API_BASE_URL,
|
DEFAULT_COPILOT_API_BASE_URL,
|
||||||
resolveCopilotApiToken,
|
resolveCopilotApiToken,
|
||||||
} from "../providers/github-copilot-token.js";
|
} from "../providers/github-copilot-token.js";
|
||||||
import {
|
import { ensureAuthProfileStore, listProfilesForProvider } from "./auth-profiles.js";
|
||||||
ensureAuthProfileStore,
|
|
||||||
listProfilesForProvider,
|
|
||||||
} from "./auth-profiles.js";
|
|
||||||
import { resolveAwsSdkEnvVarName, resolveEnvApiKey } from "./model-auth.js";
|
import { resolveAwsSdkEnvVarName, resolveEnvApiKey } from "./model-auth.js";
|
||||||
import { discoverBedrockModels } from "./bedrock-discovery.js";
|
import { discoverBedrockModels } from "./bedrock-discovery.js";
|
||||||
import {
|
import {
|
||||||
@ -114,8 +111,7 @@ async function discoverOllamaModels(): Promise<ModelDefinitionConfig[]> {
|
|||||||
return data.models.map((model) => {
|
return data.models.map((model) => {
|
||||||
const modelId = model.name;
|
const modelId = model.name;
|
||||||
const isReasoning =
|
const isReasoning =
|
||||||
modelId.toLowerCase().includes("r1") ||
|
modelId.toLowerCase().includes("r1") || modelId.toLowerCase().includes("reasoning");
|
||||||
modelId.toLowerCase().includes("reasoning");
|
|
||||||
return {
|
return {
|
||||||
id: modelId,
|
id: modelId,
|
||||||
name: modelId,
|
name: modelId,
|
||||||
@ -199,8 +195,7 @@ export function normalizeProviders(params: {
|
|||||||
// Fix common misconfig: apiKey set to "${ENV_VAR}" instead of "ENV_VAR".
|
// Fix common misconfig: apiKey set to "${ENV_VAR}" instead of "ENV_VAR".
|
||||||
if (
|
if (
|
||||||
normalizedProvider.apiKey &&
|
normalizedProvider.apiKey &&
|
||||||
normalizeApiKeyConfig(normalizedProvider.apiKey) !==
|
normalizeApiKeyConfig(normalizedProvider.apiKey) !== normalizedProvider.apiKey
|
||||||
normalizedProvider.apiKey
|
|
||||||
) {
|
) {
|
||||||
mutated = true;
|
mutated = true;
|
||||||
normalizedProvider = {
|
normalizedProvider = {
|
||||||
@ -212,12 +207,10 @@ export function normalizeProviders(params: {
|
|||||||
// If a provider defines models, pi's ModelRegistry requires apiKey to be set.
|
// If a provider defines models, pi's ModelRegistry requires apiKey to be set.
|
||||||
// Fill it from the environment or auth profiles when possible.
|
// Fill it from the environment or auth profiles when possible.
|
||||||
const hasModels =
|
const hasModels =
|
||||||
Array.isArray(normalizedProvider.models) &&
|
Array.isArray(normalizedProvider.models) && normalizedProvider.models.length > 0;
|
||||||
normalizedProvider.models.length > 0;
|
|
||||||
if (hasModels && !normalizedProvider.apiKey?.trim()) {
|
if (hasModels && !normalizedProvider.apiKey?.trim()) {
|
||||||
const authMode =
|
const authMode =
|
||||||
normalizedProvider.auth ??
|
normalizedProvider.auth ?? (normalizedKey === "amazon-bedrock" ? "aws-sdk" : undefined);
|
||||||
(normalizedKey === "amazon-bedrock" ? "aws-sdk" : undefined);
|
|
||||||
if (authMode === "aws-sdk") {
|
if (authMode === "aws-sdk") {
|
||||||
const apiKey = resolveAwsSdkApiKeyVarName();
|
const apiKey = resolveAwsSdkApiKeyVarName();
|
||||||
mutated = true;
|
mutated = true;
|
||||||
@ -439,8 +432,7 @@ export async function resolveImplicitCopilotProvider(params: {
|
|||||||
const authStore = ensureAuthProfileStore(params.agentDir, {
|
const authStore = ensureAuthProfileStore(params.agentDir, {
|
||||||
allowKeychainPrompt: false,
|
allowKeychainPrompt: false,
|
||||||
});
|
});
|
||||||
const hasProfile =
|
const hasProfile = listProfilesForProvider(authStore, "github-copilot").length > 0;
|
||||||
listProfilesForProvider(authStore, "github-copilot").length > 0;
|
|
||||||
const envToken = env.COPILOT_GITHUB_TOKEN ?? env.GH_TOKEN ?? env.GITHUB_TOKEN;
|
const envToken = env.COPILOT_GITHUB_TOKEN ?? env.GH_TOKEN ?? env.GITHUB_TOKEN;
|
||||||
const githubToken = (envToken ?? "").trim();
|
const githubToken = (envToken ?? "").trim();
|
||||||
|
|
||||||
@ -503,11 +495,7 @@ export async function resolveImplicitBedrockProvider(params: {
|
|||||||
if (enabled === false) return null;
|
if (enabled === false) return null;
|
||||||
if (enabled !== true && !hasAwsCreds) return null;
|
if (enabled !== true && !hasAwsCreds) return null;
|
||||||
|
|
||||||
const region =
|
const region = discoveryConfig?.region ?? env.AWS_REGION ?? env.AWS_DEFAULT_REGION ?? "us-east-1";
|
||||||
discoveryConfig?.region ??
|
|
||||||
env.AWS_REGION ??
|
|
||||||
env.AWS_DEFAULT_REGION ??
|
|
||||||
"us-east-1";
|
|
||||||
const models = await discoverBedrockModels({
|
const models = await discoverBedrockModels({
|
||||||
region,
|
region,
|
||||||
config: discoveryConfig,
|
config: discoveryConfig,
|
||||||
|
|||||||
@ -74,9 +74,7 @@ describe("models-config", () => {
|
|||||||
agentDir,
|
agentDir,
|
||||||
);
|
);
|
||||||
|
|
||||||
await expect(
|
await expect(fs.stat(path.join(agentDir, "models.json"))).rejects.toThrow();
|
||||||
fs.stat(path.join(agentDir, "models.json")),
|
|
||||||
).rejects.toThrow();
|
|
||||||
expect(result.wrote).toBe(false);
|
expect(result.wrote).toBe(false);
|
||||||
} finally {
|
} finally {
|
||||||
if (previous === undefined) delete process.env.COPILOT_GITHUB_TOKEN;
|
if (previous === undefined) delete process.env.COPILOT_GITHUB_TOKEN;
|
||||||
@ -91,8 +89,7 @@ describe("models-config", () => {
|
|||||||
else process.env.MINIMAX_API_KEY = previousMinimax;
|
else process.env.MINIMAX_API_KEY = previousMinimax;
|
||||||
if (previousMoonshot === undefined) delete process.env.MOONSHOT_API_KEY;
|
if (previousMoonshot === undefined) delete process.env.MOONSHOT_API_KEY;
|
||||||
else process.env.MOONSHOT_API_KEY = previousMoonshot;
|
else process.env.MOONSHOT_API_KEY = previousMoonshot;
|
||||||
if (previousSynthetic === undefined)
|
if (previousSynthetic === undefined) delete process.env.SYNTHETIC_API_KEY;
|
||||||
delete process.env.SYNTHETIC_API_KEY;
|
|
||||||
else process.env.SYNTHETIC_API_KEY = previousSynthetic;
|
else process.env.SYNTHETIC_API_KEY = previousSynthetic;
|
||||||
if (previousVenice === undefined) delete process.env.VENICE_API_KEY;
|
if (previousVenice === undefined) delete process.env.VENICE_API_KEY;
|
||||||
else process.env.VENICE_API_KEY = previousVenice;
|
else process.env.VENICE_API_KEY = previousVenice;
|
||||||
@ -113,9 +110,7 @@ describe("models-config", () => {
|
|||||||
providers: Record<string, { baseUrl?: string }>;
|
providers: Record<string, { baseUrl?: string }>;
|
||||||
};
|
};
|
||||||
|
|
||||||
expect(parsed.providers["custom-proxy"]?.baseUrl).toBe(
|
expect(parsed.providers["custom-proxy"]?.baseUrl).toBe("http://localhost:4000/v1");
|
||||||
"http://localhost:4000/v1",
|
|
||||||
);
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
it("adds minimax provider when MINIMAX_API_KEY is set", async () => {
|
it("adds minimax provider when MINIMAX_API_KEY is set", async () => {
|
||||||
@ -141,9 +136,7 @@ describe("models-config", () => {
|
|||||||
}
|
}
|
||||||
>;
|
>;
|
||||||
};
|
};
|
||||||
expect(parsed.providers.minimax?.baseUrl).toBe(
|
expect(parsed.providers.minimax?.baseUrl).toBe("https://api.minimax.io/v1");
|
||||||
"https://api.minimax.io/v1",
|
|
||||||
);
|
|
||||||
expect(parsed.providers.minimax?.apiKey).toBe("MINIMAX_API_KEY");
|
expect(parsed.providers.minimax?.apiKey).toBe("MINIMAX_API_KEY");
|
||||||
const ids = parsed.providers.minimax?.models?.map((model) => model.id);
|
const ids = parsed.providers.minimax?.models?.map((model) => model.id);
|
||||||
expect(ids).toContain("MiniMax-M2.1");
|
expect(ids).toContain("MiniMax-M2.1");
|
||||||
@ -177,13 +170,9 @@ describe("models-config", () => {
|
|||||||
}
|
}
|
||||||
>;
|
>;
|
||||||
};
|
};
|
||||||
expect(parsed.providers.synthetic?.baseUrl).toBe(
|
expect(parsed.providers.synthetic?.baseUrl).toBe("https://api.synthetic.new/anthropic");
|
||||||
"https://api.synthetic.new/anthropic",
|
|
||||||
);
|
|
||||||
expect(parsed.providers.synthetic?.apiKey).toBe("SYNTHETIC_API_KEY");
|
expect(parsed.providers.synthetic?.apiKey).toBe("SYNTHETIC_API_KEY");
|
||||||
const ids = parsed.providers.synthetic?.models?.map(
|
const ids = parsed.providers.synthetic?.models?.map((model) => model.id);
|
||||||
(model) => model.id,
|
|
||||||
);
|
|
||||||
expect(ids).toContain("hf:MiniMaxAI/MiniMax-M2.1");
|
expect(ids).toContain("hf:MiniMaxAI/MiniMax-M2.1");
|
||||||
} finally {
|
} finally {
|
||||||
if (prevKey === undefined) delete process.env.SYNTHETIC_API_KEY;
|
if (prevKey === undefined) delete process.env.SYNTHETIC_API_KEY;
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user