Skip to content

Commit 72ba9f7

Browse files
Add filtering to sessionID for workspace chats (#2531)
1 parent c3a7a35 commit 72ba9f7

File tree

3 files changed

+47
-1
lines changed

3 files changed

+47
-1
lines changed

server/endpoints/api/workspace/index.js

+13-1
Original file line numberDiff line numberDiff line change
@@ -339,6 +339,12 @@ function apiWorkspaceEndpoints(app) {
339339
required: true,
340340
type: 'string'
341341
}
342+
#swagger.parameters['apiSessionId'] = {
343+
in: 'query',
344+
description: 'Optional apiSessionId to filter by',
345+
required: false,
346+
type: 'string'
347+
}
342348
#swagger.responses[200] = {
343349
content: {
344350
"application/json": {
@@ -370,14 +376,20 @@ function apiWorkspaceEndpoints(app) {
370376
*/
371377
try {
372378
const { slug } = request.params;
379+
const { apiSessionId = null } = request.query;
373380
const workspace = await Workspace.get({ slug });
374381

375382
if (!workspace) {
376383
response.sendStatus(400).end();
377384
return;
378385
}
379386

380-
const history = await WorkspaceChats.forWorkspace(workspace.id);
387+
const history = apiSessionId
388+
? await WorkspaceChats.forWorkspaceByApiSessionId(
389+
workspace.id,
390+
apiSessionId
391+
)
392+
: await WorkspaceChats.forWorkspace(workspace.id);
381393
response.status(200).json({ history: convertToChatHistory(history) });
382394
} catch (e) {
383395
console.error(e.message, e);

server/models/workspaceChats.js

+25
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,31 @@ const WorkspaceChats = {
5555
}
5656
},
5757

58+
forWorkspaceByApiSessionId: async function (
59+
workspaceId = null,
60+
apiSessionId = null,
61+
limit = null,
62+
orderBy = null
63+
) {
64+
if (!workspaceId || !apiSessionId) return [];
65+
try {
66+
const chats = await prisma.workspace_chats.findMany({
67+
where: {
68+
workspaceId,
69+
user_id: null,
70+
api_session_id: String(apiSessionId),
71+
thread_id: null,
72+
},
73+
...(limit !== null ? { take: limit } : {}),
74+
...(orderBy !== null ? { orderBy } : { orderBy: { id: "asc" } }),
75+
});
76+
return chats;
77+
} catch (error) {
78+
console.error(error.message);
79+
return [];
80+
}
81+
},
82+
5883
forWorkspace: async function (
5984
workspaceId = null,
6085
limit = null,

server/swagger/openapi.json

+9
Original file line numberDiff line numberDiff line change
@@ -1649,6 +1649,15 @@
16491649
"type": "string"
16501650
},
16511651
"description": "Unique slug of workspace to find"
1652+
},
1653+
{
1654+
"name": "apiSessionId",
1655+
"in": "query",
1656+
"description": "Optional apiSessionId to filter by",
1657+
"required": false,
1658+
"schema": {
1659+
"type": "string"
1660+
}
16521661
}
16531662
],
16541663
"responses": {

0 commit comments

Comments
 (0)