mirror of
https://github.com/Significant-Gravitas/AutoGPT.git
synced 2026-04-08 03:00:28 -04:00
refactor(frontend): use generated API client instead of legacy BackendAPI
Switch rate limit admin UI to use auto-generated hooks/types from OpenAPI spec instead of manually typed legacy BackendAPI methods. Removes UserRateLimitResponse from deprecated types.ts and getUserRateLimit/resetUserRateLimit from legacy client.ts. Also regenerates API client to fix pre-existing type error from dev.
This commit is contained in:
@@ -1,21 +0,0 @@
|
||||
"use server";
|
||||
|
||||
import { revalidatePath } from "next/cache";
|
||||
import BackendApi from "@/lib/autogpt-server-api";
|
||||
import type { UserRateLimitResponse } from "@/lib/autogpt-server-api/types";
|
||||
|
||||
export async function getUserRateLimit(
|
||||
userId: string,
|
||||
): Promise<UserRateLimitResponse> {
|
||||
const api = new BackendApi();
|
||||
return api.getUserRateLimit(userId);
|
||||
}
|
||||
|
||||
export async function resetUserRateLimit(
|
||||
userId: string,
|
||||
): Promise<UserRateLimitResponse> {
|
||||
const api = new BackendApi();
|
||||
const result = await api.resetUserRateLimit(userId);
|
||||
revalidatePath("/admin/rate-limits");
|
||||
return result;
|
||||
}
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
import { useState } from "react";
|
||||
import { Button } from "@/components/__legacy__/ui/button";
|
||||
import type { UserRateLimitResponse } from "@/lib/autogpt-server-api/types";
|
||||
import type { UserRateLimitResponse } from "@/app/api/__generated__/models/userRateLimitResponse";
|
||||
|
||||
function formatTokens(tokens: number): string {
|
||||
if (tokens === 0) return "Unlimited";
|
||||
|
||||
@@ -6,8 +6,11 @@ import { Input } from "@/components/__legacy__/ui/input";
|
||||
import { Label } from "@/components/__legacy__/ui/label";
|
||||
import { MagnifyingGlass } from "@phosphor-icons/react/dist/ssr";
|
||||
import { useToast } from "@/components/molecules/Toast/use-toast";
|
||||
import type { UserRateLimitResponse } from "@/lib/autogpt-server-api/types";
|
||||
import { getUserRateLimit, resetUserRateLimit } from "../actions";
|
||||
import type { UserRateLimitResponse } from "@/app/api/__generated__/models/userRateLimitResponse";
|
||||
import {
|
||||
getV2GetUserRateLimit,
|
||||
postV2ResetUserRateLimitUsage,
|
||||
} from "@/app/api/__generated__/endpoints/admin/admin";
|
||||
import { RateLimitDisplay } from "./RateLimitDisplay";
|
||||
|
||||
export function RateLimitManager() {
|
||||
@@ -23,8 +26,11 @@ export function RateLimitManager() {
|
||||
|
||||
setIsLoading(true);
|
||||
try {
|
||||
const data = await getUserRateLimit(trimmed);
|
||||
setRateLimitData(data);
|
||||
const response = await getV2GetUserRateLimit({ user_id: trimmed });
|
||||
if (response.status !== 200) {
|
||||
throw new Error("Failed to fetch rate limit");
|
||||
}
|
||||
setRateLimitData(response.data);
|
||||
} catch (error) {
|
||||
console.error("Error fetching rate limit:", error);
|
||||
toast({
|
||||
@@ -42,8 +48,13 @@ export function RateLimitManager() {
|
||||
if (!rateLimitData) return;
|
||||
|
||||
try {
|
||||
const data = await resetUserRateLimit(rateLimitData.user_id);
|
||||
setRateLimitData(data);
|
||||
const response = await postV2ResetUserRateLimitUsage({
|
||||
user_id: rateLimitData.user_id,
|
||||
});
|
||||
if (response.status !== 200) {
|
||||
throw new Error("Failed to reset usage");
|
||||
}
|
||||
setRateLimitData(response.data);
|
||||
toast({
|
||||
title: "Success",
|
||||
description: "User rate limit usage reset to zero.",
|
||||
|
||||
@@ -53,7 +53,6 @@ import type {
|
||||
TransactionHistory,
|
||||
User,
|
||||
UserPasswordCredentials,
|
||||
UserRateLimitResponse,
|
||||
UsersBalanceHistoryResponse,
|
||||
WebSocketNotification,
|
||||
} from "./types";
|
||||
@@ -481,16 +480,6 @@ export default class BackendAPI {
|
||||
return this._get("/credits/admin/users_history", params);
|
||||
}
|
||||
|
||||
getUserRateLimit(user_id: string): Promise<UserRateLimitResponse> {
|
||||
return this._get("/copilot/admin/rate_limit", { user_id });
|
||||
}
|
||||
|
||||
resetUserRateLimit(user_id: string): Promise<UserRateLimitResponse> {
|
||||
return this._request("POST", "/copilot/admin/rate_limit/reset", {
|
||||
user_id,
|
||||
});
|
||||
}
|
||||
|
||||
////////////////////////////////////////
|
||||
//////////// V2 LIBRARY API ////////////
|
||||
////////////////////////////////////////
|
||||
|
||||
@@ -965,14 +965,6 @@ export type AddUserCreditsResponse = {
|
||||
transaction_key: string;
|
||||
};
|
||||
|
||||
export type UserRateLimitResponse = {
|
||||
user_id: string;
|
||||
daily_token_limit: number;
|
||||
weekly_token_limit: number;
|
||||
daily_tokens_used: number;
|
||||
weekly_tokens_used: number;
|
||||
};
|
||||
|
||||
const _stringFormatToDataTypeMap: Partial<Record<string, DataType>> = {
|
||||
date: DataType.DATE,
|
||||
time: DataType.TIME,
|
||||
|
||||
Reference in New Issue
Block a user