feat(frontend): 步骤 6.3 — 类型定义与 API 配置

This commit is contained in:
hhs
2026-06-10 15:23:52 +08:00
parent a6667e0a33
commit 3041ce770f
3 changed files with 47 additions and 0 deletions

View File

@@ -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"),
};

31
frontend/src/types/api.ts Normal file
View File

@@ -0,0 +1,31 @@
export interface Response<T> {
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;
}

9
frontend/src/types/env.d.ts vendored Normal file
View File

@@ -0,0 +1,9 @@
declare global {
interface Window {
__ENV?: {
NEXT_PUBLIC_API_BASE_URL: string;
};
}
}
export {};