/** * Response Adapter for Edge Function envelope format * Handles the transition between direct API responses and Edge Function wrapped responses */ import { EdgeFunctionResponse } from "../core/types.js"; import { ApiResponse } from "./http-client.js"; export interface UsageInfo { tokens_used: number; cost_usd: number; cached: boolean; } export interface TierInfo { tier: string; usage_remaining: number; } export interface UnwrappedResponse { data?: T; error?: { message: string; code?: string; }; usage?: UsageInfo; tier_info?: TierInfo; status: number; } /** * Adapts Edge Function envelope response to SDK internal format * Edge Functions return: { success, data, error, usage, tier_info } * SDK expects: { data, error, status } */ export declare function adaptEdgeFunctionResponse(httpResponse: ApiResponse>): UnwrappedResponse; /** * Checks if a response appears to be an Edge Function envelope */ export declare function isEdgeFunctionEnvelope(data: unknown): data is EdgeFunctionResponse; /** * Smart adapter that detects response format and adapts accordingly * Supports both direct API responses and Edge Function envelopes */ export declare function adaptResponse(httpResponse: ApiResponse>): UnwrappedResponse; /** * Cache entry for offline fallback support */ export interface CacheEntry { data: T; timestamp: number; endpoint: string; params?: Record; } /** * Simple in-memory cache for offline fallback */ export declare class ResponseCache { private cache; private ttl; constructor(ttlMs?: number); private generateKey; set(endpoint: string, data: T, params?: Record): void; get(endpoint: string, params?: Record): T | null; clear(): void; /** * Clean up expired entries */ cleanup(): void; }