feat: zod schema (#6740)

* feat: zod schema

move file api

feat: chat and dataset zod

* fix: review

* feat: dataset openapi

* fix: test

* update cr
This commit is contained in:
Archer
2026-04-10 22:55:44 +08:00
committed by GitHub
parent fc6953fcb3
commit 8524487034
202 changed files with 4520 additions and 4175 deletions
@@ -7,7 +7,7 @@ import { ChatRoleEnum } from '@fastgpt/global/core/chat/constants';
import { getNanoid } from '@fastgpt/global/common/string/tools';
import { getUser } from '@test/datas/users';
import { Call } from '@test/utils/request';
import type { getChatRecordsResponse } from '@/pages/api/core/chat/record/getRecords_v2';
import type { GetRecordsV2ResponseType } from '@fastgpt/global/openapi/core/chat/record/api';
// Helper: create a human chat item
async function createHumanItem({
@@ -124,7 +124,7 @@ describe('debugSession/records', () => {
// ── Empty result ──────────────────────────────
it('should return empty list when no chat items exist', async () => {
const res = await Call<any, any, getChatRecordsResponse>(handler, {
const res = await Call<any, any, GetRecordsV2ResponseType>(handler, {
auth: testUser,
body: { skillId, chatId }
});
@@ -153,7 +153,7 @@ describe('debugSession/records', () => {
text: 'pong'
});
const res = await Call<any, any, getChatRecordsResponse>(handler, {
const res = await Call<any, any, GetRecordsV2ResponseType>(handler, {
auth: testUser,
body: { skillId, chatId }
});
@@ -172,7 +172,7 @@ describe('debugSession/records', () => {
text: 'test message'
});
const res = await Call<any, any, getChatRecordsResponse>(handler, {
const res = await Call<any, any, GetRecordsV2ResponseType>(handler, {
auth: testUser,
body: { skillId, chatId }
});
@@ -194,7 +194,7 @@ describe('debugSession/records', () => {
tmbId: testUser.tmbId
});
const res = await Call<any, any, getChatRecordsResponse>(handler, {
const res = await Call<any, any, GetRecordsV2ResponseType>(handler, {
auth: testUser,
body: { skillId, chatId }
});
@@ -217,7 +217,7 @@ describe('debugSession/records', () => {
tmbId: testUser.tmbId
});
const res = await Call<any, any, getChatRecordsResponse>(handler, {
const res = await Call<any, any, GetRecordsV2ResponseType>(handler, {
auth: testUser,
body: { skillId, chatId }
});
@@ -236,7 +236,7 @@ describe('debugSession/records', () => {
});
await MongoChatItem.updateOne({ _id: doc._id }, { $set: { deleteTime: new Date() } });
const res = await Call<any, any, getChatRecordsResponse>(handler, {
const res = await Call<any, any, GetRecordsV2ResponseType>(handler, {
auth: testUser,
body: { skillId, chatId }
});
@@ -258,7 +258,7 @@ describe('debugSession/records', () => {
});
}
const res = await Call<any, any, getChatRecordsResponse>(handler, {
const res = await Call<any, any, GetRecordsV2ResponseType>(handler, {
auth: testUser,
body: { skillId, chatId, pageSize: 3 }
});
@@ -285,7 +285,7 @@ describe('debugSession/records', () => {
// Use the last item's dataId as initialId to anchor at the end
const lastDataId = items[items.length - 1].dataId;
const res = await Call<any, any, getChatRecordsResponse>(handler, {
const res = await Call<any, any, GetRecordsV2ResponseType>(handler, {
auth: testUser,
body: { skillId, chatId, pageSize: 3, initialId: lastDataId }
});
@@ -309,7 +309,7 @@ describe('debugSession/records', () => {
}
// First page: get 2 items
const page1 = await Call<any, any, getChatRecordsResponse>(handler, {
const page1 = await Call<any, any, GetRecordsV2ResponseType>(handler, {
auth: testUser,
body: { skillId, chatId, pageSize: 2 }
});
@@ -319,7 +319,7 @@ describe('debugSession/records', () => {
if (page1.data.hasMoreNext && page1.data.list.length > 0) {
// Navigate to next page
const lastId = page1.data.list[page1.data.list.length - 1].dataId;
const page2 = await Call<any, any, getChatRecordsResponse>(handler, {
const page2 = await Call<any, any, GetRecordsV2ResponseType>(handler, {
auth: testUser,
body: { skillId, chatId, pageSize: 2, nextId: lastId }
});
@@ -1,4 +1,8 @@
import * as createapi from '@/pages/api/core/dataset/create';
import createHandler from '@/pages/api/core/dataset/create';
import type {
CreateDatasetBody,
CreateDatasetResponse
} from '@fastgpt/global/openapi/core/dataset/api';
import { DatasetTypeEnum } from '@fastgpt/global/core/dataset/constants';
import { TeamDatasetCreatePermissionVal } from '@fastgpt/global/support/permission/user/constant';
import { MongoResourcePermission } from '@fastgpt/service/support/permission/schema';
@@ -16,11 +20,7 @@ describe('create dataset', () => {
tmbId: users.members[0].tmbId,
permission: TeamDatasetCreatePermissionVal
});
const res = await Call<
createapi.DatasetCreateBody,
createapi.DatasetCreateQuery,
createapi.DatasetCreateResponse
>(createapi.default, {
const res = await Call<CreateDatasetBody, {}, CreateDatasetResponse>(createHandler, {
auth: users.members[0],
body: {
name: 'folder',
@@ -33,11 +33,7 @@ describe('create dataset', () => {
expect(res.code).toBe(200);
const folderId = res.data as string;
const res2 = await Call<
createapi.DatasetCreateBody,
createapi.DatasetCreateQuery,
createapi.DatasetCreateResponse
>(createapi.default, {
const res2 = await Call<CreateDatasetBody, {}, CreateDatasetResponse>(createHandler, {
auth: users.members[0],
body: {
name: 'test',