mirror of
https://github.com/Mintplex-Labs/anything-llm.git
synced 2024-11-19 12:40:09 +01:00
Add filtering to sessionID for workspace chats (#2531)
This commit is contained in:
parent
c3a7a35346
commit
72ba9f7f28
@ -339,6 +339,12 @@ function apiWorkspaceEndpoints(app) {
|
|||||||
required: true,
|
required: true,
|
||||||
type: 'string'
|
type: 'string'
|
||||||
}
|
}
|
||||||
|
#swagger.parameters['apiSessionId'] = {
|
||||||
|
in: 'query',
|
||||||
|
description: 'Optional apiSessionId to filter by',
|
||||||
|
required: false,
|
||||||
|
type: 'string'
|
||||||
|
}
|
||||||
#swagger.responses[200] = {
|
#swagger.responses[200] = {
|
||||||
content: {
|
content: {
|
||||||
"application/json": {
|
"application/json": {
|
||||||
@ -370,6 +376,7 @@ function apiWorkspaceEndpoints(app) {
|
|||||||
*/
|
*/
|
||||||
try {
|
try {
|
||||||
const { slug } = request.params;
|
const { slug } = request.params;
|
||||||
|
const { apiSessionId = null } = request.query;
|
||||||
const workspace = await Workspace.get({ slug });
|
const workspace = await Workspace.get({ slug });
|
||||||
|
|
||||||
if (!workspace) {
|
if (!workspace) {
|
||||||
@ -377,7 +384,12 @@ function apiWorkspaceEndpoints(app) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const history = await WorkspaceChats.forWorkspace(workspace.id);
|
const history = apiSessionId
|
||||||
|
? await WorkspaceChats.forWorkspaceByApiSessionId(
|
||||||
|
workspace.id,
|
||||||
|
apiSessionId
|
||||||
|
)
|
||||||
|
: await WorkspaceChats.forWorkspace(workspace.id);
|
||||||
response.status(200).json({ history: convertToChatHistory(history) });
|
response.status(200).json({ history: convertToChatHistory(history) });
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error(e.message, e);
|
console.error(e.message, e);
|
||||||
|
@ -55,6 +55,31 @@ const WorkspaceChats = {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
forWorkspaceByApiSessionId: async function (
|
||||||
|
workspaceId = null,
|
||||||
|
apiSessionId = null,
|
||||||
|
limit = null,
|
||||||
|
orderBy = null
|
||||||
|
) {
|
||||||
|
if (!workspaceId || !apiSessionId) return [];
|
||||||
|
try {
|
||||||
|
const chats = await prisma.workspace_chats.findMany({
|
||||||
|
where: {
|
||||||
|
workspaceId,
|
||||||
|
user_id: null,
|
||||||
|
api_session_id: String(apiSessionId),
|
||||||
|
thread_id: null,
|
||||||
|
},
|
||||||
|
...(limit !== null ? { take: limit } : {}),
|
||||||
|
...(orderBy !== null ? { orderBy } : { orderBy: { id: "asc" } }),
|
||||||
|
});
|
||||||
|
return chats;
|
||||||
|
} catch (error) {
|
||||||
|
console.error(error.message);
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
forWorkspace: async function (
|
forWorkspace: async function (
|
||||||
workspaceId = null,
|
workspaceId = null,
|
||||||
limit = null,
|
limit = null,
|
||||||
|
@ -1649,6 +1649,15 @@
|
|||||||
"type": "string"
|
"type": "string"
|
||||||
},
|
},
|
||||||
"description": "Unique slug of workspace to find"
|
"description": "Unique slug of workspace to find"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "apiSessionId",
|
||||||
|
"in": "query",
|
||||||
|
"description": "Optional apiSessionId to filter by",
|
||||||
|
"required": false,
|
||||||
|
"schema": {
|
||||||
|
"type": "string"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"responses": {
|
"responses": {
|
||||||
|
Loading…
Reference in New Issue
Block a user