fix: default engine auto with graphql primary

This commit is contained in:
Peter Steinberger
2025-12-25 14:00:35 +01:00
parent c4689d2580
commit 3661f784cb
4 changed files with 26 additions and 20 deletions
+2 -17
View File
@@ -17,6 +17,7 @@ import JSON5 from 'json5';
import kleur from 'kleur';
import { resolveCliInvocation } from './lib/cli-args.js';
import { resolveCredentials } from './lib/cookies.js';
import { resolveEngineMode, shouldUseSweetistics, type EngineMode } from './lib/engine.js';
import { extractTweetId } from './lib/extract-tweet-id.js';
import { SweetisticsClient } from './lib/sweetistics-client.js';
import { type TweetData, TwitterClient } from './lib/twitter-client.js';
@@ -130,12 +131,10 @@ program
.option(
'--engine <engine>',
'Engine: graphql | sweetistics | auto',
process.env.BIRD_ENGINE || config.engine || 'graphql',
process.env.BIRD_ENGINE || config.engine || 'auto',
)
.option('--timeout <ms>', 'Request timeout in milliseconds');
type EngineMode = 'graphql' | 'sweetistics' | 'auto';
type MediaSpec = { path: string; alt?: string; mime: string; buffer: Buffer };
function resolveSweetisticsConfig(options: { sweetisticsApiKey?: string; sweetisticsBaseUrl?: string }) {
@@ -147,20 +146,6 @@ function resolveSweetisticsConfig(options: { sweetisticsApiKey?: string; sweetis
return { apiKey, baseUrl };
}
function resolveEngineMode(value?: string): EngineMode {
const normalized = (value || 'auto').toLowerCase();
if (normalized === 'graphql' || normalized === 'sweetistics' || normalized === 'auto') {
return normalized;
}
return 'auto';
}
function shouldUseSweetistics(engine: EngineMode, hasApiKey: boolean): boolean {
if (engine === 'sweetistics') return true;
if (engine === 'graphql') return false;
return hasApiKey; // auto
}
function resolveTimeoutMs(...values: Array<string | number | undefined | null>): number | undefined {
for (const value of values) {
if (value === undefined || value === null || value === '') continue;
+15
View File
@@ -0,0 +1,15 @@
export type EngineMode = 'graphql' | 'sweetistics' | 'auto';
export function resolveEngineMode(value?: string): EngineMode {
const normalized = (value || 'auto').toLowerCase();
if (normalized === 'graphql' || normalized === 'sweetistics' || normalized === 'auto') {
return normalized;
}
return 'auto';
}
export function shouldUseSweetistics(engine: EngineMode, hasApiKey: boolean): boolean {
if (engine === 'sweetistics') return true;
if (engine === 'graphql') return false;
return false; // auto: GraphQL primary, Sweetistics only as fallback
}