Skip to content

Commit b790af3

Browse files
committed
Fix Directives chat
1 parent 0514824 commit b790af3

File tree

5 files changed

+88
-82
lines changed

5 files changed

+88
-82
lines changed

src/components/Agentic/IncidentDetails/IncidentMetaData/index.tsx

Lines changed: 42 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { useParams } from "react-router";
44
import { useAgenticDispatch } from "../../../../containers/Agentic/hooks";
55
import { useGetIncidentQuery } from "../../../../redux/services/digma";
66
import { setIncidentToClose } from "../../../../redux/slices/incidentsSlice";
7+
import { intersperse } from "../../../../utils/intersperse";
78
import { Tooltip } from "../../../common/v3/Tooltip";
89
import { Divider } from "./Divider";
910
import * as s from "./styles";
@@ -47,25 +48,25 @@ export const IncidentMetaData = () => {
4748
return <s.Container />;
4849
}
4950

50-
return (
51-
<s.Container>
52-
<s.AttributesList>
53-
{data.status_timestamps.active && (
54-
<s.Attribute>
55-
<s.AttributeLabel>Incident start time:</s.AttributeLabel>
56-
<Tooltip title={new Date(data.status_timestamps.active).toString()}>
57-
<s.AttributeValue>
58-
{format(data.status_timestamps.active, DATE_FORMAT)}
59-
</s.AttributeValue>
60-
</Tooltip>
61-
</s.Attribute>
62-
)}
63-
{data.status_timestamps.closed && (
64-
<>
65-
<s.DividerContainer>
66-
<Divider color={"currentColor"} />
67-
</s.DividerContainer>
68-
<s.Attribute>
51+
const attributes = intersperse(
52+
[
53+
...(data.status_timestamps.active
54+
? [
55+
<s.Attribute key={"start-time"}>
56+
<s.AttributeLabel>Incident start time:</s.AttributeLabel>
57+
<Tooltip
58+
title={new Date(data.status_timestamps.active).toString()}
59+
>
60+
<s.AttributeValue>
61+
{format(data.status_timestamps.active, DATE_FORMAT)}
62+
</s.AttributeValue>
63+
</Tooltip>
64+
</s.Attribute>
65+
]
66+
: []),
67+
...(data.status_timestamps.closed
68+
? [
69+
<s.Attribute key={"close-time"}>
6970
<s.AttributeLabel>Incident close time:</s.AttributeLabel>
7071
<Tooltip
7172
title={new Date(data.status_timestamps.closed).toString()}
@@ -75,14 +76,11 @@ export const IncidentMetaData = () => {
7576
</s.AttributeValue>
7677
</Tooltip>
7778
</s.Attribute>
78-
</>
79-
)}
80-
{data.affected_services.length > 0 && (
81-
<>
82-
<s.DividerContainer>
83-
<Divider color={"currentColor"} />
84-
</s.DividerContainer>
85-
<s.ServicesContainer>
79+
]
80+
: []),
81+
...(data.affected_services.length > 0
82+
? [
83+
<s.ServicesContainer key={"affected-services"}>
8684
<span>Affected services:</span>
8785
{serviceTagsToShow.map((x) => (
8886
<Tooltip key={x} title={x}>
@@ -97,16 +95,23 @@ export const IncidentMetaData = () => {
9795
</Tooltip>
9896
)}
9997
</s.ServicesContainer>
100-
</>
101-
)}
102-
<s.DividerContainer>
103-
<Divider color={"currentColor"} />
104-
</s.DividerContainer>
105-
<s.Attribute>
106-
<s.AttributeLabel>Status:</s.AttributeLabel>
107-
<s.StatusAttributeValue>{data.status}</s.StatusAttributeValue>
108-
</s.Attribute>
109-
</s.AttributesList>
98+
]
99+
: []),
100+
<s.Attribute key={"status"}>
101+
<s.AttributeLabel>Status:</s.AttributeLabel>
102+
<s.StatusAttributeValue>{data.status}</s.StatusAttributeValue>
103+
</s.Attribute>
104+
],
105+
(i) => (
106+
<s.DividerContainer key={`separator-${i}`}>
107+
<Divider color={"currentColor"} />
108+
</s.DividerContainer>
109+
)
110+
);
111+
112+
return (
113+
<s.Container>
114+
<s.AttributesList>{attributes}</s.AttributesList>
110115
{data.status === "pending" && (
111116
<s.CloseIncidentButton
112117
label={"Close incident"}

src/components/Agentic/IncidentTemplate/MCPServerDialog/index.tsx

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,13 @@ export const MCPServerDialog = ({
4242
const handleServerStepConnect = (settings: string) => {
4343
setTestServerError(undefined);
4444

45+
try {
46+
JSON.parse(settings);
47+
} catch {
48+
setTestServerError("Invalid JSON");
49+
return;
50+
}
51+
4552
void testMCPServer({
4653
config_json: settings
4754
})

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

Lines changed: 22 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
import { useMemo, useState } from "react";
1+
import { useEffect, useMemo, useState } from "react";
2+
import { isNumber } from "../../../../typeGuards/isNumber";
23
import { AgentEvent } from "./AgentEvent";
34
import type { AgentEventsListProps } from "./types";
45

5-
// TODO: fix
66
export const AgentEventsList = ({
77
events,
88
onNavigateToIncident,
@@ -11,21 +11,10 @@ export const AgentEventsList = ({
1111
const [initialEventsCount] = useState<number>(
1212
typeInitialEvents ? 0 : events.length
1313
);
14-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
1514
const [eventsVisibleCount, setEventsVisibleCount] = useState<number>(
1615
typeInitialEvents ? 0 : events.length
1716
);
18-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
19-
const [lastRenderedAgentEventIndex, setLastRenderedAgentEventIndex] =
20-
useState<number | undefined>(
21-
typeInitialEvents
22-
? undefined
23-
: events.length > 0
24-
? events.length - 1
25-
: undefined
26-
);
2717

28-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
2918
const agentEventsIndexes = useMemo(
3019
() =>
3120
events.reduce((acc, event, index) => {
@@ -39,15 +28,14 @@ export const AgentEventsList = ({
3928

4029
const handleEventTypingComplete = (id: string) => {
4130
const i = events.findIndex((x) => x.id === id);
42-
setLastRenderedAgentEventIndex(i);
4331

44-
// const nextAgentEventIndex = agentEventsIndexes.find((el) => el > i);
32+
const nextAgentEventIndex = agentEventsIndexes.find((el) => el > i);
4533

46-
// if (isNumber(nextAgentEventIndex) && nextAgentEventIndex >= 0) {
47-
// setEventsVisibleCount(nextAgentEventIndex + 1);
48-
// } else {
49-
// setEventsVisibleCount(events.length);
50-
// }
34+
if (isNumber(nextAgentEventIndex)) {
35+
setEventsVisibleCount(nextAgentEventIndex + 1);
36+
} else {
37+
setEventsVisibleCount(events.length);
38+
}
5139
};
5240

5341
const visibleEvents = useMemo(
@@ -65,6 +53,20 @@ export const AgentEventsList = ({
6553
return index >= initialEventsCount;
6654
};
6755

56+
useEffect(() => {
57+
if (events.length > eventsVisibleCount) {
58+
const nextAgentEventIndex = agentEventsIndexes.find(
59+
(index) => index >= eventsVisibleCount
60+
);
61+
62+
if (isNumber(nextAgentEventIndex)) {
63+
setEventsVisibleCount(nextAgentEventIndex + 1);
64+
} else {
65+
setEventsVisibleCount(events.length);
66+
}
67+
}
68+
}, [events.length, eventsVisibleCount, agentEventsIndexes]);
69+
6870
return visibleEvents.map((event) => (
6971
<AgentEvent
7072
key={event.id}

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

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,10 @@ export const PromptInput = ({
2727
const [textAreaHeight, setTextAreaHeight] = useState<number>(
2828
s.TEXT_AREA_MIN_HEIGHT
2929
);
30-
const [shouldRefocus, setShouldRefocus] = useState(false);
3130

3231
const handleSubmit = (e: FormEvent) => {
3332
e.preventDefault();
3433
if (!isSubmittingDisabled) {
35-
setShouldRefocus(true);
3634
onSubmit();
3735
}
3836
};
@@ -82,14 +80,6 @@ export const PromptInput = ({
8280
}
8381
}, [value, fontSize]);
8482

85-
// TODO: check if working
86-
useEffect(() => {
87-
if (shouldRefocus && value === "" && textAreaRef.current) {
88-
textAreaRef.current.focus();
89-
setShouldRefocus(false);
90-
}
91-
}, [value, shouldRefocus]);
92-
9383
const formHeight = textAreaHeight + s.FORM_TOP_BOTTOM_PADDING * 2;
9484

9585
return (
@@ -109,7 +99,7 @@ export const PromptInput = ({
10999
onChange={handleChange}
110100
placeholder={placeholder}
111101
onKeyDown={handleKeyDown}
112-
disabled={isDisabled ?? isSubmittingDisabled}
102+
disabled={isDisabled}
113103
/>
114104
</s.TextAreaContainer>
115105
<s.SubmitButton type={"submit"} disabled={isSubmittingDisabled}>

src/redux/services/digma.ts

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@ export const digmaApi = createApi({
123123
"IncidentAgentChatEvent",
124124
"IncidentEntryAgentChatEvent",
125125
"IncidentAgentDirective",
126+
"IncidentDirectivesAgentChatEvent",
126127
"IncidentAgentMCPServer"
127128
],
128129
reducerPath: "digmaApi",
@@ -662,19 +663,6 @@ export const digmaApi = createApi({
662663
}),
663664
invalidatesTags: ["IncidentAgentDirective"]
664665
}),
665-
sendMessageToIncidentAgentDirectivesChat: builder.mutation<
666-
unknown, // text/event-stream
667-
SendMessageToDirectivesChatPayload
668-
>({
669-
query: ({ conversationId, data }) => ({
670-
url: `Agentic/directives/chat/${window.encodeURIComponent(
671-
conversationId
672-
)}`,
673-
method: "POST",
674-
body: data
675-
}),
676-
invalidatesTags: ["IncidentEntryAgentChatEvent"]
677-
}),
678666
getIncidentAgentDirectivesChatEvents: builder.query<
679667
ExtendedGetDirectivesChatEventsResponse,
680668
GetDirectivesChatEventsPayload
@@ -691,7 +679,21 @@ export const digmaApi = createApi({
691679
) => ({
692680
data: response,
693681
extra: arg
694-
})
682+
}),
683+
providesTags: ["IncidentDirectivesAgentChatEvent"]
684+
}),
685+
sendMessageToIncidentAgentDirectivesChat: builder.mutation<
686+
unknown, // text/event-stream
687+
SendMessageToDirectivesChatPayload
688+
>({
689+
query: ({ conversationId, data }) => ({
690+
url: `Agentic/directives/chat/${window.encodeURIComponent(
691+
conversationId
692+
)}`,
693+
method: "POST",
694+
body: data
695+
}),
696+
invalidatesTags: ["IncidentDirectivesAgentChatEvent"]
695697
}),
696698
getIncidentAgentMCPServers: builder.query<GetMCPServersResponse, void>({
697699
query: () => ({

0 commit comments

Comments
 (0)