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

Method handleFlashFallback

packages/core/src/core/anusChat.ts:136–177  ·  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

134 * Uses a fallback handler if provided by the config; otherwise, returns null.
135 */
136 private async handleFlashFallback(
137 authType?: string,
138 error?: unknown,
139 ): Promise<string | null> {
140 // Only handle fallback for OAuth users
141 if (authType !== AuthType.LOGIN_WITH_GOOGLE) {
142 return null;
143 }
144
145 const currentModel = this.config.getModel();
146 const fallbackModel = DEFAULT_FALLBACK_MODEL;
147
148 // Don't fallback if already using Flash model
149 if (currentModel === fallbackModel) {
150 return null;
151 }
152
153 // Check if config has a fallback handler (set by CLI package)
154 const fallbackHandler = this.config.flashFallbackHandler;
155 if (typeof fallbackHandler === 'function') {
156 try {
157 const accepted = await fallbackHandler(
158 currentModel,
159 fallbackModel,
160 error,
161 );
162 if (accepted !== false && accepted !== null) {
163 this.config.setModel(fallbackModel);
164 this.config.setFallbackMode(true);
165 return fallbackModel;
166 }
167 // Check if the model was switched manually in the handler
168 if (this.config.getModel() === fallbackModel) {
169 return null; // Model was switched but don't continue with current prompt
170 }
171 } catch (error) {
172 console.warn('Flash fallback handler failed:', error);
173 }
174 }
175
176 return null;
177 }
178
179 setSystemInstruction(sysInstr: string) {
180 this.generationConfig.systemInstruction = sysInstr;

Callers 2

sendMessageMethod · 0.95
sendMessageStreamMethod · 0.95

Calls 3

getModelMethod · 0.80
setModelMethod · 0.80
setFallbackModeMethod · 0.80

Tested by

no test coverage detected