Skip to content

Commit ae630cc

Browse files
committed
commit
1 parent 82cb175 commit ae630cc

File tree

15 files changed

+98
-36
lines changed

15 files changed

+98
-36
lines changed

.azure.env

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
SENTRIUS_VERSION=1.1.140
1+
SENTRIUS_VERSION=1.1.149
22
SENTRIUS_SSH_VERSION=1.1.12
33
SENTRIUS_KEYCLOAK_VERSION=1.1.15
44
SENTRIUS_AGENT_VERSION=1.1.24
5-
SENTRIUS_AI_AGENT_VERSION=1.1.5
5+
SENTRIUS_AI_AGENT_VERSION=1.1.8
66
LLMPROXY_VERSION=1.1.5
77
LAUNCHER_VERSION=1.1.6
8-
AGENTPROXY_VERSION=1.1.8
8+
AGENTPROXY_VERSION=1.1.9
99
SSHPROXY_VERSION=1.1.5
10-
RDPPROXY_VERSION=1.1.5
10+
RDPPROXY_VERSION=1.1.7
1111
GITHUB_MCP_VERSION=1.1.5
1212
PROMPT_ADVISOR_VERSION=1.1.8
1313
MONITORING_AGENT_VERSION=1.1.23

agent-proxy/src/main/java/io/sentrius/sso/config/AgentWebSocketProxyHandler.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ public Mono<Void> handle(WebSocketSession clientSession) {
4848
chatGroupId = chatGroupId.replace(" ","+");
4949
String ztat = queryParams.get("ztat");
5050
String ztatForChat = queryParams.get("jwt");
51+
String userId = queryParams.get("userId");
52+
userId = userId.replace(" ","+");
5153

5254

5355
if (ztatForChat != null && !ztatForChat.isEmpty()) {
@@ -62,10 +64,11 @@ public Mono<Void> handle(WebSocketSession clientSession) {
6264
log.info("Invalid ZTAT token for sessionId: {}", sessionId);
6365
return Mono.error(new RuntimeException("Invalid ZTAT token") );
6466
}
65-
log.info("Handling WebSocket connection for host: {}, sessionId: {}, chatGroupId: {}, ztat: {}",
66-
agentHost, sessionId, chatGroupId, ztat);
67+
log.info("Handling WebSocket connection for host: {}, sessionId: {}, chatGroupId: {}, ztat: {}, userId: {}",
68+
agentHost, sessionId, chatGroupId, ztat, userId);
6769

68-
URI agentUri = agentLocator.resolveWebSocketUri(agentHost.toLowerCase(), sessionId, chatGroupId, ztat);
70+
URI agentUri = agentLocator.resolveWebSocketUri(agentHost.toLowerCase(), sessionId, chatGroupId, ztat,
71+
userId);
6972

7073
log.info("Resolved agent URI: {}", agentUri);
7174

agent-proxy/src/main/java/io/sentrius/sso/locator/KubernetesAgentLocator.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@
1010
public class KubernetesAgentLocator {
1111

1212

13-
public URI resolveWebSocketUri(String host, String sessionId, String chatGroupId, String ztat) {
13+
public URI resolveWebSocketUri(String host, String sessionId, String chatGroupId, String ztat, String userId) {
1414
// DNS: sentrius-agent-[ID].[namespace].svc.cluster.local
1515
///api/v1/chat/attach/subscribe?sessionId=${encodeURIComponent(this.sessionId)}&chatGroupId=${this.chatGroupId}&ztat=${encodeURIComponent(jwt)
16-
String fqdn = String.format("%s/api/v1/chat/attach/subscribe?sessionId=%s&chatGroupId=%s&ztat=%s",
17-
host, sessionId, chatGroupId, ztat);
16+
String fqdn = String.format("%s/api/v1/chat/attach/subscribe?sessionId=%s&chatGroupId=%s&ztat=%s&userId=%s",
17+
host, sessionId, chatGroupId, ztat, userId);
1818
return URI.create(fqdn);
1919
}
2020
}

api/src/main/java/io/sentrius/sso/controllers/api/TooltipController.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ public ResponseEntity<TooltipChatResponse> chat(
133133
}
134134

135135
// Build token DTO for LLM service
136-
TokenDTO tokenDTO = TokenDTO.builder().build();
136+
TokenDTO tokenDTO = TokenDTO.builder().communicationId(UUID.randomUUID().toString()).build();
137137
// Token will be populated from security context by LLM service
138138

139139
// Generate chat response
@@ -162,7 +162,7 @@ public ResponseEntity<TooltipChatResponse> chat(
162162
*/
163163
@PostMapping("/admin/index")
164164
@Endpoint(description = "Trigger manual indexing of codebase and documentation")
165-
@LimitAccess(applicationAccess = ApplicationAccessEnum.CAN_LOG_IN)
165+
@LimitAccess(applicationAccess = ApplicationAccessEnum.CAN_MANAGE_APPLICATION)
166166
public ResponseEntity<Map<String, Object>> triggerIndexing(
167167
HttpServletRequest httpRequest,
168168
HttpServletResponse httpResponse) {

api/src/main/java/io/sentrius/sso/controllers/view/AgentController.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
import io.sentrius.sso.core.services.auditing.AuditService;
1717
import io.sentrius.sso.core.services.security.CryptoService;
1818
import io.sentrius.sso.core.services.terminal.SessionTrackingService;
19+
import jakarta.servlet.http.HttpServletRequest;
20+
import jakarta.servlet.http.HttpServletResponse;
1921
import lombok.extern.slf4j.Slf4j;
2022
import org.springframework.http.ResponseEntity;
2123
import org.springframework.stereotype.Controller;
@@ -58,7 +60,8 @@ public String listAgents(Model m) {
5860

5961
@GetMapping("/design/chat")
6062
@LimitAccess(applicationAccess = {ApplicationAccessEnum.CAN_MANAGE_APPLICATION})
61-
public String designAgent(Model m) {
63+
public String designAgent(HttpServletRequest request, HttpServletResponse response, Model m) {
64+
m.addAttribute("userId", getOperatingUser(request,response).getUserId() );
6265
return "sso/agents/design_chat";
6366
}
6467

api/src/main/java/io/sentrius/sso/websocket/ChatWSHandler.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public class ChatWSHandler extends TextWebSocketHandler {
3333

3434

3535

36-
// Store active sessions, using session ID or a custom identifier
36+
// Storec active sessions, using session ID or a custom identifier
3737
private final ConcurrentHashMap<String, WebSocketSession> sessions = new ConcurrentHashMap<>();
3838

3939
@Override

api/src/main/resources/static/js/ai-helper.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -344,6 +344,8 @@
344344
const input = document.getElementById('ai-helper-chat-input');
345345
if (!input) return;
346346

347+
const token = document.querySelector('meta[name="_csrf"]')?.content;
348+
347349
const message = input.value.trim();
348350
if (!message) return;
349351

@@ -365,6 +367,7 @@
365367
method: 'POST',
366368
headers: {
367369
'Content-Type': 'application/json',
370+
'X-CSRF-TOKEN': token
368371
},
369372
body: JSON.stringify({
370373
message: message,

api/src/main/resources/static/js/chat.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,12 @@ const chatSessions = new Map(); // key: agentId, value: ChatSession
2323
// Section: ChatSession Class
2424
// =========================
2525
class ChatSession {
26-
constructor(agentName, agentId, sessionId, agentHost, preloadMessages = []) {
26+
constructor(agentName, agentId, sessionId, userId, agentHost, preloadMessages = []) {
2727
this.agentId = agentId;
2828
this.agentName = agentName;
2929
this.sessionId = sessionId;
3030
this.agentHost = agentHost;
31+
this.userId = userId;
3132
this.chatGroupId = `${agentId}-${sessionId}`;
3233
this.messages = preloadMessages || [];
3334
this.connection = null;
@@ -79,7 +80,7 @@ class ChatSession {
7980
let ztatForChat = {};
8081
try {
8182
const response = await fetch(
82-
"/api/v1/agent/connect?session_id=" + this.sessionId,
83+
"/api/v1/agent/connect?session_id=" + this.sessionId + "&userId=" + this.userId,
8384
{
8485
method: "POST",
8586
headers: {
@@ -115,7 +116,7 @@ class ChatSession {
115116
//const uri = `${phost}/api/v1/chat/attach/subscribe?sessionId=${encodeURIComponent(this.sessionId)}&chatGroupId=${this.chatGroupId}&ztat=${encodeURIComponent(jwt)}`;
116117
//const uri = `/api/v1/agents/ws/${encodeURIComponent(phost)}/${encodeURIComponent(this.sessionId)}/${encodeURIComponent(this.chatGroupId)}/${encodeURIComponent(jwt)}`;
117118

118-
const uri = config.agentProxyWsUrl + `/api/v1/agents/ws?phost=${encodeURIComponent(phost)}&sessionId=${encodeURIComponent(this.sessionId)}&chatGroupId=${encodeURIComponent(this.chatGroupId)}&ztat=${encodeURIComponent(jwt)}&jwt=${encodeURIComponent(ztatForChat.ztat_token)}`;
119+
const uri = config.agentProxyWsUrl + `/api/v1/agents/ws?phost=${encodeURIComponent(phost)}&sessionId=${encodeURIComponent(this.sessionId)}&userId=${encodeURIComponent(this.userId)}&chatGroupId=${encodeURIComponent(this.chatGroupId)}&ztat=${encodeURIComponent(jwt)}&jwt=${encodeURIComponent(ztatForChat.ztat_token)}`;
119120

120121
console.log("Connecting to chat server with ZTAT at:", uri);
121122
this.connection = new WebSocket(uri);

api/src/main/resources/templates/sso/agents/design_chat.html

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -341,9 +341,10 @@ <h2><i class="fas fa-robot"></i> Agent Designer</h2>
341341
</div>
342342
</div>
343343

344-
<script type="module">
344+
<script type="module" th:inline="javascript">
345345
import * as Chat from '/js/chat.js';
346346
let sessionId = crypto.randomUUID();
347+
let userId = [[${userId}]];
347348
let conversationHistory = [];
348349
let availableAgent = null;
349350
const csrfToken = document.getElementById("csrf-token").value;
@@ -426,7 +427,7 @@ <h2><i class="fas fa-robot"></i> Agent Designer</h2>
426427
if (!session) {
427428
console.log("New session creating:");
428429
session = new ChatSession(availableAgent.agentName, availableAgent.agentId, sessionId,
429-
availableAgent.agentCallback);
430+
userId,availableAgent.agentCallback);
430431
session.connect().then(() => {
431432
console.log("Connected to chat server");
432433
});
@@ -458,7 +459,7 @@ <h2><i class="fas fa-robot"></i> Agent Designer</h2>
458459
let session = chatSessions.get(availableAgent.agentId);
459460
if (!session) {
460461
console.log("New session creating:");
461-
session = new ChatSession(availableAgent.agentName, availableAgent.agentId, sessionId,
462+
session = new ChatSession(availableAgent.agentName, availableAgent.agentId, sessionId,userId,
462463
availableAgent.agentCallback);
463464
session.connect().then(() => {
464465
console.log("Connected to chat server");

enterprise-agent/src/main/java/io/sentrius/agent/analysis/api/websocket/ChatWSHandler.java

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -136,19 +136,23 @@ protected void handleTextMessage(WebSocketSession session, TextMessage message)
136136
if (uri != null) {
137137
Map<String, String> queryParams = parseQueryParams(uri.getQuery());
138138
String sessionId = queryParams.get("sessionId");
139+
String userId = queryParams.get("userId");
139140

140141
var websocky = userCommunicationService.getSession(sessionId);
141142

143+
142144
if (sessionId != null && websocky.isPresent()) {
143145
var websocketCommunication = websocky.get();
146+
websocketCommunication.setUserId(userId);
144147
if (null == websocketCommunication.getAgentExecutionContextDTO().getAgentContext()){
145148
log.info("Loading agent context for session ID: {} is null ? {}" , sessionId,
146149
agentExecutionService.getExecutionContextDTO( chatAgent.getAgentExecution().getExecutionId() ).getAgentContext()==null);
147150
websocketCommunication.getAgentExecutionContextDTO().setAgentContext(
148151
agentExecutionService.getExecutionContextDTO( chatAgent.getAgentExecution().getExecutionId() ).getAgentContext()
149152
);
150153
}
151-
log.info("Received message from session ID: {}" , sessionId, websocketCommunication.getUniqueIdentifier());
154+
log.info("Received message from session ID: {}, userId {}" , sessionId,
155+
websocketCommunication.getUniqueIdentifier(), userId);
152156
// Handle the message (e.g., process or respond)
153157

154158

@@ -521,9 +525,7 @@ protected void handleTextMessage(WebSocketSession session, TextMessage message)
521525
memoryMeta.get("value") : memoryMeta;
522526

523527
// Add userId to markings for privacy scoping if userId is available
524-
String userId = chatAgent.getAgentExecution().getUser() != null
525-
? chatAgent.getAgentExecution().getUser().getUserId()
526-
: null;
528+
527529
String enhancedMarkings;
528530
if (userId != null && !userId.isEmpty()) {
529531
enhancedMarkings = markings != null
@@ -574,10 +576,7 @@ protected void handleTextMessage(WebSocketSession session, TextMessage message)
574576
JsonNode value = memoryMeta.has("value") ?
575577
memoryMeta.get("value") : memoryMeta;
576578

577-
// Add userId to markings for privacy scoping if userId is available
578-
String userId = chatAgent.getAgentExecution().getUser() != null
579-
? chatAgent.getAgentExecution().getUser().getUserId()
580-
: null;
579+
581580
String enhancedMarkings;
582581
if (userId != null && !userId.isEmpty()) {
583582
enhancedMarkings = markings != null

0 commit comments

Comments
 (0)