Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,40 @@ vi.mock("react-router", () => ({

vi.mock("@api/useGetProjectCasesPage");
vi.mock("@api/useGetProjectFilters");
vi.mock("@api/useGetProjectCases", () => ({
default: () => ({
data: undefined,
isLoading: false,
isError: false,
hasNextPage: false,
isFetchingNextPage: false,
fetchNextPage: vi.fn(),
}),
}));
vi.mock("@api/usePostProjectDeploymentsSearch", () => ({
usePostProjectDeploymentsSearchInfinite: () => ({
data: undefined,
isLoading: false,
hasNextPage: false,
isFetchingNextPage: false,
fetchNextPage: vi.fn(),
}),
}));
vi.mock("@features/settings/api/useGetProjectContacts", () => ({
default: () => ({ data: [], isLoading: false }),
}));
vi.mock("@api/usePostProjectDeploymentsSearch", () => ({
usePostProjectDeploymentsSearchInfinite: () => ({
data: undefined,
isLoading: false,
hasNextPage: false,
isFetchingNextPage: false,
fetchNextPage: vi.fn(),
}),
}));
vi.mock("@features/settings/api/useGetProjectContacts", () => ({
default: () => ({ data: [], isLoading: false }),
}));

vi.mock("@asgardeo/react", () => ({
useAsgardeo: () => ({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,21 +34,16 @@ import type {
export function useConversationRecommendationsSearch(
payload: RecommendationSearchRequest | null,
enabled: boolean,
conversationId?: string,
): UseQueryResult<RecommendationSearchResponse, Error> {
const logger = useLogger();
const { isSignedIn, isLoading: isAuthLoading } = useAsgardeo();
const authFetch = useAuthApiClient();

const msgCount = payload?.chatHistory.length ?? 0;
const firstTs = payload?.chatHistory[0]?.timestamp ?? "";
const lastTs = payload?.chatHistory[msgCount - 1]?.timestamp ?? "";

return useQuery<RecommendationSearchResponse, Error>({
queryKey: [
ApiQueryKeys.CONVERSATION_RECOMMENDATIONS_SEARCH,
msgCount,
firstTs,
lastTs,
conversationId ?? payload?.chatHistory[0]?.timestamp ?? "",
],
Comment thread
SasmithaDilshan marked this conversation as resolved.
queryFn: async (): Promise<RecommendationSearchResponse> => {
if (!payload) {
Expand Down Expand Up @@ -86,6 +81,6 @@ export function useConversationRecommendationsSearch(
payload.chatHistory.length > 0 &&
isSignedIn &&
!isAuthLoading,
staleTime: 10 * 60 * 1000,
staleTime: 45 * 60 * 1000,
});
}
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ export default function ChatHistoryCard({

return (
<Form.CardButton
onClick={() => onItemAction?.(item.chatId, ChatAction.VIEW)}
onClick={() => onItemAction?.(item.chatId, action)}
sx={{
p: 2,
width: "100%",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ import {
getBaseProductOptions,
isUnknownPlaceholderProductLabel,
getBaseDeploymentOptions,
formatChatHistoryForClassification,
} from "@features/support/utils/caseCreation";
import { ChatSender } from "@features/support/types/conversations";
import type { DeploymentProductItem } from "@features/project-details/types/deployments";

describe("caseCreation utils", () => {
Expand Down Expand Up @@ -414,6 +416,31 @@ describe("caseCreation utils", () => {
});
});

describe("formatChatHistoryForClassification", () => {
it("truncates message text to last 150 chars", () => {
const longText = "a".repeat(200);
const result = formatChatHistoryForClassification([
{ text: longText, sender: ChatSender.USER },
]);
expect(result).toBe(`User: ${"a".repeat(150)}`);
});

it("does not truncate messages under 150 chars", () => {
const result = formatChatHistoryForClassification([
{ text: "short message", sender: ChatSender.USER },
]);
expect(result).toBe("User: short message");
});

it("keeps the last 150 chars of a long message", () => {
const text = "start" + "b".repeat(200);
const result = formatChatHistoryForClassification([
{ text, sender: ChatSender.BOT },
]);
expect(result).toBe(`Assistant: ${"b".repeat(150)}`);
});
});

describe("getBaseDeploymentOptions", () => {
it("returns deployment names or type labels", () => {
const deployments = [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import { describe, expect, it } from "vitest";
import {
buildRecommendationRequestFromCase,
buildRecommendationRequestFromConversationMessages,
recommendationScoreToPercent,
} from "@features/support/utils/recommendations";
import type { CaseDetails } from "@features/support/types/cases";
Expand All @@ -33,6 +34,36 @@ describe("recommendationScoreToPercent", () => {
});
});

describe("buildRecommendationRequestFromConversationMessages", () => {
it("returns null for empty messages", () => {
expect(buildRecommendationRequestFromConversationMessages([])).toBeNull();
});

const makeMsg = (content: string) => ({
id: "1",
content,
type: "user",
createdOn: "2026-01-01T00:00:00Z",
isEscalated: false,
hasInlineAttachments: false,
inlineAttachments: [],
});

it("truncates message content to last 150 chars", () => {
const req = buildRecommendationRequestFromConversationMessages([
makeMsg("x".repeat(200)),
]);
expect(req?.chatHistory[0].content).toBe("x".repeat(150));
});

it("does not truncate messages under 150 chars", () => {
const req = buildRecommendationRequestFromConversationMessages([
makeMsg("short message"),
]);
expect(req?.chatHistory[0].content).toBe("short message");
});
});

describe("buildRecommendationRequestFromCase", () => {
it("should return null when case data is undefined", () => {
expect(buildRecommendationRequestFromCase(undefined, [])).toBeNull();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,7 @@ export function formatChatHistoryForClassification(
): string {
return messages
.map((m) => {
const text = (m.text || "").trim();
const text = (m.text || "").trim().slice(-150);
if (!text) return "";
const role = m.sender === ChatSender.USER ? "User" : "Assistant";
return `${role}: ${text}`;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ export function buildRecommendationRequestFromConversationMessages(

const chatHistory: RecommendationApiMessage[] = [];
for (const m of sorted) {
const content = m.content?.trim() ?? "";
const content = (m.content?.trim() ?? "").slice(-150);
if (!content) continue;
const isBot =
m.type?.toLowerCase() === "bot" ||
Expand Down