File tree 3 files changed +47
-1
lines changed
3 files changed +47
-1
lines changed Original file line number Diff line number Diff line change @@ -339,6 +339,12 @@ function apiWorkspaceEndpoints(app) {
339
339
required: true,
340
340
type: 'string'
341
341
}
342
+ #swagger.parameters['apiSessionId'] = {
343
+ in: 'query',
344
+ description: 'Optional apiSessionId to filter by',
345
+ required: false,
346
+ type: 'string'
347
+ }
342
348
#swagger.responses[200] = {
343
349
content: {
344
350
"application/json": {
@@ -370,14 +376,20 @@ function apiWorkspaceEndpoints(app) {
370
376
*/
371
377
try {
372
378
const { slug } = request . params ;
379
+ const { apiSessionId = null } = request . query ;
373
380
const workspace = await Workspace . get ( { slug } ) ;
374
381
375
382
if ( ! workspace ) {
376
383
response . sendStatus ( 400 ) . end ( ) ;
377
384
return ;
378
385
}
379
386
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 ) ;
381
393
response . status ( 200 ) . json ( { history : convertToChatHistory ( history ) } ) ;
382
394
} catch ( e ) {
383
395
console . error ( e . message , e ) ;
Original file line number Diff line number Diff line change @@ -55,6 +55,31 @@ const WorkspaceChats = {
55
55
}
56
56
} ,
57
57
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
+
58
83
forWorkspace : async function (
59
84
workspaceId = null ,
60
85
limit = null ,
Original file line number Diff line number Diff line change 1649
1649
"type" : " string"
1650
1650
},
1651
1651
"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
+ }
1652
1661
}
1653
1662
],
1654
1663
"responses" : {
You can’t perform that action at this time.
0 commit comments