From 3041ce770fdf367b73c458f720016a2b0f5c2de7 Mon Sep 17 00:00:00 2001 From: hhs <386998068@qq.com> Date: Wed, 10 Jun 2026 15:23:52 +0800 Subject: [PATCH] =?UTF-8?q?feat(frontend):=20=E6=AD=A5=E9=AA=A4=206.3=20?= =?UTF-8?q?=E2=80=94=20=E7=B1=BB=E5=9E=8B=E5=AE=9A=E4=B9=89=E4=B8=8E=20API?= =?UTF-8?q?=20=E9=85=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- frontend/src/config/api-config.ts | 7 +++++++ frontend/src/types/api.ts | 31 +++++++++++++++++++++++++++++++ frontend/src/types/env.d.ts | 9 +++++++++ 3 files changed, 47 insertions(+) create mode 100644 frontend/src/config/api-config.ts create mode 100644 frontend/src/types/api.ts create mode 100644 frontend/src/types/env.d.ts diff --git a/frontend/src/config/api-config.ts b/frontend/src/config/api-config.ts new file mode 100644 index 0000000..f06e944 --- /dev/null +++ b/frontend/src/config/api-config.ts @@ -0,0 +1,7 @@ +export const API_CONFIG = { + // 优先使用运行时注入的 window.__ENV,其次使用构建时的环境变量,最后回退到默认值 + BASE_URL: + (typeof window !== "undefined" && window.__ENV?.NEXT_PUBLIC_API_BASE_URL) + ? window.__ENV.NEXT_PUBLIC_API_BASE_URL + : (process.env.NEXT_PUBLIC_API_BASE_URL || "http://localhost:8091/api/v1"), +}; diff --git a/frontend/src/types/api.ts b/frontend/src/types/api.ts new file mode 100644 index 0000000..7a92801 --- /dev/null +++ b/frontend/src/types/api.ts @@ -0,0 +1,31 @@ +export interface Response { + code: string; + info: string; + data: T; +} + +export interface AiAgentConfigResponseDTO { + agentId: string; + agentName: string; + agentDesc: string; +} + +export interface CreateSessionRequestDTO { + agentId: string; + userId: string; +} + +export interface CreateSessionResponseDTO { + sessionId: string; +} + +export interface ChatRequestDTO { + agentId: string; + userId: string; + sessionId: string; + message: string; +} + +export interface ChatResponseDTO { + content: string; +} diff --git a/frontend/src/types/env.d.ts b/frontend/src/types/env.d.ts new file mode 100644 index 0000000..759c9bc --- /dev/null +++ b/frontend/src/types/env.d.ts @@ -0,0 +1,9 @@ +declare global { + interface Window { + __ENV?: { + NEXT_PUBLIC_API_BASE_URL: string; + }; + } +} + +export {};