feat(frontend): 步骤 6.3 — 类型定义与 API 配置
This commit is contained in:
7
frontend/src/config/api-config.ts
Normal file
7
frontend/src/config/api-config.ts
Normal 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
31
frontend/src/types/api.ts
Normal 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
9
frontend/src/types/env.d.ts
vendored
Normal file
@@ -0,0 +1,9 @@
|
||||
declare global {
|
||||
interface Window {
|
||||
__ENV?: {
|
||||
NEXT_PUBLIC_API_BASE_URL: string;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
export {};
|
||||
Reference in New Issue
Block a user