Loading source
Pulling the file list, source metadata, and syntax-aware rendering for this listing.
Source from repo
Generate text and images via the reverse-engineered Gemini Web API with multi-turn conversation support.
Files
Skill
Size
Entrypoint
Format
Open file
Syntax-highlighted preview of this file as included in the skill package.
scripts/gemini-webapi/utils/decorators.ts
1import { APIError, ImageGenerationError } from '../exceptions.js';2import { sleep } from './http.js';34export function running(retry: number = 0) {5return <TArgs extends unknown[], TResult>(6fn: (client: any, ...args: TArgs) => Promise<TResult>,7): ((client: any, ...args: TArgs) => Promise<TResult>) => {8const wrap = async (client: any, ...args: TArgs): Promise<TResult> => {9try {10if (!client?._running) {11await client.init?.({12timeout: client.timeout,13auto_close: client.auto_close,14close_delay: client.close_delay,15auto_refresh: client.auto_refresh,16refresh_interval: client.refresh_interval,17verbose: false,18});19}20return await fn(client, ...args);21} catch (e) {22let r = retry;23if (e instanceof ImageGenerationError) r = Math.min(1, r);24if (e instanceof APIError && r > 0) {25await sleep(1000);26return await running(r - 1)(fn)(client, ...args);27}28throw e;29}30};31return wrap;32};33}3435