|
|
|
|
@ -42,41 +42,6 @@ export class MemoryController {
|
|
|
|
|
router.applyRoute(MemoryController);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private initRoutes(): void {
|
|
|
|
|
var memoryRouter = new SwaggerRouter({
|
|
|
|
|
prefix: '/memory',
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
memoryRouter.all('/v1/(.*)', this.checkDb);
|
|
|
|
|
|
|
|
|
|
memoryRouter.get('/v1/:conversationId/last_dialogue', this.getConversationLastDialogue);
|
|
|
|
|
memoryRouter.post('/v1/:conversationId/last_dialogue', this.updateConversationLastDialogue);
|
|
|
|
|
|
|
|
|
|
memoryRouter.get('/v1/:conversationId/last_dialogue/message/:role', async (ctx) => { });
|
|
|
|
|
memoryRouter.post('/v1/:conversationId/last_dialogue/message/:role', async (ctx) => { });
|
|
|
|
|
|
|
|
|
|
memoryRouter.post('/v1/:conversationId/append', this.appendMessagesToConversation);
|
|
|
|
|
memoryRouter.post('/v1/:conversationId/override', this.overrideMessagesToConversation);
|
|
|
|
|
memoryRouter.delete('/v1/:conversationId', this.deleteConversation);
|
|
|
|
|
|
|
|
|
|
memoryRouter.get('/v1/:conversationId/pages', this.listPages);
|
|
|
|
|
memoryRouter.post('/v1/:conversationId/new_page', this.createNewPage);
|
|
|
|
|
|
|
|
|
|
memoryRouter.get('/v1/:conversationId/page/:pageId', async (ctx) => { });
|
|
|
|
|
memoryRouter.get('/v1/:conversationId/page/:pageId/metadata', async (ctx) => { });
|
|
|
|
|
memoryRouter.get('/v1/:conversationId/page/:pageId/metadata/:varKey', async (ctx) => { });
|
|
|
|
|
memoryRouter.get('/v1/:conversationId/page/:pageId/metadata/:varKey/json', async (ctx) => { });
|
|
|
|
|
|
|
|
|
|
memoryRouter.post('/v1/:conversationId/page/:pageId/metadata', async (ctx) => { });
|
|
|
|
|
memoryRouter.post('/v1/:conversationId/page/:pageId/merge_metadata', async (ctx) => { });
|
|
|
|
|
memoryRouter.post('/v1/:conversationId/page/:pageId/metadata/:varKey', async (ctx) => { });
|
|
|
|
|
memoryRouter.post('/v1/:conversationId/page/:pageId/metadata/:varKey/json', async (ctx) => { });
|
|
|
|
|
|
|
|
|
|
memoryRouter.delete('/v1/:conversationId/page/:pageId/metadata/:varKey', async (ctx) => { });
|
|
|
|
|
memoryRouter.delete('/v1/:conversationId/page/:pageId/metadata', async (ctx) => { });
|
|
|
|
|
memoryRouter.post('/v1/:conversationId/page/:pageId/:varKey/delete', async (ctx) => { });
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public checkDb(ctx: Koa.ParameterizedContext): boolean {
|
|
|
|
|
if (!ctx.database) {
|
|
|
|
|
ctx.status = 500;
|
|
|
|
|
@ -91,7 +56,7 @@ export class MemoryController {
|
|
|
|
|
method: 'get',
|
|
|
|
|
path: '/memory/v1/{conversationId}',
|
|
|
|
|
summary: 'Get conversation information',
|
|
|
|
|
operationId: 'getConversationInfo',
|
|
|
|
|
operationId: 'Get Conversation Info',
|
|
|
|
|
request: {
|
|
|
|
|
params: z.object({
|
|
|
|
|
conversationId: z.string().describe('The conversation ID to retrieve information for.'),
|
|
|
|
|
@ -133,7 +98,7 @@ export class MemoryController {
|
|
|
|
|
method: 'get',
|
|
|
|
|
path: '/memory/v1/{conversationId}/last_dialogue',
|
|
|
|
|
summary: 'Get the last dialogue of a conversation',
|
|
|
|
|
operationId: 'getConversationLastDialogue',
|
|
|
|
|
operationId: 'Get Conversation Last Dialogue',
|
|
|
|
|
request: {
|
|
|
|
|
params: z.object({
|
|
|
|
|
conversationId: z.string().describe('The conversation ID to retrieve the last dialogue for.'),
|
|
|
|
|
@ -172,7 +137,7 @@ export class MemoryController {
|
|
|
|
|
method: 'post',
|
|
|
|
|
path: '/memory/v1/{conversationId}/last_dialogue',
|
|
|
|
|
summary: 'Update the last dialogue of a conversation',
|
|
|
|
|
operationId: 'updateConversationLastDialogue',
|
|
|
|
|
operationId: 'Update Conversation Last Dialogue',
|
|
|
|
|
request: {
|
|
|
|
|
params: z.object({
|
|
|
|
|
conversationId: z.string().describe('The conversation ID to update the last dialogue for.'),
|
|
|
|
|
@ -224,7 +189,7 @@ export class MemoryController {
|
|
|
|
|
method: 'get',
|
|
|
|
|
path: '/memory/v1/{conversationId}/last_dialogue/message/{role}',
|
|
|
|
|
summary: 'Get the last dialogue of a conversation',
|
|
|
|
|
operationId: 'getConversationLastDialogueMessage',
|
|
|
|
|
operationId: 'Get Message From Conversation Last Dialogue',
|
|
|
|
|
request: {
|
|
|
|
|
params: z.object({
|
|
|
|
|
conversationId: z.string().describe('The conversation ID to retrieve the last dialogue for.'),
|
|
|
|
|
@ -313,7 +278,7 @@ export class MemoryController {
|
|
|
|
|
method: 'post',
|
|
|
|
|
path: '/memory/v1/{conversationId}/append',
|
|
|
|
|
summary: 'Append messages to a conversation',
|
|
|
|
|
operationId: 'appendMessagesToConversation',
|
|
|
|
|
operationId: 'Append Messages To Conversation',
|
|
|
|
|
request: {
|
|
|
|
|
params: z.object({
|
|
|
|
|
conversationId: z.string().describe('The conversation ID to append messages to.'),
|
|
|
|
|
@ -357,7 +322,7 @@ export class MemoryController {
|
|
|
|
|
method: 'post',
|
|
|
|
|
path: '/memory/v1/{conversationId}/override',
|
|
|
|
|
summary: 'Override messages in a conversation',
|
|
|
|
|
operationId: 'overrideMessagesToConversation',
|
|
|
|
|
operationId: 'Override Messages To Conversation',
|
|
|
|
|
request: {
|
|
|
|
|
params: z.object({
|
|
|
|
|
conversationId: z.string().describe('The conversation ID to override messages in.'),
|
|
|
|
|
@ -401,7 +366,7 @@ export class MemoryController {
|
|
|
|
|
method: 'delete',
|
|
|
|
|
path: '/memory/v1/{conversationId}',
|
|
|
|
|
summary: 'Delete a conversation',
|
|
|
|
|
operationId: 'deleteConversation',
|
|
|
|
|
operationId: 'Delete Conversation',
|
|
|
|
|
request: {
|
|
|
|
|
params: z.object({
|
|
|
|
|
conversationId: z.string().describe('The conversation ID to delete.'),
|
|
|
|
|
@ -430,7 +395,7 @@ export class MemoryController {
|
|
|
|
|
method: 'get',
|
|
|
|
|
path: '/memory/v1/{conversationId}/pages',
|
|
|
|
|
summary: 'List all pages of a conversation',
|
|
|
|
|
operationId: 'listPages',
|
|
|
|
|
operationId: 'List Conversation Pages',
|
|
|
|
|
request: {
|
|
|
|
|
params: z.object({
|
|
|
|
|
conversationId: z.string().describe('The conversation ID to list pages for.'),
|
|
|
|
|
@ -460,7 +425,7 @@ export class MemoryController {
|
|
|
|
|
method: 'post',
|
|
|
|
|
path: '/memory/v1/{conversationId}/new_page',
|
|
|
|
|
summary: 'Create a new page for a conversation',
|
|
|
|
|
operationId: 'createNewPage',
|
|
|
|
|
operationId: 'Create New Page (Shadow clear memory messages)',
|
|
|
|
|
request: {
|
|
|
|
|
params: z.object({
|
|
|
|
|
conversationId: z.string().describe('The conversation ID to create a new page for.'),
|
|
|
|
|
@ -537,7 +502,7 @@ export class MemoryController {
|
|
|
|
|
method: 'get',
|
|
|
|
|
path: '/memory/v1/{conversationId}/page/{pageId}',
|
|
|
|
|
summary: 'Get information about a specific page in a conversation',
|
|
|
|
|
operationId: 'getPageInfo',
|
|
|
|
|
operationId: 'Get Page Info',
|
|
|
|
|
request: {
|
|
|
|
|
params: z.object({
|
|
|
|
|
conversationId: z.string().describe('The conversation ID to retrieve the page for.'),
|
|
|
|
|
@ -585,7 +550,7 @@ export class MemoryController {
|
|
|
|
|
method: 'get',
|
|
|
|
|
path: '/memory/v1/{conversationId}/page/{pageId}/metadata',
|
|
|
|
|
summary: 'Get metadata of a specific page in a conversation',
|
|
|
|
|
operationId: 'getPageMetadata',
|
|
|
|
|
operationId: 'Get Page Metadata',
|
|
|
|
|
request: {
|
|
|
|
|
params: z.object({
|
|
|
|
|
conversationId: z.string().describe('The conversation ID to retrieve the page for.'),
|
|
|
|
|
@ -615,7 +580,7 @@ export class MemoryController {
|
|
|
|
|
method: 'get',
|
|
|
|
|
path: '/memory/v1/{conversationId}/page/{pageId}/metadata/{varKey}',
|
|
|
|
|
summary: 'Get a specific metadata variable from a page in a conversation',
|
|
|
|
|
operationId: 'getPageMetadataVariable',
|
|
|
|
|
operationId: 'Get Variable From Page Metadata',
|
|
|
|
|
request: {
|
|
|
|
|
params: z.object({
|
|
|
|
|
conversationId: z.string().describe('The conversation ID to retrieve the page for.'),
|
|
|
|
|
@ -657,46 +622,12 @@ export class MemoryController {
|
|
|
|
|
|
|
|
|
|
return metadataValue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@routeConfig({
|
|
|
|
|
method: 'get',
|
|
|
|
|
path: '/memory/v1/{conversationId}/page/{pageId}/metadata/{varKey}/json',
|
|
|
|
|
summary: 'Get a specific metadata variable from a page in a conversation as JSON',
|
|
|
|
|
operationId: 'getPageMetadataVariableJson',
|
|
|
|
|
request: {
|
|
|
|
|
params: z.object({
|
|
|
|
|
conversationId: z.string().describe('The conversation ID to retrieve the page for.'),
|
|
|
|
|
pageId: pageIdSchema,
|
|
|
|
|
varKey: z.string().describe('The key of the metadata variable to retrieve.'),
|
|
|
|
|
}),
|
|
|
|
|
},
|
|
|
|
|
responses: DefaultResponses,
|
|
|
|
|
})
|
|
|
|
|
@responses(z.string() as any)
|
|
|
|
|
public async getPageMetadataVariableJson(ctx: Koa.ParameterizedContext): Promise<any> {
|
|
|
|
|
const metadataValue = await this.getPageMetadataVariable(ctx);
|
|
|
|
|
if (metadataValue === null) {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
const jsonValue = JSON.stringify(metadataValue);
|
|
|
|
|
ctx.status = 200;
|
|
|
|
|
ctx.type = 'application/json';
|
|
|
|
|
ctx.body = jsonValue;
|
|
|
|
|
return jsonValue;
|
|
|
|
|
} catch (error) {
|
|
|
|
|
ctx.status = 500;
|
|
|
|
|
ctx.body = { error: `Failed to convert metadata variable "${ctx.params.varKey}" to JSON` };
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@routeConfig({
|
|
|
|
|
method: 'post',
|
|
|
|
|
path: '/memory/v1/{conversationId}/page/{pageId}/metadata',
|
|
|
|
|
summary: 'Update metadata of a specific page in a conversation',
|
|
|
|
|
operationId: 'updatePageMetadata',
|
|
|
|
|
operationId: 'Set or Update Page Metadata',
|
|
|
|
|
request: {
|
|
|
|
|
params: z.object({
|
|
|
|
|
conversationId: z.string().describe('The conversation ID to update the page metadata for.'),
|
|
|
|
|
@ -771,7 +702,7 @@ export class MemoryController {
|
|
|
|
|
method: 'post',
|
|
|
|
|
path: '/memory/v1/{conversationId}/page/{pageId}/metadata/{varKey}',
|
|
|
|
|
summary: 'Update a specific metadata variable of a page in a conversation',
|
|
|
|
|
operationId: 'updatePageMetadataVariable',
|
|
|
|
|
operationId: 'Set or Update Page Metadata Variable',
|
|
|
|
|
request: {
|
|
|
|
|
params: z.object({
|
|
|
|
|
conversationId: z.string().describe('The conversation ID to update the page metadata for.'),
|
|
|
|
|
@ -843,7 +774,7 @@ export class MemoryController {
|
|
|
|
|
method: 'delete',
|
|
|
|
|
path: '/memory/v1/{conversationId}/page/{pageId}/metadata',
|
|
|
|
|
summary: 'Clear metadata of a specific page in a conversation',
|
|
|
|
|
operationId: 'deletePageMetadata',
|
|
|
|
|
operationId: 'Clear Page Metadata',
|
|
|
|
|
request: {
|
|
|
|
|
params: z.object({
|
|
|
|
|
conversationId: z.string().describe('The conversation ID to clear the page metadata for.'),
|
|
|
|
|
@ -879,7 +810,7 @@ export class MemoryController {
|
|
|
|
|
method: 'delete',
|
|
|
|
|
path: '/memory/v1/{conversationId}/page/{pageId}/metadata/{varKey}',
|
|
|
|
|
summary: 'Delete a specific metadata variable from a page in a conversation',
|
|
|
|
|
operationId: 'deletePageMetadataVariable',
|
|
|
|
|
operationId: 'Delete Page Metadata Variable',
|
|
|
|
|
request: {
|
|
|
|
|
params: z.object({
|
|
|
|
|
conversationId: z.string().describe('The conversation ID to delete the page metadata variable from.'),
|
|
|
|
|
|