Skip to content

Commit c567e68

Browse files
committed
Enable chat in the Directives
1 parent 3c718bb commit c567e68

File tree

8 files changed

+419
-247
lines changed

8 files changed

+419
-247
lines changed

src/components/Agentic/IncidentDirectives/index.tsx

Lines changed: 291 additions & 195 deletions
Large diffs are not rendered by default.

src/components/Agentic/IncidentDirectives/styles.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,18 +83,23 @@ export const TableBody = styled.div`
8383
color: ${({ theme }) => theme.colors.v3.text.primary};
8484
display: flex;
8585
flex-direction: column;
86+
border: 1px solid ${({ theme }) => theme.colors.v3.surface.sidePanelHeader};
8687
`;
8788

8889
export const TableBodyRow = styled.div`
8990
display: flex;
9091
height: 70px;
9192
box-sizing: border-box;
92-
border-top: 1px solid
93+
border-bottom: 1px solid
9394
${({ theme }) => theme.colors.v3.surface.sidePanelHeader};
9495
9596
&:nth-child(even) {
9697
background: ${({ theme }) => theme.colors.v3.surface.primary};
9798
}
99+
100+
&:first-child {
101+
border-bottom: none;
102+
}
98103
`;
99104

100105
export const TableBodyCell = styled.div`
@@ -132,6 +137,13 @@ export const Directive = styled.span`
132137
color: ${({ theme }) => theme.colors.v3.text.secondary};
133138
`;
134139

140+
export const LoadingContainer = styled.div`
141+
display: flex;
142+
align-items: center;
143+
justify-content: center;
144+
flex-grow: 1;
145+
`;
146+
135147
export const SelectedConditionsContainer = styled.div`
136148
display: flex;
137149
gap: 6px;

src/components/Agentic/IncidentsContainer/CreateIncidentChatOverlay/index.tsx

Lines changed: 36 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
import { fetchEventSource } from "@microsoft/fetch-event-source";
1+
import {
2+
fetchEventSource,
3+
type EventSourceMessage
4+
} from "@microsoft/fetch-event-source";
25
import { useEffect, useRef, useState } from "react";
36
import { useNavigate } from "react-router";
47
import { useAgenticDispatch } from "../../../../containers/Agentic/hooks";
@@ -93,6 +96,11 @@ export const CreateIncidentChatOverlay = () => {
9396
setIncidentId(
9497
response.headers.get("agentic-conversation-id") ?? ""
9598
);
99+
// eslint-disable-next-line no-console
100+
console.log(
101+
`[${new Date().toISOString()}] Got conversation ID:`,
102+
response.headers.get("agentic-conversation-id") ?? ""
103+
);
96104
setIsStartMessageSending(false);
97105
return Promise.resolve();
98106
} else {
@@ -102,26 +110,31 @@ export const CreateIncidentChatOverlay = () => {
102110
);
103111
}
104112
},
105-
// onmessage: (message: EventSourceMessage) => {
106-
// if (message.data) {
107-
// try {
108-
// const parsedData = JSON.parse(
109-
// message.data
110-
// ) as IncidentAgentEvent;
111-
// if (["human", "token"].includes(parsedData.type)) {
112-
// setAccumulatedData((prev) =>
113-
// prev ? [...prev, parsedData] : [parsedData]
114-
// );
115-
// }
116-
// if (parsedData.type === "input_user_required") {
117-
// setIsStartMessageSending(false);
118-
// }
119-
// } catch (error) {
120-
// // eslint-disable-next-line no-console
121-
// console.error("Error parsing message data:", error);
122-
// }
123-
// }
124-
// },
113+
onmessage: (message: EventSourceMessage) => {
114+
// eslint-disable-next-line no-console
115+
console.log(
116+
`[${new Date().toISOString()}] Received message:`,
117+
message
118+
);
119+
// if (message.data) {
120+
// try {
121+
// const parsedData = JSON.parse(
122+
// message.data
123+
// ) as IncidentAgentEvent;
124+
// if (["human", "token"].includes(parsedData.type)) {
125+
// setAccumulatedData((prev) =>
126+
// prev ? [...prev, parsedData] : [parsedData]
127+
// );
128+
// }
129+
// if (parsedData.type === "input_user_required") {
130+
// setIsStartMessageSending(false);
131+
// }
132+
// } catch (error) {
133+
// // eslint-disable-next-line no-console
134+
// console.error("Error parsing message data:", error);
135+
// }
136+
// }
137+
},
125138
onerror: (err: unknown) => {
126139
abortControllerRef.current = null;
127140
setIsStartMessageSending(false);
@@ -138,10 +151,8 @@ export const CreateIncidentChatOverlay = () => {
138151
}
139152
}
140153
);
141-
}
142-
143-
// Send subsequent messages to the incident creation chat
144-
if (incidentId) {
154+
} else {
155+
// Send subsequent messages to the incident creation chat
145156
void sendMessage({
146157
incidentId,
147158
data: { text }

src/components/Agentic/Sidebar/index.tsx

Lines changed: 36 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,19 @@ const isIncidentActive = (incident: IncidentResponseItem): boolean => {
2727
return incident.active_status === "active";
2828
};
2929

30+
const linkButtons: { id: string; label: string; route: string }[] = [
31+
{
32+
id: "incidents",
33+
label: "Directives",
34+
route: "/incidents/directives"
35+
},
36+
{
37+
id: "template",
38+
label: "Template",
39+
route: "/incidents/template"
40+
}
41+
];
42+
3043
export const Sidebar = () => {
3144
const theme = useTheme();
3245
const themeKind = getThemeKind(theme);
@@ -60,16 +73,18 @@ export const Sidebar = () => {
6073
dispatch(setIsCreateIncidentChatOpen(true));
6174
};
6275

63-
const handleDirectivesButtonClick = () => {
64-
sendUserActionTrackingEvent(
65-
trackingEvents.SIDEBAR_DIRECTIVES_BUTTON_CLICKED
66-
);
67-
void navigate("/incidents/directives");
68-
};
76+
const handleLinkButtonClick = (id: string) => () => {
77+
sendUserActionTrackingEvent(trackingEvents.SIDEBAR_LINK_BUTTON_CLICKED, {
78+
id
79+
});
80+
81+
const button = linkButtons.find((button) => button.id === id);
82+
83+
if (!button) {
84+
return;
85+
}
6986

70-
const handleTemplateButtonClick = () => {
71-
sendUserActionTrackingEvent(trackingEvents.SIDEBAR_TEMPLATE_BUTTON_CLICKED);
72-
void navigate("/incidents/template");
87+
void navigate(button.route);
7388
};
7489

7590
const handleLogoutMenuItemClick = () => {
@@ -116,10 +131,6 @@ export const Sidebar = () => {
116131

117132
const user = useAgenticSelector((state) => state.auth.user);
118133
const userInitial = (user?.email[0] ?? "").toLocaleUpperCase();
119-
const isTemplateButtonHighlighted =
120-
location.pathname === "/incidents/template";
121-
const isDirectivesButtonHighlighted =
122-
location.pathname === "/incidents/directives";
123134

124135
return (
125136
<s.Container>
@@ -151,16 +162,18 @@ export const Sidebar = () => {
151162
))}
152163
</s.IncidentsList>
153164
</s.IncidentsListContainer>
154-
<s.LinkButton
155-
buttonType={isDirectivesButtonHighlighted ? "primary" : "secondary"}
156-
label={"Directives"}
157-
onClick={handleDirectivesButtonClick}
158-
/>
159-
<s.LinkButton
160-
buttonType={isTemplateButtonHighlighted ? "primary" : "secondary"}
161-
label={"Template"}
162-
onClick={handleTemplateButtonClick}
163-
/>
165+
{linkButtons.map((button) => {
166+
const isHighlighted = location.pathname === button.route;
167+
168+
return (
169+
<s.LinkButton
170+
key={button.label}
171+
buttonType={isHighlighted ? "primary" : "secondary"}
172+
label={button.label}
173+
onClick={handleLinkButtonClick(button.id)}
174+
/>
175+
);
176+
})}
164177
<NewPopover
165178
content={
166179
<Popup>

src/components/Agentic/common/AgentChat/index.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,8 @@ export const AgentChat = ({
126126
</s.AgentMessage>
127127
);
128128
}
129-
break;
129+
130+
return null;
130131
}
131132
case "memory_update":
132133
return (

src/components/Agentic/tracking.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,7 @@ export const trackingEvents = addPrefix(
99
SIDEBAR_USER_MENU_ITEM_CLICKED: "sidebar user menu item clicked",
1010
SIDEBAR_INCIDENTS_LIST_ITEM_CLICKED: "sidebar incidents list item clicked",
1111
SIDEBAR_CREATE_BUTTON_CLICKED: "sidebar create button clicked",
12-
SIDEBAR_DIRECTIVES_BUTTON_CLICKED: "sidebar directives button clicked",
13-
SIDEBAR_TEMPLATE_BUTTON_CLICKED: "sidebar template button clicked",
12+
SIDEBAR_LINK_BUTTON_CLICKED: "sidebar link button clicked",
1413
INCIDENT_CREATION_CHAT_DIALOG_CLOSED:
1514
"incident creation chat dialog closed",
1615
VIEW_NEW_INCIDENT_LINK_CLICKED: "view incident link clicked",

src/redux/services/digma.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ import type {
2323
GetAssetsResponse,
2424
GetBlockedTracesPayload,
2525
GetBlockedTracesResponse,
26+
GetDirectivesChatEventsPayload,
27+
GetDirectivesChatEventsResponse,
2628
GetDirectivesPayload,
2729
GetDirectivesResponse,
2830
GetEndpointsIssuesPayload,
@@ -92,6 +94,7 @@ import type {
9294
PinErrorPayload,
9395
RecheckInsightPayload,
9496
ResendConfirmationEmailPayload,
97+
SendMessageToDirectivesChatPayload,
9598
SendMessageToIncidentAgentChatPayload,
9699
SendMessageToIncidentCreationChatPayload,
97100
SetEndpointsIssuesPayload,
@@ -649,6 +652,29 @@ export const digmaApi = createApi({
649652
}),
650653
invalidatesTags: ["IncidentAgentDirective"]
651654
}),
655+
sendMessageToIncidentAgentDirectivesChat: builder.mutation<
656+
unknown, // text/event-stream
657+
SendMessageToDirectivesChatPayload
658+
>({
659+
query: ({ conversationId, data }) => ({
660+
url: `Agentic/directives/chat/${window.encodeURIComponent(
661+
conversationId
662+
)}`,
663+
method: "POST",
664+
body: data
665+
}),
666+
invalidatesTags: ["IncidentEntryAgentChatEvent"]
667+
}),
668+
getIncidentAgentDirectivesChatEvents: builder.query<
669+
GetDirectivesChatEventsResponse,
670+
GetDirectivesChatEventsPayload
671+
>({
672+
query: ({ conversationId }) => ({
673+
url: `Agentic/directives/chat/${window.encodeURIComponent(
674+
conversationId
675+
)}/events`
676+
})
677+
}),
652678
getIncidentAgentMCPServers: builder.query<GetMCPServersResponse, void>({
653679
query: () => ({
654680
url: "Agentic/mcps"
@@ -756,6 +782,8 @@ export const {
756782
useSendMessageToIncidentCreationChatMutation,
757783
useGetIncidentAgentDirectivesQuery,
758784
useDeleteIncidentAgentDirectiveMutation,
785+
useSendMessageToIncidentAgentDirectivesChatMutation,
786+
useGetIncidentAgentDirectivesChatEventsQuery,
759787
useGetIncidentAgentMCPServersQuery,
760788
useTestIncidentAgentMCPServerMutation,
761789
useAddIncidentAgentMCPServerMutation,

src/redux/services/types.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1188,6 +1188,7 @@ export interface IncidentAgentEvent {
11881188
agent_name: string;
11891189
tool_name?: string | null;
11901190
mcp_name?: string | null;
1191+
conversation_id?: string;
11911192
}
11921193

11931194
export type GetIncidentAgentEventsResponse = IncidentAgentEvent[];
@@ -1229,6 +1230,17 @@ export interface DeleteIncidentAgentDirectivePayload {
12291230
id: string;
12301231
}
12311232

1233+
export interface SendMessageToDirectivesChatPayload {
1234+
conversationId: string;
1235+
data: { text: string; ids: string[] };
1236+
}
1237+
1238+
export interface GetDirectivesChatEventsPayload {
1239+
conversationId: string;
1240+
}
1241+
1242+
export type GetDirectivesChatEventsResponse = IncidentAgentEvent[];
1243+
12321244
export interface MCPServerData {
12331245
uid: string;
12341246
name: string;

0 commit comments

Comments
 (0)