feat: 接口统一优化

This commit is contained in:
2026-05-23 13:45:58 +08:00
parent a3b1fba3ea
commit 7d68db723b
20 changed files with 302 additions and 302 deletions
+16 -112
View File
@@ -1,112 +1,16 @@
// app/interfaces/answer.ts - 前端和本地 API 之间使用的响应类型
/** OCS 支持的题型;空字符串表示不指定题型,交给模型根据题目判断 */
export type QuestionType =
| ""
| "single"
| "multiple"
| "judgement"
| "completion";
/** 答题接口请求体,字段名保持旧 Python 服务和 OCS AnswererWrapper 兼容 */
export interface ISearchRequest {
/** 题目正文,必填 */
title: string;
/** 题型,可能为空字符串 */
type: QuestionType | string;
/** 选项文本,多行或 JSON 字符串均按旧逻辑透传给服务端解析 */
options: string;
}
/** 答题成功时返回给 OCS 和前端的结构 */
export interface ISearchSuccessResponse {
/** OCS 约定:1 表示找到答案 */
code: 1;
/** 原题目正文 */
question: string;
/** 最终答案;多选题继续使用 `#` 分隔 */
answer: string;
}
/** 答题失败时返回给 OCS 和前端的结构 */
export interface ISearchErrorResponse {
/** OCS 约定:0 表示失败 */
code: 0;
/** 本地安全错误文案,不包含上游细节 */
msg: string;
}
/** 答题接口联合响应 */
export type ISearchResponse = ISearchSuccessResponse | ISearchErrorResponse;
/** 健康检查响应,只暴露非敏感运行信息 */
export interface IHealthResponse {
/** 服务状态,正常时为 ok */
status: "ok";
/** 本地状态文案 */
message: string;
/** 服务版本 */
version: string;
/** 当前模型名,不包含 API Key 或 baseURL */
model: string;
}
/** 服务统计响应 */
export interface IStatsResponse {
/** 服务版本 */
version: string;
/** 进程运行秒数 */
uptime: number;
/** 当前模型名 */
model: string;
/** 当前用户的问答记录总数 */
qa_records_count: number;
}
/** 最近问答记录,字段来自 server/utils/runtimeState.ts */
export interface IQaRecord {
/** 本地可读时间 */
time: string;
/** ISO 时间,方便排序和调试 */
timestamp: string;
/** 题目正文 */
question: string;
/** 题型 */
type: string;
/** 选项文本 */
options: string;
/** 最终返回给 OCS 的答案 */
answer: string;
}
/** 最近问答记录分页请求 */
export interface IRecordsRequest {
/** 当前页码,从 1 开始 */
page: number;
/** 每页数量 */
size: number;
}
/** 最近问答记录接口响应 */
export interface IRecordsResponse {
/** 管理接口是否成功 */
success: boolean;
/** 失败时的本地安全文案 */
message?: string;
/** 当前页问答记录,最新在前 */
records: IQaRecord[];
/** 当前页码,从 1 开始 */
page: number;
/** 每页数量 */
size: number;
/** 当前进程内问答记录总数 */
total: number;
}
/** 清空缓存接口响应 */
export interface IClearCacheResponse {
/** 是否清理成功;缓存关闭时为 false */
success: boolean;
/** 本地状态文案 */
message: string;
}
// app/interfaces/answer.ts - 从 shared/types/answer.ts 重新导出,前端直接使用 @/interfaces 路径无需改动
export type {
IApiResponse,
IClearCacheResponse,
IHealthResponse,
IQaRecord,
IRecordsData,
IRecordsRequest,
IRecordsResponse,
ISearchErrorResponse,
ISearchRequest,
ISearchResponse,
ISearchSuccessResponse,
IStatsResponse,
QuestionType
} from "~~/shared/types/answer";