Skip to content

Commit

Permalink
feat(frontend): add marketplace server side client (#8129)
Browse files Browse the repository at this point in the history
  • Loading branch information
ntindle authored Sep 23, 2024
1 parent 6e205cb commit 198a104
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 22 deletions.
17 changes: 9 additions & 8 deletions .vscode/all-projects.code-workspace
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
{
"folders": [
{
"name": "autogpt_server",
"path": "../autogpt_platform/autogpt_server"
"name": "frontend",
"path": "../autogpt_platform/frontend"
},
{
"name": "autogpt_builder",
"path": "../autogpt_platform/autogpt_builder"
"name": "backend",
"path": "../autogpt_platform/backend"
},
{
"name": "market",
Expand All @@ -24,10 +24,7 @@
"name": "docs",
"path": "../docs"
},
{
"name": "[root]",
"path": ".."
},

{
"name": "classic - autogpt",
"path": "../classic/original_autogpt"
Expand All @@ -44,6 +41,10 @@
"name": "classic - frontend",
"path": "../classic/frontend"
},
{
"name": "[root]",
"path": ".."
}
],
"settings": {
"python.analysis.typeCheckingMode": "basic"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"use server";
import MarketplaceAPI from "@/lib/marketplace-api";
import ServerSideMarketplaceAPI from "@/lib/marketplace-api/server-client";
import { revalidatePath } from "next/cache";
import * as Sentry from "@sentry/nextjs";

Expand All @@ -12,7 +13,7 @@ export async function approveAgent(
"approveAgent",
{},
async () => {
const api = new MarketplaceAPI();
const api = new ServerSideMarketplaceAPI();
await api.approveAgentSubmission(agentId, version, comment);
console.debug(`Approving agent ${agentId}`);
revalidatePath("/marketplace");
Expand All @@ -29,7 +30,7 @@ export async function rejectAgent(
"rejectAgent",
{},
async () => {
const api = new MarketplaceAPI();
const api = new ServerSideMarketplaceAPI();
await api.rejectAgentSubmission(agentId, version, comment);
console.debug(`Rejecting agent ${agentId}`);
revalidatePath("/marketplace");
Expand All @@ -42,7 +43,7 @@ export async function getReviewableAgents() {
"getReviewableAgents",
{},
async () => {
const api = new MarketplaceAPI();
const api = new ServerSideMarketplaceAPI();
return api.getAgentSubmissions();
},
);
Expand All @@ -56,7 +57,7 @@ export async function getFeaturedAgents(
"getFeaturedAgents",
{},
async () => {
const api = new MarketplaceAPI();
const api = new ServerSideMarketplaceAPI();
const featured = await api.getFeaturedAgents(page, pageSize);
console.debug(`Getting featured agents ${featured.agents.length}`);
return featured;
Expand All @@ -69,7 +70,7 @@ export async function getFeaturedAgent(agentId: string) {
"getFeaturedAgent",
{},
async () => {
const api = new MarketplaceAPI();
const api = new ServerSideMarketplaceAPI();
const featured = await api.getFeaturedAgent(agentId);
console.debug(`Getting featured agent ${featured.agentId}`);
return featured;
Expand All @@ -85,7 +86,7 @@ export async function addFeaturedAgent(
"addFeaturedAgent",
{},
async () => {
const api = new MarketplaceAPI();
const api = new ServerSideMarketplaceAPI();
await api.addFeaturedAgent(agentId, categories);
console.debug(`Adding featured agent ${agentId}`);
revalidatePath("/marketplace");
Expand All @@ -101,7 +102,7 @@ export async function removeFeaturedAgent(
"removeFeaturedAgent",
{},
async () => {
const api = new MarketplaceAPI();
const api = new ServerSideMarketplaceAPI();
await api.removeFeaturedAgent(agentId, categories);
console.debug(`Removing featured agent ${agentId}`);
revalidatePath("/marketplace");
Expand All @@ -114,7 +115,7 @@ export async function getCategories() {
"getCategories",
{},
async () => {
const api = new MarketplaceAPI();
const api = new ServerSideMarketplaceAPI();
const categories = await api.getCategories();
console.debug(
`Getting categories ${categories.unique_categories.length}`,
Expand All @@ -132,7 +133,7 @@ export async function getNotFeaturedAgents(
"getNotFeaturedAgents",
{},
async () => {
const api = new MarketplaceAPI();
const api = new ServerSideMarketplaceAPI();
const agents = await api.getNotFeaturedAgents(page, pageSize);
console.debug(`Getting not featured agents ${agents.agents.length}`);
return agents;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { createClient } from "../supabase/client";
import { SupabaseClient } from "@supabase/supabase-js";
import {
AddAgentRequest,
AgentResponse,
Expand All @@ -11,15 +11,17 @@ import {
AnalyticsEvent,
} from "./types";

export default class MarketplaceAPI {
export default class BaseMarketplaceAPI {
private baseUrl: string;
private supabaseClient = createClient();
private supabaseClient: SupabaseClient | null = null;

constructor(
baseUrl: string = process.env.NEXT_PUBLIC_AGPT_MARKETPLACE_URL ||
"http://localhost:8015/api/v1/market",
supabaseClient: SupabaseClient | null = null,
) {
this.baseUrl = baseUrl;
this.supabaseClient = supabaseClient;
}

async checkHealth(): Promise<{ status: string }> {
Expand Down Expand Up @@ -262,7 +264,15 @@ export default class MarketplaceAPI {
response_data.detail,
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;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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);
}
}
2 changes: 1 addition & 1 deletion autogpt_platform/frontend/src/lib/marketplace-api/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import MarketplaceAPI from "./client";
import MarketplaceAPI from "./browser-client";

export default MarketplaceAPI;
export * from "./types";
12 changes: 12 additions & 0 deletions autogpt_platform/frontend/src/lib/marketplace-api/server-client.ts
Original file line number Diff line number Diff line change
@@ -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);
}
}

0 comments on commit 198a104

Please sign in to comment.