mirror of
https://github.com/danny-avila/LibreChat.git
synced 2025-09-21 21:50:49 +02:00
🏪 fix: Template for Chats Starting from Agent Marketplace (#9702)
* fix: correctly build conversation template and preset for chats starting from marketplace * test: enhance AgentDetail tests with additional localization and conversation mocks
This commit is contained in:
parent
98af4564e8
commit
c40554c03b
3 changed files with 36 additions and 12 deletions
|
@ -11,9 +11,9 @@ import {
|
||||||
AgentListResponse,
|
AgentListResponse,
|
||||||
} from 'librechat-data-provider';
|
} from 'librechat-data-provider';
|
||||||
import type t from 'librechat-data-provider';
|
import type t from 'librechat-data-provider';
|
||||||
|
import { useLocalize, useDefaultConvo } from '~/hooks';
|
||||||
import { useChatContext } from '~/Providers';
|
import { useChatContext } from '~/Providers';
|
||||||
import { renderAgentAvatar } from '~/utils';
|
import { renderAgentAvatar } from '~/utils';
|
||||||
import { useLocalize } from '~/hooks';
|
|
||||||
|
|
||||||
interface SupportContact {
|
interface SupportContact {
|
||||||
name?: string;
|
name?: string;
|
||||||
|
@ -34,11 +34,11 @@ interface AgentDetailProps {
|
||||||
*/
|
*/
|
||||||
const AgentDetail: React.FC<AgentDetailProps> = ({ agent, isOpen, onClose }) => {
|
const AgentDetail: React.FC<AgentDetailProps> = ({ agent, isOpen, onClose }) => {
|
||||||
const localize = useLocalize();
|
const localize = useLocalize();
|
||||||
// const navigate = useNavigate();
|
const queryClient = useQueryClient();
|
||||||
const { conversation, newConversation } = useChatContext();
|
|
||||||
const { showToast } = useToastContext();
|
const { showToast } = useToastContext();
|
||||||
const dialogRef = useRef<HTMLDivElement>(null);
|
const dialogRef = useRef<HTMLDivElement>(null);
|
||||||
const queryClient = useQueryClient();
|
const getDefaultConversation = useDefaultConvo();
|
||||||
|
const { conversation, newConversation } = useChatContext();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Navigate to chat with the selected agent
|
* Navigate to chat with the selected agent
|
||||||
|
@ -62,13 +62,22 @@ const AgentDetail: React.FC<AgentDetailProps> = ({ agent, isOpen, onClose }) =>
|
||||||
);
|
);
|
||||||
queryClient.invalidateQueries([QueryKeys.messages]);
|
queryClient.invalidateQueries([QueryKeys.messages]);
|
||||||
|
|
||||||
|
/** Template with agent configuration */
|
||||||
|
const template = {
|
||||||
|
conversationId: Constants.NEW_CONVO as string,
|
||||||
|
endpoint: EModelEndpoint.agents,
|
||||||
|
agent_id: agent.id,
|
||||||
|
title: localize('com_agents_chat_with', { name: agent.name || localize('com_ui_agent') }),
|
||||||
|
};
|
||||||
|
|
||||||
|
const currentConvo = getDefaultConversation({
|
||||||
|
conversation: { ...(conversation ?? {}), ...template },
|
||||||
|
preset: template,
|
||||||
|
});
|
||||||
|
|
||||||
newConversation({
|
newConversation({
|
||||||
template: {
|
template: currentConvo,
|
||||||
conversationId: Constants.NEW_CONVO as string,
|
preset: template,
|
||||||
endpoint: EModelEndpoint.agents,
|
|
||||||
agent_id: agent.id,
|
|
||||||
title: `Chat with ${agent.name || 'Agent'}`,
|
|
||||||
},
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -20,6 +20,7 @@ jest.mock('react-router-dom', () => ({
|
||||||
jest.mock('~/hooks', () => ({
|
jest.mock('~/hooks', () => ({
|
||||||
useMediaQuery: jest.fn(() => false), // Mock as desktop by default
|
useMediaQuery: jest.fn(() => false), // Mock as desktop by default
|
||||||
useLocalize: jest.fn(),
|
useLocalize: jest.fn(),
|
||||||
|
useDefaultConvo: jest.fn(),
|
||||||
}));
|
}));
|
||||||
|
|
||||||
jest.mock('@librechat/client', () => ({
|
jest.mock('@librechat/client', () => ({
|
||||||
|
@ -47,7 +48,12 @@ const mockWriteText = jest.fn();
|
||||||
|
|
||||||
const mockNavigate = jest.fn();
|
const mockNavigate = jest.fn();
|
||||||
const mockShowToast = jest.fn();
|
const mockShowToast = jest.fn();
|
||||||
const mockLocalize = jest.fn((key: string) => key);
|
const mockLocalize = jest.fn((key: string, values?: Record<string, any>) => {
|
||||||
|
if (key === 'com_agents_chat_with' && values?.name) {
|
||||||
|
return `Chat with ${values.name}`;
|
||||||
|
}
|
||||||
|
return key;
|
||||||
|
});
|
||||||
|
|
||||||
const mockAgent: t.Agent = {
|
const mockAgent: t.Agent = {
|
||||||
id: 'test-agent-id',
|
id: 'test-agent-id',
|
||||||
|
@ -106,8 +112,12 @@ describe('AgentDetail', () => {
|
||||||
(useNavigate as jest.Mock).mockReturnValue(mockNavigate);
|
(useNavigate as jest.Mock).mockReturnValue(mockNavigate);
|
||||||
const { useToastContext } = require('@librechat/client');
|
const { useToastContext } = require('@librechat/client');
|
||||||
(useToastContext as jest.Mock).mockReturnValue({ showToast: mockShowToast });
|
(useToastContext as jest.Mock).mockReturnValue({ showToast: mockShowToast });
|
||||||
const { useLocalize } = require('~/hooks');
|
const { useLocalize, useDefaultConvo } = require('~/hooks');
|
||||||
(useLocalize as jest.Mock).mockReturnValue(mockLocalize);
|
(useLocalize as jest.Mock).mockReturnValue(mockLocalize);
|
||||||
|
(useDefaultConvo as jest.Mock).mockReturnValue(() => ({
|
||||||
|
conversationId: Constants.NEW_CONVO,
|
||||||
|
endpoint: EModelEndpoint.agents,
|
||||||
|
}));
|
||||||
|
|
||||||
// Mock useChatContext
|
// Mock useChatContext
|
||||||
const { useChatContext } = require('~/Providers');
|
const { useChatContext } = require('~/Providers');
|
||||||
|
@ -227,6 +237,10 @@ describe('AgentDetail', () => {
|
||||||
template: {
|
template: {
|
||||||
conversationId: Constants.NEW_CONVO,
|
conversationId: Constants.NEW_CONVO,
|
||||||
endpoint: EModelEndpoint.agents,
|
endpoint: EModelEndpoint.agents,
|
||||||
|
},
|
||||||
|
preset: {
|
||||||
|
conversationId: Constants.NEW_CONVO,
|
||||||
|
endpoint: EModelEndpoint.agents,
|
||||||
agent_id: 'test-agent-id',
|
agent_id: 'test-agent-id',
|
||||||
title: 'Chat with Test Agent',
|
title: 'Chat with Test Agent',
|
||||||
},
|
},
|
||||||
|
|
|
@ -9,6 +9,7 @@
|
||||||
"com_agents_all_category": "All",
|
"com_agents_all_category": "All",
|
||||||
"com_agents_all_description": "Browse all shared agents across all categories",
|
"com_agents_all_description": "Browse all shared agents across all categories",
|
||||||
"com_agents_by_librechat": "by LibreChat",
|
"com_agents_by_librechat": "by LibreChat",
|
||||||
|
"com_agents_chat_with": "Chat with {{name}}",
|
||||||
"com_agents_category_aftersales": "After Sales",
|
"com_agents_category_aftersales": "After Sales",
|
||||||
"com_agents_category_aftersales_description": "Agents specialized in post-sale support, maintenance, and customer service",
|
"com_agents_category_aftersales_description": "Agents specialized in post-sale support, maintenance, and customer service",
|
||||||
"com_agents_category_empty": "No agents found in the {{category}} category",
|
"com_agents_category_empty": "No agents found in the {{category}} category",
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue