UNPKG

@struktoai/mirage-core

Version:

A Unified Virtual Filesystem For AI Agents

71 lines • 4.6 kB
import type { ByteSpool } from '../../io/spool.ts'; import type { ApiRequestOptions, ErrorOf, RetryPolicy } from '../api/client.ts'; import type { GoogleConfig } from './config.ts'; import { TokenManager as OAuthTokenManager } from '../api/oauth.ts'; import { type ByteWindow } from '../../utils/ranges.ts'; import type { Clock } from '../../utils/clock.ts'; import { ApiError } from '../api/errors.ts'; /** Extract Google's API or OAuth error message, with a plain-response fallback. */ export declare function googleErrorMessage(body: string, status: number, reason?: string | null): string; export declare function tokenUrl(config: GoogleConfig): string; export declare function driveBase(tokenManager: TokenManager): string; export declare function driveUploadBase(tokenManager: TokenManager): string; export declare function docsBase(tokenManager: TokenManager): string; export declare function slidesBase(tokenManager: TokenManager): string; export declare function sheetsBase(tokenManager: TokenManager): string; export declare function gmailBase(tokenManager: TokenManager): string; export declare function calendarBase(tokenManager: TokenManager): string; export declare function formsBase(tokenManager: TokenManager): string; /** * Whether a retryable status is worth waiting out. Google answers both "slow * down" and "you may not" with a 403, and only its error reason tells them * apart: the APIs list the reasons in `error.errors`. Every other listed * status is transient as it is. */ export declare function transient(status: number, text: string): boolean; export declare const READ_RETRY: RetryPolicy; export declare const WRITE_RETRY: RetryPolicy; export declare class GoogleApiError extends ApiError { readonly status: number; constructor(message: string, status: number); } export declare function refreshAccessToken(config: GoogleConfig, sleep?: (seconds: number) => Promise<void>): Promise<[string, number]>; /** * Manages OAuth2 access token lifecycle. `clock` is the clock token expiry * and the waits between retries of every call made with this manager are * read on; absent is the system clock. */ export declare class TokenManager extends OAuthTokenManager { readonly config: GoogleConfig; constructor(config: GoogleConfig, clock?: Clock); /** * A supplied token short-circuits the grant entirely, and is read every * call rather than cached: a provider callable is the caller's own cache, * and caching its answer here would outlive the refresh it just performed. * Mirrors python's `TokenManager.get_token`. */ getToken(signal?: AbortSignal): Promise<string>; protected refreshPair(): Promise<[string, number]>; } export declare function googleHeaders(tm: TokenManager): Promise<Record<string, string>>; /** * One Google API call: the door every request but a stream takes. It signs * the call, rides the manager's clock and picks the retry policy from the * method, so a new call site cannot forget any of them: absent `retry`, GET * and HEAD read and everything else writes. A write that is safe to repeat * (the start of a resumable upload) passes READ_RETRY. */ export declare function googleRequest(tm: TokenManager, method: string, url: string, options?: Omit<ApiRequestOptions, 'errorOf' | 'retry' | 'sleep'> & { retry?: RetryPolicy | undefined; errorOf?: ErrorOf | undefined; }): Promise<unknown>; export declare function googleGet(tm: TokenManager, url: string, params?: Record<string, string | number>): Promise<unknown>; export declare function googlePost(tm: TokenManager, url: string, json: unknown): Promise<unknown>; export declare function googlePatch(tm: TokenManager, url: string, json: unknown, params?: Record<string, string>): Promise<unknown>; export declare function googleSendBytes(tm: TokenManager, method: 'POST' | 'PATCH', url: string, data: Uint8Array, contentType: string, params?: Record<string, string>): Promise<unknown>; export declare function googleDelete(tm: TokenManager, url: string): Promise<void>; export declare function googleGetBytes(tm: TokenManager, url: string, window?: ByteWindow): Promise<Uint8Array>; /** GET a URL's raw bytes as they arrive. Mirrors Python's `google_get_stream`. */ export declare function googleGetStream(tm: TokenManager, url: string): AsyncGenerator<Uint8Array, void>; export declare function googleResumable(tm: TokenManager, method: 'POST' | 'PATCH', url: string, metadata: Record<string, unknown>, spool: ByteSpool, mimeType: string, params: Record<string, string>): Promise<unknown>; //# sourceMappingURL=client.d.ts.map