You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

128 lines
6.8 KiB
TypeScript

import { SB } from '@serafin/schema-builder';
import { z } from 'koa-swagger-decorator';
export const pageIdSchema = z.union([
z.number().int().min(0).describe('The page ID of the conversation.'),
z.enum(['current']).describe('The special value "current" to refer to the current page.'),
]).describe('The page ID of the conversation, either as a number or the special value "current".');
export const ConversationDataSchema = z.object({
conversationId: z.string().describe('The unique identifier for the conversation.'),
llmApi: z.string().describe('The API id of the LLM used in the conversation.'),
dialogueCount: z.number().int().min(0).describe('Current dialogue count (from Dify) in the conversation.'),
currentPage: z.number().int().min(0).describe('The current page ID in the conversation.'),
createdAt: z.string().describe('The timestamp when the conversation was created.').datetime(),
updatedAt: z.string().describe('The timestamp when the conversation was last updated.').datetime(),
});
export const CommonApiMessageSchema = z.object({
role: z.string().describe('The role of the message sender, e.g., "user" or "assistant".'),
content: z.string().describe('The content of the message.'),
name: z.string().describe('The name of the message sender, if applicable.').nullable().optional(),
}).passthrough();
export const ConversationDialogueSchema = z.object({
id: z.number().int().min(0).describe('The unique identifier for the dialogue.'),
conversationId: z.string().describe('The unique identifier for the conversation.'),
dialogueCount: z.number().int().min(0).describe('The count of dialogues of this dialogue.'),
page: z.number().int().min(0).describe('The page number of the dialogue.'),
messages: z.array(CommonApiMessageSchema).describe('Messages'),
updatedAt: z.string().describe('The time when the dialogue was last updated.').datetime(),
});
export const ConversationPageSchema = z.object({
id: z.number().int().min(0).describe('The unique identifier for the page record.'),
conversationId: z.string().describe('The unique identifier for the conversation.'),
pageId: z.number().int().min(0).describe('The page number of the conversation.'),
metadata: z.record(z.any()).describe('Metadata'),
updatedAt: z.string().describe('The timestamp when the page was last updated.').datetime(),
});
export const ActionRes = z.object({
success: z.boolean().describe('Indicates whether the action was successful.'),
message: z.string().describe('A message providing additional information about the action result.'),
error: z.string().describe('An error message if the action failed.').nullable().optional(),
});
export type ActionResType = z.infer<typeof ActionRes>;
/**
* 获取对话信息响应体
*/
export const GetConversationInfoRes = ConversationDataSchema;
export type GetConversationInfoResType = z.infer<typeof GetConversationInfoRes>;
/**
* 获取单轮对话信息响应体
*/
export const GetDialogueInfoRes = ConversationDialogueSchema;
export type GetDialogueInfoResType = z.infer<typeof GetDialogueInfoRes>;
/**
* 更新对话内容请求体
*/
export const UpdateDialogueMessagesReq = z.object({
messages: z.array(
z.object({
role: z.string().describe('The role of the message sender, e.g., "user" or "assistant".'),
content: z.string().describe('The content of the message.'),
name: z.string().describe('The name of the message sender, if applicable.').nullable().optional(),
}).passthrough()
).describe('An array of messages to update the dialogue with.'),
dialogueCount: z.number().int().min(0).describe('The count of dialogues in the conversation.').nullable().optional(),
});
export type UpdateDialogueMessagesReqType = z.infer<typeof UpdateDialogueMessagesReq>;
export const OverrideDialogueMessagesReq = z.object({
messages: z.array(CommonApiMessageSchema).describe('An array of messages to update the dialogue with.'),
dialogueCount: z.number().int().min(0).describe('The count of dialogues in the conversation.'),
});
export type OverrideDialogueMessagesReqType = z.infer<typeof OverrideDialogueMessagesReq>;
export const GetMessageContentQuery = z.object({
offset: z.string().describe('The number of dialogues to skip. for example, 1 means update the 2nd message of this role.').nullable().optional(),
offsetEnd: z.string().describe('The number of dialogues to skip from the end. for example, 1 means update the 2nd last message of this role.').nullable().optional(),
}).describe('GetMessageContentQuery');
export type GetMessageContentQueryType = z.infer<typeof GetMessageContentQuery>;
export const GetPageListRes = z.array(
ConversationPageSchema.omit({ metadata: true })
).describe('GetPageListRes');
export type GetPageListResType = z.infer<typeof GetPageListRes>;
export const GetPageInfoRes = ConversationPageSchema;
export type GetPageInfoResType = z.infer<typeof GetPageInfoRes>;
export const GetPageMetadataRes = z.object({
metadata: z.record(z.any()).describe('The metadata of the page.'),
}).describe('GetPageMetadataRes');
export type GetPageMetadataResType = z.infer<typeof GetPageMetadataRes>;
export const UpdatePageMetadataReq = z.object({
metadata: z.record(z.any()).describe('The metadata to update for the page.'),
}).describe('UpdatePageMetadataReq');
export type UpdatePageMetadataReqType = z.infer<typeof UpdatePageMetadataReq>;
export const GetPageMetadataItemRes = z.object({
key: z.string().describe('The key of the metadata item.'),
value: z.any().describe('The value of the metadata item.'),
type: z.enum(['string', 'number', 'boolean', 'object', 'array', 'null']).describe('The type of the metadata item value.'),
exists: z.boolean().describe('Indicates whether the metadata item exists.'),
}).describe('GetPageMetadataItemRes');
export type GetPageMetadataItemResType = z.infer<typeof GetPageMetadataItemRes>;
export const UpdatePageMetadataItemReq = z.object({
value: z.any().describe('The new value for the metadata item.'),
valueIsJson: z.boolean().describe('Indicates whether the value is a JSON string.').default(false),
}).describe('UpdatePageMetadataItemReq');
export type UpdatePageMetadataItemReqType = z.infer<typeof UpdatePageMetadataItemReq>;
export const CreateNewPageReq = z.object({
metadata: z.record(z.any()).describe('The metadata for the new page.').nullable().optional(),
inheritMetadata: z.boolean().describe('Whether to inherit metadata from the current page.').default(true),
}).describe('NewPageReq');
export type CreateNewPageReqType = z.infer<typeof CreateNewPageReq>;
export const CreateNewPageRes = z.object({
pageId: z.number().int().min(0).describe('The ID of the newly created page.'),
}).describe('NewPageRes');
export type CreateNewPageResType = z.infer<typeof CreateNewPageRes>;