feat(frontend): add marketplace server side client (#8129)
parent
6e205cb850
commit
198a1048e8
|
@ -1,12 +1,12 @@
|
||||||
{
|
{
|
||||||
"folders": [
|
"folders": [
|
||||||
{
|
{
|
||||||
"name": "autogpt_server",
|
"name": "frontend",
|
||||||
"path": "../autogpt_platform/autogpt_server"
|
"path": "../autogpt_platform/frontend"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "autogpt_builder",
|
"name": "backend",
|
||||||
"path": "../autogpt_platform/autogpt_builder"
|
"path": "../autogpt_platform/backend"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "market",
|
"name": "market",
|
||||||
|
@ -24,10 +24,7 @@
|
||||||
"name": "docs",
|
"name": "docs",
|
||||||
"path": "../docs"
|
"path": "../docs"
|
||||||
},
|
},
|
||||||
{
|
|
||||||
"name": "[root]",
|
|
||||||
"path": ".."
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
"name": "classic - autogpt",
|
"name": "classic - autogpt",
|
||||||
"path": "../classic/original_autogpt"
|
"path": "../classic/original_autogpt"
|
||||||
|
@ -44,6 +41,10 @@
|
||||||
"name": "classic - frontend",
|
"name": "classic - frontend",
|
||||||
"path": "../classic/frontend"
|
"path": "../classic/frontend"
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"name": "[root]",
|
||||||
|
"path": ".."
|
||||||
|
}
|
||||||
],
|
],
|
||||||
"settings": {
|
"settings": {
|
||||||
"python.analysis.typeCheckingMode": "basic"
|
"python.analysis.typeCheckingMode": "basic"
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
"use server";
|
"use server";
|
||||||
import MarketplaceAPI from "@/lib/marketplace-api";
|
import MarketplaceAPI from "@/lib/marketplace-api";
|
||||||
|
import ServerSideMarketplaceAPI from "@/lib/marketplace-api/server-client";
|
||||||
import { revalidatePath } from "next/cache";
|
import { revalidatePath } from "next/cache";
|
||||||
import * as Sentry from "@sentry/nextjs";
|
import * as Sentry from "@sentry/nextjs";
|
||||||
|
|
||||||
|
@ -12,7 +13,7 @@ export async function approveAgent(
|
||||||
"approveAgent",
|
"approveAgent",
|
||||||
{},
|
{},
|
||||||
async () => {
|
async () => {
|
||||||
const api = new MarketplaceAPI();
|
const api = new ServerSideMarketplaceAPI();
|
||||||
await api.approveAgentSubmission(agentId, version, comment);
|
await api.approveAgentSubmission(agentId, version, comment);
|
||||||
console.debug(`Approving agent ${agentId}`);
|
console.debug(`Approving agent ${agentId}`);
|
||||||
revalidatePath("/marketplace");
|
revalidatePath("/marketplace");
|
||||||
|
@ -29,7 +30,7 @@ export async function rejectAgent(
|
||||||
"rejectAgent",
|
"rejectAgent",
|
||||||
{},
|
{},
|
||||||
async () => {
|
async () => {
|
||||||
const api = new MarketplaceAPI();
|
const api = new ServerSideMarketplaceAPI();
|
||||||
await api.rejectAgentSubmission(agentId, version, comment);
|
await api.rejectAgentSubmission(agentId, version, comment);
|
||||||
console.debug(`Rejecting agent ${agentId}`);
|
console.debug(`Rejecting agent ${agentId}`);
|
||||||
revalidatePath("/marketplace");
|
revalidatePath("/marketplace");
|
||||||
|
@ -42,7 +43,7 @@ export async function getReviewableAgents() {
|
||||||
"getReviewableAgents",
|
"getReviewableAgents",
|
||||||
{},
|
{},
|
||||||
async () => {
|
async () => {
|
||||||
const api = new MarketplaceAPI();
|
const api = new ServerSideMarketplaceAPI();
|
||||||
return api.getAgentSubmissions();
|
return api.getAgentSubmissions();
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
@ -56,7 +57,7 @@ export async function getFeaturedAgents(
|
||||||
"getFeaturedAgents",
|
"getFeaturedAgents",
|
||||||
{},
|
{},
|
||||||
async () => {
|
async () => {
|
||||||
const api = new MarketplaceAPI();
|
const api = new ServerSideMarketplaceAPI();
|
||||||
const featured = await api.getFeaturedAgents(page, pageSize);
|
const featured = await api.getFeaturedAgents(page, pageSize);
|
||||||
console.debug(`Getting featured agents ${featured.agents.length}`);
|
console.debug(`Getting featured agents ${featured.agents.length}`);
|
||||||
return featured;
|
return featured;
|
||||||
|
@ -69,7 +70,7 @@ export async function getFeaturedAgent(agentId: string) {
|
||||||
"getFeaturedAgent",
|
"getFeaturedAgent",
|
||||||
{},
|
{},
|
||||||
async () => {
|
async () => {
|
||||||
const api = new MarketplaceAPI();
|
const api = new ServerSideMarketplaceAPI();
|
||||||
const featured = await api.getFeaturedAgent(agentId);
|
const featured = await api.getFeaturedAgent(agentId);
|
||||||
console.debug(`Getting featured agent ${featured.agentId}`);
|
console.debug(`Getting featured agent ${featured.agentId}`);
|
||||||
return featured;
|
return featured;
|
||||||
|
@ -85,7 +86,7 @@ export async function addFeaturedAgent(
|
||||||
"addFeaturedAgent",
|
"addFeaturedAgent",
|
||||||
{},
|
{},
|
||||||
async () => {
|
async () => {
|
||||||
const api = new MarketplaceAPI();
|
const api = new ServerSideMarketplaceAPI();
|
||||||
await api.addFeaturedAgent(agentId, categories);
|
await api.addFeaturedAgent(agentId, categories);
|
||||||
console.debug(`Adding featured agent ${agentId}`);
|
console.debug(`Adding featured agent ${agentId}`);
|
||||||
revalidatePath("/marketplace");
|
revalidatePath("/marketplace");
|
||||||
|
@ -101,7 +102,7 @@ export async function removeFeaturedAgent(
|
||||||
"removeFeaturedAgent",
|
"removeFeaturedAgent",
|
||||||
{},
|
{},
|
||||||
async () => {
|
async () => {
|
||||||
const api = new MarketplaceAPI();
|
const api = new ServerSideMarketplaceAPI();
|
||||||
await api.removeFeaturedAgent(agentId, categories);
|
await api.removeFeaturedAgent(agentId, categories);
|
||||||
console.debug(`Removing featured agent ${agentId}`);
|
console.debug(`Removing featured agent ${agentId}`);
|
||||||
revalidatePath("/marketplace");
|
revalidatePath("/marketplace");
|
||||||
|
@ -114,7 +115,7 @@ export async function getCategories() {
|
||||||
"getCategories",
|
"getCategories",
|
||||||
{},
|
{},
|
||||||
async () => {
|
async () => {
|
||||||
const api = new MarketplaceAPI();
|
const api = new ServerSideMarketplaceAPI();
|
||||||
const categories = await api.getCategories();
|
const categories = await api.getCategories();
|
||||||
console.debug(
|
console.debug(
|
||||||
`Getting categories ${categories.unique_categories.length}`,
|
`Getting categories ${categories.unique_categories.length}`,
|
||||||
|
@ -132,7 +133,7 @@ export async function getNotFeaturedAgents(
|
||||||
"getNotFeaturedAgents",
|
"getNotFeaturedAgents",
|
||||||
{},
|
{},
|
||||||
async () => {
|
async () => {
|
||||||
const api = new MarketplaceAPI();
|
const api = new ServerSideMarketplaceAPI();
|
||||||
const agents = await api.getNotFeaturedAgents(page, pageSize);
|
const agents = await api.getNotFeaturedAgents(page, pageSize);
|
||||||
console.debug(`Getting not featured agents ${agents.agents.length}`);
|
console.debug(`Getting not featured agents ${agents.agents.length}`);
|
||||||
return agents;
|
return agents;
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
import { createClient } from "../supabase/client";
|
import { SupabaseClient } from "@supabase/supabase-js";
|
||||||
import {
|
import {
|
||||||
AddAgentRequest,
|
AddAgentRequest,
|
||||||
AgentResponse,
|
AgentResponse,
|
||||||
|
@ -11,15 +11,17 @@ import {
|
||||||
AnalyticsEvent,
|
AnalyticsEvent,
|
||||||
} from "./types";
|
} from "./types";
|
||||||
|
|
||||||
export default class MarketplaceAPI {
|
export default class BaseMarketplaceAPI {
|
||||||
private baseUrl: string;
|
private baseUrl: string;
|
||||||
private supabaseClient = createClient();
|
private supabaseClient: SupabaseClient | null = null;
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
baseUrl: string = process.env.NEXT_PUBLIC_AGPT_MARKETPLACE_URL ||
|
baseUrl: string = process.env.NEXT_PUBLIC_AGPT_MARKETPLACE_URL ||
|
||||||
"http://localhost:8015/api/v1/market",
|
"http://localhost:8015/api/v1/market",
|
||||||
|
supabaseClient: SupabaseClient | null = null,
|
||||||
) {
|
) {
|
||||||
this.baseUrl = baseUrl;
|
this.baseUrl = baseUrl;
|
||||||
|
this.supabaseClient = supabaseClient;
|
||||||
}
|
}
|
||||||
|
|
||||||
async checkHealth(): Promise<{ status: string }> {
|
async checkHealth(): Promise<{ status: string }> {
|
||||||
|
@ -262,7 +264,15 @@ export default class MarketplaceAPI {
|
||||||
response_data.detail,
|
response_data.detail,
|
||||||
response,
|
response,
|
||||||
);
|
);
|
||||||
throw new Error(`HTTP error ${response.status}! ${response_data.detail}`);
|
try {
|
||||||
|
const response_data = await response.json();
|
||||||
|
} catch (e) {
|
||||||
|
console.warn("Failed to parse response body", e);
|
||||||
|
}
|
||||||
|
|
||||||
|
throw new Error(
|
||||||
|
`HTTP error ${response.status}! ${response_data.detail} ${method} ${response.url}`,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
return response_data;
|
return response_data;
|
||||||
}
|
}
|
|
@ -0,0 +1,12 @@
|
||||||
|
import { createClient } from "../supabase/client";
|
||||||
|
import BaseMarketplaceAPI from "./base-client";
|
||||||
|
|
||||||
|
export default class ClientSideMarketplaceAPI extends BaseMarketplaceAPI {
|
||||||
|
constructor(
|
||||||
|
baseUrl: string = process.env.NEXT_PUBLIC_AGPT_MARKETPLACE_URL ||
|
||||||
|
"http://localhost:8015/api/v1/market",
|
||||||
|
) {
|
||||||
|
const supabaseClient = createClient();
|
||||||
|
super(baseUrl, supabaseClient);
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,4 +1,4 @@
|
||||||
import MarketplaceAPI from "./client";
|
import MarketplaceAPI from "./browser-client";
|
||||||
|
|
||||||
export default MarketplaceAPI;
|
export default MarketplaceAPI;
|
||||||
export * from "./types";
|
export * from "./types";
|
||||||
|
|
|
@ -0,0 +1,12 @@
|
||||||
|
import { createServerClient } from "../supabase/server";
|
||||||
|
import BaseMarketplaceAPI from "./base-client";
|
||||||
|
|
||||||
|
export default class ServerSideMarketplaceAPI extends BaseMarketplaceAPI {
|
||||||
|
constructor(
|
||||||
|
baseUrl: string = process.env.NEXT_PUBLIC_AGPT_MARKETPLACE_URL ||
|
||||||
|
"http://localhost:8015/api/v1/market",
|
||||||
|
) {
|
||||||
|
const supabaseClient = createServerClient();
|
||||||
|
super(baseUrl, supabaseClient);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue