@@ -15,14 +15,26 @@ import (
15
15
"github.com/uozi-tech/cosy/logger"
16
16
)
17
17
18
+ const TerminalAssistantPath = "__terminal_assistant__"
19
+
18
20
// GetLLMSessions returns LLM sessions with optional filtering
19
21
func GetLLMSessions (c * gin.Context ) {
20
22
g := query .LLMSession
21
23
query := g .Order (g .UpdatedAt .Desc ())
22
24
23
- // Filter by path if provided
24
- if path := c .Query ("path" ); path != "" {
25
- if ! helper .IsUnderDirectory (path , nginx .GetConfPath ()) {
25
+ // Filter by type if provided
26
+ if assistantType := c .Query ("type" ); assistantType != "" {
27
+ if assistantType == "terminal" {
28
+ // For terminal type, filter by terminal assistant path
29
+ query = query .Where (g .Path .Eq (TerminalAssistantPath ))
30
+ } else if assistantType == "nginx" {
31
+ // For nginx type, exclude terminal assistant path
32
+ query = query .Where (g .Path .Neq (TerminalAssistantPath ))
33
+ }
34
+ } else if path := c .Query ("path" ); path != "" {
35
+ // Filter by path if provided (legacy support)
36
+ // Skip path validation for terminal assistant
37
+ if path != TerminalAssistantPath && ! helper .IsUnderDirectory (path , nginx .GetConfPath ()) {
26
38
c .JSON (http .StatusForbidden , gin.H {
27
39
"message" : "path is not under the nginx conf path" ,
28
40
})
@@ -59,23 +71,31 @@ func CreateLLMSession(c *gin.Context) {
59
71
var json struct {
60
72
Title string `json:"title" binding:"required"`
61
73
Path string `json:"path"`
74
+ Type string `json:"type"`
62
75
}
63
76
64
77
if ! cosy .BindAndValid (c , & json ) {
65
78
return
66
79
}
67
80
68
- // Validate path if provided
69
- if json .Path != "" && ! helper .IsUnderDirectory (json .Path , nginx .GetConfPath ()) {
70
- c .JSON (http .StatusForbidden , gin.H {
71
- "message" : "path is not under the nginx conf path" ,
72
- })
73
- return
81
+ // Determine path based on type
82
+ var sessionPath string
83
+ if json .Type == "terminal" {
84
+ sessionPath = TerminalAssistantPath
85
+ } else {
86
+ sessionPath = json .Path
87
+ // Validate path for non-terminal types
88
+ if sessionPath != "" && ! helper .IsUnderDirectory (sessionPath , nginx .GetConfPath ()) {
89
+ c .JSON (http .StatusForbidden , gin.H {
90
+ "message" : "path is not under the nginx conf path" ,
91
+ })
92
+ return
93
+ }
74
94
}
75
95
76
96
session := & model.LLMSession {
77
97
Title : json .Title ,
78
- Path : json . Path ,
98
+ Path : sessionPath ,
79
99
Messages : []openai.ChatCompletionMessage {},
80
100
MessageCount : 0 ,
81
101
IsActive : true ,
@@ -197,7 +217,8 @@ func DuplicateLLMSession(c *gin.Context) {
197
217
func GetLLMSessionByPath (c * gin.Context ) {
198
218
path := c .Query ("path" )
199
219
200
- if ! helper .IsUnderDirectory (path , nginx .GetConfPath ()) {
220
+ // Skip path validation for terminal assistant
221
+ if path != TerminalAssistantPath && ! helper .IsUnderDirectory (path , nginx .GetConfPath ()) {
201
222
c .JSON (http .StatusForbidden , gin.H {
202
223
"message" : "path is not under the nginx conf path" ,
203
224
})
@@ -250,7 +271,8 @@ func CreateOrUpdateLLMSessionByPath(c *gin.Context) {
250
271
return
251
272
}
252
273
253
- if ! helper .IsUnderDirectory (json .FileName , nginx .GetConfPath ()) {
274
+ // Skip path validation for terminal assistant
275
+ if json .FileName != TerminalAssistantPath && ! helper .IsUnderDirectory (json .FileName , nginx .GetConfPath ()) {
254
276
c .JSON (http .StatusForbidden , gin.H {
255
277
"message" : "path is not under the nginx conf path" ,
256
278
})
0 commit comments