chore(lint): restore zero-error eslint baseline
This commit is contained in:
+96
-96
@@ -57,115 +57,115 @@ function resolveZaiCredential(cfg: ModelConfig): string {
|
||||
export function createClientFromConfig(cfg: ModelConfig): ModelClient {
|
||||
switch (cfg.provider) {
|
||||
case 'anthropic':
|
||||
{
|
||||
const authMode = getEffectiveAuthMode(cfg);
|
||||
|
||||
if (authMode === 'oauth') {
|
||||
const token = cfg.auth_token ?? getAnthropicAuthToken();
|
||||
if (!token) {
|
||||
throw new Error(
|
||||
'Anthropic auth token not configured (auth_mode: oauth). ' +
|
||||
'Set ANTHROPIC_AUTH_TOKEN, run `flynn anthropic-auth --token`, or provide auth_token in config.',
|
||||
);
|
||||
}
|
||||
return new AnthropicClient({
|
||||
model: cfg.model,
|
||||
authToken: token,
|
||||
});
|
||||
}
|
||||
|
||||
if (authMode === 'api_key') {
|
||||
const apiKey = cfg.api_key ?? getAnthropicApiKey();
|
||||
if (!apiKey) {
|
||||
throw new Error(
|
||||
'Anthropic API key not configured (auth_mode: api_key). ' +
|
||||
'Set ANTHROPIC_API_KEY, run `flynn anthropic-auth`, or provide api_key in config.',
|
||||
);
|
||||
}
|
||||
return new AnthropicClient({
|
||||
model: cfg.model,
|
||||
apiKey,
|
||||
});
|
||||
}
|
||||
|
||||
// auto: prefer API key, then token
|
||||
const apiKey = cfg.api_key ?? getAnthropicApiKey();
|
||||
if (apiKey) {
|
||||
return new AnthropicClient({
|
||||
model: cfg.model,
|
||||
apiKey,
|
||||
});
|
||||
}
|
||||
{
|
||||
const authMode = getEffectiveAuthMode(cfg);
|
||||
|
||||
if (authMode === 'oauth') {
|
||||
const token = cfg.auth_token ?? getAnthropicAuthToken();
|
||||
if (token) {
|
||||
return new AnthropicClient({
|
||||
model: cfg.model,
|
||||
authToken: token,
|
||||
});
|
||||
if (!token) {
|
||||
throw new Error(
|
||||
'Anthropic auth token not configured (auth_mode: oauth). ' +
|
||||
'Set ANTHROPIC_AUTH_TOKEN, run `flynn anthropic-auth --token`, or provide auth_token in config.',
|
||||
);
|
||||
}
|
||||
return new AnthropicClient({
|
||||
model: cfg.model,
|
||||
authToken: token,
|
||||
});
|
||||
}
|
||||
|
||||
throw new Error(
|
||||
'Anthropic credentials not configured (auth_mode: auto). ' +
|
||||
if (authMode === 'api_key') {
|
||||
const apiKey = cfg.api_key ?? getAnthropicApiKey();
|
||||
if (!apiKey) {
|
||||
throw new Error(
|
||||
'Anthropic API key not configured (auth_mode: api_key). ' +
|
||||
'Set ANTHROPIC_API_KEY, run `flynn anthropic-auth`, or provide api_key in config.',
|
||||
);
|
||||
}
|
||||
return new AnthropicClient({
|
||||
model: cfg.model,
|
||||
apiKey,
|
||||
});
|
||||
}
|
||||
|
||||
// auto: prefer API key, then token
|
||||
const apiKey = cfg.api_key ?? getAnthropicApiKey();
|
||||
if (apiKey) {
|
||||
return new AnthropicClient({
|
||||
model: cfg.model,
|
||||
apiKey,
|
||||
});
|
||||
}
|
||||
|
||||
const token = cfg.auth_token ?? getAnthropicAuthToken();
|
||||
if (token) {
|
||||
return new AnthropicClient({
|
||||
model: cfg.model,
|
||||
authToken: token,
|
||||
});
|
||||
}
|
||||
|
||||
throw new Error(
|
||||
'Anthropic credentials not configured (auth_mode: auto). ' +
|
||||
'Set ANTHROPIC_API_KEY (or run `flynn anthropic-auth`), ' +
|
||||
'or set ANTHROPIC_AUTH_TOKEN (or run `flynn anthropic-auth --token`).',
|
||||
);
|
||||
}
|
||||
);
|
||||
}
|
||||
case 'openai':
|
||||
{
|
||||
const authMode = getEffectiveAuthMode(cfg);
|
||||
|
||||
if (authMode === 'oauth') {
|
||||
const existing = loadStoredOpenAIAuth();
|
||||
if (!existing) {
|
||||
throw new Error(
|
||||
'OpenAI OAuth is not configured (auth_mode: oauth). ' +
|
||||
'Run `flynn openai-auth` to authenticate.',
|
||||
);
|
||||
}
|
||||
return new OpenAIClient({
|
||||
model: cfg.model,
|
||||
useOAuth: true,
|
||||
});
|
||||
}
|
||||
|
||||
if (authMode === 'api_key') {
|
||||
const apiKey = cfg.api_key ?? getOpenAIApiKey();
|
||||
if (!apiKey) {
|
||||
throw new Error(
|
||||
'OpenAI API key not configured (auth_mode: api_key). ' +
|
||||
'Set OPENAI_API_KEY, run `flynn openai-key`, or provide api_key in config.',
|
||||
);
|
||||
}
|
||||
return new OpenAIClient({
|
||||
model: cfg.model,
|
||||
apiKey,
|
||||
});
|
||||
}
|
||||
|
||||
// auto: prefer API key, then OAuth
|
||||
const apiKey = cfg.api_key ?? getOpenAIApiKey();
|
||||
if (apiKey) {
|
||||
return new OpenAIClient({
|
||||
model: cfg.model,
|
||||
apiKey,
|
||||
});
|
||||
}
|
||||
{
|
||||
const authMode = getEffectiveAuthMode(cfg);
|
||||
|
||||
if (authMode === 'oauth') {
|
||||
const existing = loadStoredOpenAIAuth();
|
||||
if (existing) {
|
||||
return new OpenAIClient({
|
||||
model: cfg.model,
|
||||
useOAuth: true,
|
||||
});
|
||||
if (!existing) {
|
||||
throw new Error(
|
||||
'OpenAI OAuth is not configured (auth_mode: oauth). ' +
|
||||
'Run `flynn openai-auth` to authenticate.',
|
||||
);
|
||||
}
|
||||
return new OpenAIClient({
|
||||
model: cfg.model,
|
||||
useOAuth: true,
|
||||
});
|
||||
}
|
||||
|
||||
throw new Error(
|
||||
'OpenAI credentials not configured (auth_mode: auto). ' +
|
||||
if (authMode === 'api_key') {
|
||||
const apiKey = cfg.api_key ?? getOpenAIApiKey();
|
||||
if (!apiKey) {
|
||||
throw new Error(
|
||||
'OpenAI API key not configured (auth_mode: api_key). ' +
|
||||
'Set OPENAI_API_KEY, run `flynn openai-key`, or provide api_key in config.',
|
||||
);
|
||||
}
|
||||
return new OpenAIClient({
|
||||
model: cfg.model,
|
||||
apiKey,
|
||||
});
|
||||
}
|
||||
|
||||
// auto: prefer API key, then OAuth
|
||||
const apiKey = cfg.api_key ?? getOpenAIApiKey();
|
||||
if (apiKey) {
|
||||
return new OpenAIClient({
|
||||
model: cfg.model,
|
||||
apiKey,
|
||||
});
|
||||
}
|
||||
|
||||
const existing = loadStoredOpenAIAuth();
|
||||
if (existing) {
|
||||
return new OpenAIClient({
|
||||
model: cfg.model,
|
||||
useOAuth: true,
|
||||
});
|
||||
}
|
||||
|
||||
throw new Error(
|
||||
'OpenAI credentials not configured (auth_mode: auto). ' +
|
||||
'Set OPENAI_API_KEY (or run `flynn openai-key`), ' +
|
||||
'or run `flynn openai-auth` for OAuth.',
|
||||
);
|
||||
}
|
||||
);
|
||||
}
|
||||
case 'ollama':
|
||||
return new OllamaClient({
|
||||
model: cfg.model,
|
||||
|
||||
Reference in New Issue
Block a user