Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(frontend): Automatically choose client/server-side API client #8916

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
"use client";

import { createClient } from "../supabase/client";
import BaseAutoGPTServerAPI from "./baseClient";

export class AutoGPTServerAPIClientSide extends BaseAutoGPTServerAPI {
constructor(
baseUrl: string = process.env.NEXT_PUBLIC_AGPT_SERVER_URL ||
"http://localhost:8006/api",
wsUrl: string = process.env.NEXT_PUBLIC_AGPT_WS_SERVER_URL ||
"ws://localhost:8001/ws",
) {
const supabaseClient = createClient();
super(baseUrl, wsUrl, supabaseClient);
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
"use server";

import { createServerClient } from "../supabase/server";
import BaseAutoGPTServerAPI from "./baseClient";

export default class AutoGPTServerAPIServerSide extends BaseAutoGPTServerAPI {
export class AutoGPTServerAPIServerSide extends BaseAutoGPTServerAPI {
constructor(
baseUrl: string = process.env.NEXT_PUBLIC_AGPT_SERVER_URL ||
"http://localhost:8006/api",
Expand Down
23 changes: 10 additions & 13 deletions autogpt_platform/frontend/src/lib/autogpt-server-api/client.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
import { createClient } from "../supabase/client";
import BaseAutoGPTServerAPI from "./baseClient";
import { AutoGPTServerAPIClientSide } from "./client-client";
import { AutoGPTServerAPIServerSide } from "./client-server";

export class AutoGPTServerAPI extends BaseAutoGPTServerAPI {
constructor(
baseUrl: string = process.env.NEXT_PUBLIC_AGPT_SERVER_URL ||
"http://localhost:8006/api",
wsUrl: string = process.env.NEXT_PUBLIC_AGPT_WS_SERVER_URL ||
"ws://localhost:8001/ws",
) {
const supabaseClient = createClient();
super(baseUrl, wsUrl, supabaseClient);
}
}
export const AutoGPTServerAPI =
typeof window !== "undefined"
? AutoGPTServerAPIClientSide
: AutoGPTServerAPIServerSide;

export type AutoGPTServerAPI =
| AutoGPTServerAPIClientSide
| AutoGPTServerAPIServerSide;
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { AutoGPTServerAPI } from "./client";

// TODO: rename to BackendAPI
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not do this in this PR?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Out of scope, would cause a huge amount of changes and also conflicts on ongoing PRs

export default AutoGPTServerAPI;
export * from "./client";
export * from "./context";
Expand Down
Loading