Skip to content

Commit 1959e87

Browse files
authored
Merge branch 'master' into zamilmajdy/make-api-host-configurable
2 parents 74c2ef6 + 198a104 commit 1959e87

File tree

9 files changed

+95
-26
lines changed

9 files changed

+95
-26
lines changed

.vscode/all-projects.code-workspace

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
{
22
"folders": [
33
{
4-
"name": "autogpt_server",
5-
"path": "../autogpt_platform/autogpt_server"
4+
"name": "frontend",
5+
"path": "../autogpt_platform/frontend"
66
},
77
{
8-
"name": "autogpt_builder",
9-
"path": "../autogpt_platform/autogpt_builder"
8+
"name": "backend",
9+
"path": "../autogpt_platform/backend"
1010
},
1111
{
1212
"name": "market",
@@ -24,10 +24,7 @@
2424
"name": "docs",
2525
"path": "../docs"
2626
},
27-
{
28-
"name": "[root]",
29-
"path": ".."
30-
},
27+
3128
{
3229
"name": "classic - autogpt",
3330
"path": "../classic/original_autogpt"
@@ -44,6 +41,10 @@
4441
"name": "classic - frontend",
4542
"path": "../classic/frontend"
4643
},
44+
{
45+
"name": "[root]",
46+
"path": ".."
47+
}
4748
],
4849
"settings": {
4950
"python.analysis.typeCheckingMode": "basic"

autogpt_platform/frontend/src/components/CreditButton.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import { useState, useEffect } from "react";
44
import { Button } from "@/components/ui/button";
5-
import { IconRefresh } from "@/components/ui/icons";
5+
import { IconRefresh, IconCoin } from "@/components/ui/icons";
66
import AutoGPTServerAPI from "@/lib/autogpt-server-api";
77

88
export default function CreditButton() {
@@ -24,7 +24,9 @@ export default function CreditButton() {
2424
variant="outline"
2525
className="flex items-center space-x-2 text-muted-foreground"
2626
>
27-
<span>Credits: {credit}</span>
27+
<span className="flex items-center">
28+
<IconCoin /> {credit}
29+
</span>
2830
<IconRefresh />
2931
</Button>
3032
)

autogpt_platform/frontend/src/components/CustomNode.tsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ import { getPrimaryCategoryColor } from "@/lib/utils";
3333
import { FlowContext } from "./Flow";
3434
import { Badge } from "./ui/badge";
3535
import DataTable from "./DataTable";
36+
import { IconCoin } from "./ui/icons";
3637

3738
type ParsedKey = { key: string; index?: number };
3839

@@ -577,8 +578,10 @@ export function CustomNode({ data, id, width, height }: NodeProps<CustomNode>) {
577578
</div>
578579
</div>
579580
{blockCost && (
580-
<div className="p-3 text-right font-semibold">
581-
Cost: {blockCost.cost_amount} / {blockCost.cost_type}
581+
<div className="p-3 font-semibold">
582+
<span className="ml-auto flex items-center">
583+
<IconCoin /> {blockCost.cost_amount} per {blockCost.cost_type}
584+
</span>
582585
</div>
583586
)}
584587
{data.uiType !== BlockUIType.NOTE ? (

autogpt_platform/frontend/src/components/admin/marketplace/actions.ts

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
"use server";
22
import MarketplaceAPI from "@/lib/marketplace-api";
3+
import ServerSideMarketplaceAPI from "@/lib/marketplace-api/server-client";
34
import { revalidatePath } from "next/cache";
45
import * as Sentry from "@sentry/nextjs";
56

@@ -12,7 +13,7 @@ export async function approveAgent(
1213
"approveAgent",
1314
{},
1415
async () => {
15-
const api = new MarketplaceAPI();
16+
const api = new ServerSideMarketplaceAPI();
1617
await api.approveAgentSubmission(agentId, version, comment);
1718
console.debug(`Approving agent ${agentId}`);
1819
revalidatePath("/marketplace");
@@ -29,7 +30,7 @@ export async function rejectAgent(
2930
"rejectAgent",
3031
{},
3132
async () => {
32-
const api = new MarketplaceAPI();
33+
const api = new ServerSideMarketplaceAPI();
3334
await api.rejectAgentSubmission(agentId, version, comment);
3435
console.debug(`Rejecting agent ${agentId}`);
3536
revalidatePath("/marketplace");
@@ -42,7 +43,7 @@ export async function getReviewableAgents() {
4243
"getReviewableAgents",
4344
{},
4445
async () => {
45-
const api = new MarketplaceAPI();
46+
const api = new ServerSideMarketplaceAPI();
4647
return api.getAgentSubmissions();
4748
},
4849
);
@@ -56,7 +57,7 @@ export async function getFeaturedAgents(
5657
"getFeaturedAgents",
5758
{},
5859
async () => {
59-
const api = new MarketplaceAPI();
60+
const api = new ServerSideMarketplaceAPI();
6061
const featured = await api.getFeaturedAgents(page, pageSize);
6162
console.debug(`Getting featured agents ${featured.agents.length}`);
6263
return featured;
@@ -69,7 +70,7 @@ export async function getFeaturedAgent(agentId: string) {
6970
"getFeaturedAgent",
7071
{},
7172
async () => {
72-
const api = new MarketplaceAPI();
73+
const api = new ServerSideMarketplaceAPI();
7374
const featured = await api.getFeaturedAgent(agentId);
7475
console.debug(`Getting featured agent ${featured.agentId}`);
7576
return featured;
@@ -85,7 +86,7 @@ export async function addFeaturedAgent(
8586
"addFeaturedAgent",
8687
{},
8788
async () => {
88-
const api = new MarketplaceAPI();
89+
const api = new ServerSideMarketplaceAPI();
8990
await api.addFeaturedAgent(agentId, categories);
9091
console.debug(`Adding featured agent ${agentId}`);
9192
revalidatePath("/marketplace");
@@ -101,7 +102,7 @@ export async function removeFeaturedAgent(
101102
"removeFeaturedAgent",
102103
{},
103104
async () => {
104-
const api = new MarketplaceAPI();
105+
const api = new ServerSideMarketplaceAPI();
105106
await api.removeFeaturedAgent(agentId, categories);
106107
console.debug(`Removing featured agent ${agentId}`);
107108
revalidatePath("/marketplace");
@@ -114,7 +115,7 @@ export async function getCategories() {
114115
"getCategories",
115116
{},
116117
async () => {
117-
const api = new MarketplaceAPI();
118+
const api = new ServerSideMarketplaceAPI();
118119
const categories = await api.getCategories();
119120
console.debug(
120121
`Getting categories ${categories.unique_categories.length}`,
@@ -132,7 +133,7 @@ export async function getNotFeaturedAgents(
132133
"getNotFeaturedAgents",
133134
{},
134135
async () => {
135-
const api = new MarketplaceAPI();
136+
const api = new ServerSideMarketplaceAPI();
136137
const agents = await api.getNotFeaturedAgents(page, pageSize);
137138
console.debug(`Getting not featured agents ${agents.agents.length}`);
138139
return agents;

autogpt_platform/frontend/src/components/ui/icons.tsx

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,34 @@ export const IconRefresh = createIcon((props) => (
301301
</svg>
302302
));
303303

304+
/**
305+
* Coin icon component.
306+
*
307+
* @component IconCoin
308+
* @param {IconProps} props - The props object containing additional attributes and event handlers for the icon.
309+
* @returns {JSX.Element} - The coins icon.
310+
*
311+
*/
312+
export const IconCoin = createIcon((props) => (
313+
<svg
314+
xmlns="http://www.w3.org/2000/svg"
315+
width="24"
316+
height="24"
317+
viewBox="0 0 24 24"
318+
fill="none"
319+
stroke="currentColor"
320+
strokeWidth="2"
321+
strokeLinecap="round"
322+
strokeLinejoin="round"
323+
{...props}
324+
>
325+
<circle cx="8" cy="8" r="6" />
326+
<path d="M18.09 10.37A6 6 0 1 1 10.34 18" />
327+
<path d="M7 6h1v4" />
328+
<path d="m16.71 13.88.7.71-2.82 2.82" />
329+
</svg>
330+
));
331+
304332
/**
305333
* Menu icon component.
306334
*

autogpt_platform/frontend/src/lib/marketplace-api/client.ts renamed to autogpt_platform/frontend/src/lib/marketplace-api/base-client.ts

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { createClient } from "../supabase/client";
1+
import { SupabaseClient } from "@supabase/supabase-js";
22
import {
33
AddAgentRequest,
44
AgentResponse,
@@ -11,15 +11,17 @@ import {
1111
AnalyticsEvent,
1212
} from "./types";
1313

14-
export default class MarketplaceAPI {
14+
export default class BaseMarketplaceAPI {
1515
private baseUrl: string;
16-
private supabaseClient = createClient();
16+
private supabaseClient: SupabaseClient | null = null;
1717

1818
constructor(
1919
baseUrl: string = process.env.NEXT_PUBLIC_AGPT_MARKETPLACE_URL ||
2020
"http://localhost:8015/api/v1/market",
21+
supabaseClient: SupabaseClient | null = null,
2122
) {
2223
this.baseUrl = baseUrl;
24+
this.supabaseClient = supabaseClient;
2325
}
2426

2527
async checkHealth(): Promise<{ status: string }> {
@@ -262,7 +264,15 @@ export default class MarketplaceAPI {
262264
response_data.detail,
263265
response,
264266
);
265-
throw new Error(`HTTP error ${response.status}! ${response_data.detail}`);
267+
try {
268+
const response_data = await response.json();
269+
} catch (e) {
270+
console.warn("Failed to parse response body", e);
271+
}
272+
273+
throw new Error(
274+
`HTTP error ${response.status}! ${response_data.detail} ${method} ${response.url}`,
275+
);
266276
}
267277
return response_data;
268278
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { createClient } from "../supabase/client";
2+
import BaseMarketplaceAPI from "./base-client";
3+
4+
export default class ClientSideMarketplaceAPI extends BaseMarketplaceAPI {
5+
constructor(
6+
baseUrl: string = process.env.NEXT_PUBLIC_AGPT_MARKETPLACE_URL ||
7+
"http://localhost:8015/api/v1/market",
8+
) {
9+
const supabaseClient = createClient();
10+
super(baseUrl, supabaseClient);
11+
}
12+
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import MarketplaceAPI from "./client";
1+
import MarketplaceAPI from "./browser-client";
22

33
export default MarketplaceAPI;
44
export * from "./types";
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { createServerClient } from "../supabase/server";
2+
import BaseMarketplaceAPI from "./base-client";
3+
4+
export default class ServerSideMarketplaceAPI extends BaseMarketplaceAPI {
5+
constructor(
6+
baseUrl: string = process.env.NEXT_PUBLIC_AGPT_MARKETPLACE_URL ||
7+
"http://localhost:8015/api/v1/market",
8+
) {
9+
const supabaseClient = createServerClient();
10+
super(baseUrl, supabaseClient);
11+
}
12+
}

0 commit comments

Comments
 (0)