MCPcopy Create free account
hub / github.com/anus-dev/ANUS / handleFlashFallback

Method handleFlashFallback

packages/core/src/core/client.ts:870–911  ·  view source on GitHub ↗

* Handles falling back to Flash model when persistent 429 errors occur for OAuth users. * Uses a fallback handler if provided by the config; otherwise, returns null.

(
    authType?: string,
    error?: unknown,
  )

Source from the content-addressed store, hash-verified

868 * Uses a fallback handler if provided by the config; otherwise, returns null.
869 */
870 private async handleFlashFallback(
871 authType?: string,
872 error?: unknown,
873 ): Promise<string | null> {
874 // Only handle fallback for OAuth users
875 if (authType !== AuthType.LOGIN_WITH_GOOGLE) {
876 return null;
877 }
878
879 const currentModel = this.config.getModel();
880 const fallbackModel = DEFAULT_FALLBACK_MODEL;
881
882 // Don't fallback if already using Flash model
883 if (currentModel === fallbackModel) {
884 return null;
885 }
886
887 // Check if config has a fallback handler (set by CLI package)
888 const fallbackHandler = this.config.flashFallbackHandler;
889 if (typeof fallbackHandler === 'function') {
890 try {
891 const accepted = await fallbackHandler(
892 currentModel,
893 fallbackModel,
894 error,
895 );
896 if (accepted !== false && accepted !== null) {
897 this.config.setModel(fallbackModel);
898 this.config.setFallbackMode(true);
899 return fallbackModel;
900 }
901 // Check if the model was switched manually in the handler
902 if (this.config.getModel() === fallbackModel) {
903 return null; // Model was switched but don't continue with current prompt
904 }
905 } catch (error) {
906 console.warn('Flash fallback handler failed:', error);
907 }
908 }
909
910 return null;
911 }
912}
913
914export const TEST_ONLY = {

Callers 2

generateJsonMethod · 0.95
generateContentMethod · 0.95

Calls 3

getModelMethod · 0.80
setModelMethod · 0.80
setFallbackModeMethod · 0.80

Tested by

no test coverage detected