- deleteSessionV2 请求方式 post → delete(/ai-agent/session/delete) - 工作空间删除:缺少删除信息提示不可删;接口失败保留数据;成功才移除本地并刷新工作空间树 - 会话记录删除:已认领后端号的会话接口失败保留数据且不打断连接;成功才 teardown/关闭并刷新列表; 未认领的本地虚拟会话直接本地删除 Co-Authored-By: Claude <noreply@anthropic.com>
124 lines
4.1 KiB
TypeScript
124 lines
4.1 KiB
TypeScript
import request, { type RequestOptions } from '/@/utils/request';
|
||
|
||
// ===== 会话管理(/ai-agent/session/*)=====
|
||
// 后端结构:
|
||
// ListSessionReq { page } → ListSessionRes { list: VOSession[], total }
|
||
// GetSessionInfoReq { page, sessionId } → GetSessionInfoRes { list: VOSessionInfoResult[], total }
|
||
// DeleteSessionReq { sessionId }(POST,级联删除普通对话结果,工作流结果保留)
|
||
// 说明:会话为「会话 → 会话内结果(工作流/普通对话混排,按时间倒序)」模型。
|
||
|
||
export interface VOSession {
|
||
id: string;
|
||
sessionName: string;
|
||
createdAt: string;
|
||
}
|
||
|
||
export interface VOSessionInfoResult {
|
||
id: string;
|
||
type: 'workflow' | 'chat';
|
||
status: number; // 1-运行中, 2-成功, 3-失败
|
||
flowId: string;
|
||
requestParams: Record<string, any>;
|
||
resultFileUrl: string; // 产出文件地址(单文件;工作流执行成功时后端填写,空串表示无产出)
|
||
resultContent: string; // 回复文本内容(非文件地址)
|
||
totalTokens: number;
|
||
totalFee: number;
|
||
errorMsg: string;
|
||
createdAt: string;
|
||
}
|
||
|
||
export function getSessionListV2(params?: Record<string, any>, requestOptions?: RequestOptions) {
|
||
return request({
|
||
url: '/ai-agent/session/list',
|
||
method: 'get',
|
||
params,
|
||
requestOptions,
|
||
}) as Promise<{ code: number; message: string; data: { list: VOSession[]; total: number } }>;
|
||
}
|
||
|
||
export function getSessionResults(sessionId: string, params?: Record<string, any>, requestOptions?: RequestOptions) {
|
||
return request({
|
||
url: '/ai-agent/session/get',
|
||
method: 'get',
|
||
params: { sessionId, ...params },
|
||
requestOptions,
|
||
}) as Promise<{ code: number; message: string; data: { list: VOSessionInfoResult[]; total: number } }>;
|
||
}
|
||
|
||
export function deleteSessionV2(sessionId: string, requestOptions?: RequestOptions) {
|
||
return request({
|
||
url: '/ai-agent/session/delete',
|
||
method: 'delete',
|
||
data: { sessionId },
|
||
requestOptions,
|
||
});
|
||
}
|
||
|
||
// 删除会话内的对话记录(AI 回复 / 用户问题单条或多条),传 Ids 数组,每项为 { id, type }
|
||
// 注意:记录 id 为 19 位雪花大整数,超出 JS Number 安全范围,必须用 string 形式传递,否则精度丢失
|
||
export function deleteSessionRecord(ids: { id: string; type: string }[], requestOptions?: RequestOptions) {
|
||
return request({
|
||
url: '/ai-agent/session/deleteRecord',
|
||
method: 'post',
|
||
data: { ids },
|
||
requestOptions,
|
||
});
|
||
}
|
||
|
||
// ===== 工作空间结果列表(/ai-agent/session/resultList)=====
|
||
// 与内容创作 execution/list 同结构:data.tree(按 createDate 分组)+ data.imgAddressPrefix
|
||
export interface ExecutionItem {
|
||
// 兼容旧平铺结构;resultList 新结构下 items 无独立 id,删除按流程记录 flow.Id
|
||
id?: string;
|
||
timestamp?: string;
|
||
content: string;
|
||
label: string;
|
||
type?: string;
|
||
}
|
||
|
||
// resultList 新两级结构:createDate → flows(流程分组)→ items(文件)
|
||
export interface ExecutionFlow {
|
||
flowName: string;
|
||
Id: string; // 流程结果记录 id(雪花)
|
||
sessionId: string;
|
||
items: ExecutionItem[];
|
||
}
|
||
|
||
export interface ExecutionTreeItem {
|
||
createDate: string;
|
||
// 新结构:日期下按流程分组;兼容旧平铺结构(无 flows 时回落 items)
|
||
flows?: ExecutionFlow[];
|
||
items?: ExecutionItem[];
|
||
}
|
||
|
||
export interface ExecutionListData {
|
||
tree: ExecutionTreeItem[];
|
||
imgAddressPrefix: string;
|
||
}
|
||
|
||
export interface ExecutionListResponse {
|
||
code: number;
|
||
message: string;
|
||
data: ExecutionListData;
|
||
}
|
||
|
||
/** 获取工作空间结果列表(结果树) */
|
||
export function getWorkspaceResultList(params?: Record<string, any>, requestOptions?: RequestOptions) {
|
||
return request({
|
||
url: '/ai-agent/session/resultList',
|
||
method: 'get',
|
||
params,
|
||
requestOptions,
|
||
}) as Promise<ExecutionListResponse>;
|
||
}
|
||
|
||
/** 删除工作空间结果(单个文件)——工作流域独立接口,不依赖内容创作域 */
|
||
export function deleteWorkspaceResult(data: { id: string; content: string }, requestOptions?: RequestOptions) {
|
||
return request({
|
||
url: '/ai-agent/session/resultDelete',
|
||
method: 'delete',
|
||
data,
|
||
requestOptions,
|
||
});
|
||
}
|