更改路由包
parent
449cbae77d
commit
ba06f46898
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,122 @@
|
||||
import { SB } from '@serafin/schema-builder';
|
||||
import { z } from 'koa-swagger-decorator';
|
||||
|
||||
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(),
|
||||
}).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>;
|
||||
@ -0,0 +1,11 @@
|
||||
import { Logger } from './utils/logger';
|
||||
import { DataSource } from 'typeorm';
|
||||
import App from './App';
|
||||
|
||||
declare module 'koa' {
|
||||
interface ExtendableContext {
|
||||
getLogger: (tag: string) => Logger;
|
||||
application: App;
|
||||
database: DataSource | null;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,27 @@
|
||||
import Router from 'koa-router';
|
||||
import { SwaggerRouter } from 'koa-swagger-decorator';
|
||||
|
||||
export const swaggerRouter = new SwaggerRouter({
|
||||
spec: {
|
||||
info: {
|
||||
title: 'Memory Proxy for Dify API',
|
||||
description: 'This is a memory proxy for Dify API, which is used to store and retrieve data in memory.',
|
||||
version: '1.0.0',
|
||||
},
|
||||
servers: [
|
||||
{
|
||||
url: 'http://localhost:8616',
|
||||
description: 'Local server',
|
||||
}
|
||||
],
|
||||
security: [
|
||||
{
|
||||
BearerAuth: []
|
||||
}
|
||||
],
|
||||
},
|
||||
swaggerHtmlEndpoint: '/docs',
|
||||
swaggerJsonEndpoint: '/openapi.json',
|
||||
});
|
||||
|
||||
swaggerRouter.swagger();
|
||||
Loading…
Reference in New Issue