import { invoke } from "@tauri-apps/api/core"; import type { UsageSummary, DailyStats, ProviderStats, ModelStats, RequestLog, LogFilters, ModelPricing, ProviderLimitStatus, PaginatedLogs, SessionSyncResult, DataSourceSummary, } from "@/types/usage"; import type { UsageResult } from "@/types"; import type { AppId } from "./types"; import type { TemplateType } from "@/config/constants"; export const usageApi = { // Provider usage script methods query: async (providerId: string, appId: AppId): Promise => { return invoke("queryProviderUsage", { providerId, app: appId }); }, testScript: async ( providerId: string, appId: AppId, scriptCode: string, timeout?: number, apiKey?: string, baseUrl?: string, accessToken?: string, userId?: string, templateType?: TemplateType, ): Promise => { return invoke("testUsageScript", { providerId, app: appId, scriptCode, timeout, apiKey, baseUrl, accessToken, userId, templateType, }); }, // Proxy usage statistics methods getUsageSummary: async ( startDate?: number, endDate?: number, ): Promise => { return invoke("get_usage_summary", { startDate, endDate }); }, getUsageTrends: async ( startDate?: number, endDate?: number, ): Promise => { return invoke("get_usage_trends", { startDate, endDate }); }, getProviderStats: async (): Promise => { return invoke("get_provider_stats"); }, getModelStats: async (): Promise => { return invoke("get_model_stats"); }, getRequestLogs: async ( filters: LogFilters, page: number = 0, pageSize: number = 20, ): Promise => { return invoke("get_request_logs", { filters, page, pageSize, }); }, getRequestDetail: async (requestId: string): Promise => { return invoke("get_request_detail", { requestId }); }, getModelPricing: async (): Promise => { return invoke("get_model_pricing"); }, updateModelPricing: async ( modelId: string, displayName: string, inputCost: string, outputCost: string, cacheReadCost: string, cacheCreationCost: string, ): Promise => { return invoke("update_model_pricing", { modelId, displayName, inputCost, outputCost, cacheReadCost, cacheCreationCost, }); }, deleteModelPricing: async (modelId: string): Promise => { return invoke("delete_model_pricing", { modelId }); }, checkProviderLimits: async ( providerId: string, appType: string, ): Promise => { return invoke("check_provider_limits", { providerId, appType }); }, // Session usage sync syncSessionUsage: async (): Promise => { return invoke("sync_session_usage"); }, getDataSourceBreakdown: async (): Promise => { return invoke("get_usage_data_sources"); }, };