feat: add NEXT_PUBLIC_BACKEND_BASE_URL

This commit is contained in:
Henry Li
2026-01-19 11:23:40 +08:00
parent b431567666
commit 9d18e4e12d
5 changed files with 19 additions and 10 deletions

View File

@@ -2,16 +2,12 @@
import { Client as LangGraphClient } from "@langchain/langgraph-sdk/client";
import { getBackendBaseURL } from "../config";
let _singleton: LangGraphClient | null = null;
export function getAPIClient(): LangGraphClient {
let url: URL | null = null;
if (typeof window === "undefined") {
url = new URL("/api/langgraph", "http://localhost:3000");
} else {
url = new URL("/api/langgraph", window.location.origin);
}
_singleton ??= new LangGraphClient({
apiUrl: "http://localhost:2024",
apiUrl: getBackendBaseURL(),
});
return _singleton;
}

View File

@@ -1,3 +1,4 @@
import { getBackendBaseURL } from "../config";
import type { AgentThread } from "../threads";
export function urlOfArtifact({
@@ -9,7 +10,7 @@ export function urlOfArtifact({
threadId: string;
download?: boolean;
}) {
return `http://localhost:8000/api/threads/${threadId}/artifacts${filepath}${download ? "?download=true" : ""}`;
return `${getBackendBaseURL()}/api/threads/${threadId}/artifacts${filepath}${download ? "?download=true" : ""}`;
}
export function extractArtifactsFromThread(thread: AgentThread) {

View File

@@ -0,0 +1,5 @@
import { env } from "@/env";
export function getBackendBaseURL() {
return env.NEXT_PUBLIC_BACKEND_BASE_URL ?? "http://localhost:8000";
}