mirror of
https://github.com/danny-avila/LibreChat.git
synced 2026-07-10 08:13:46 +00:00
fix: Guard optional agent_name and add config assertions
Conditionally spread agent_name in configurable to avoid sending undefined when agents have no name set. Add processStream config assertions to openai and responses controller tests.
This commit is contained in:
parent
3919d005e5
commit
8797aa35be
5 changed files with 32 additions and 4 deletions
|
|
@ -160,6 +160,20 @@ describe('OpenAIChatCompletionController', () => {
|
|||
};
|
||||
});
|
||||
|
||||
describe('processStream config', () => {
|
||||
it('should pass agent_id and dynamic runName in config.configurable', async () => {
|
||||
const api = require('@librechat/api');
|
||||
await OpenAIChatCompletionController(req, res);
|
||||
|
||||
const run = await api.createRun.mock.results[0].value;
|
||||
const config = run.processStream.mock.calls[0][1];
|
||||
|
||||
expect(config.runName).toBe('gpt-4');
|
||||
expect(config.configurable.agent_id).toBe('agent-123');
|
||||
expect(config.configurable).not.toHaveProperty('agent_name');
|
||||
});
|
||||
});
|
||||
|
||||
describe('token usage recording', () => {
|
||||
it('should call recordCollectedUsage after successful non-streaming completion', async () => {
|
||||
await OpenAIChatCompletionController(req, res);
|
||||
|
|
|
|||
|
|
@ -189,6 +189,20 @@ describe('createResponse controller', () => {
|
|||
};
|
||||
});
|
||||
|
||||
describe('processStream config', () => {
|
||||
it('should pass agent_id, agent_name, and dynamic runName in config.configurable', async () => {
|
||||
const api = require('@librechat/api');
|
||||
await createResponse(req, res);
|
||||
|
||||
const run = await api.createRun.mock.results[0].value;
|
||||
const config = run.processStream.mock.calls[0][1];
|
||||
|
||||
expect(config.runName).toBe('Test Agent');
|
||||
expect(config.configurable.agent_id).toBe('agent-123');
|
||||
expect(config.configurable.agent_name).toBe('Test Agent');
|
||||
});
|
||||
});
|
||||
|
||||
describe('token usage recording - non-streaming', () => {
|
||||
it('should call recordCollectedUsage after successful non-streaming completion', async () => {
|
||||
await createResponse(req, res);
|
||||
|
|
|
|||
|
|
@ -732,7 +732,7 @@ class AgentClient extends BaseClient {
|
|||
user_id: this.user ?? this.options.req.user?.id,
|
||||
hide_sequential_outputs: this.options.agent.hide_sequential_outputs,
|
||||
agent_id: this.options.agent.id,
|
||||
agent_name: this.options.agent.name,
|
||||
...(this.options.agent.name != null && { agent_name: this.options.agent.name }),
|
||||
requestBody: {
|
||||
messageId: this.responseMessageId,
|
||||
conversationId: this.conversationId,
|
||||
|
|
|
|||
|
|
@ -471,7 +471,7 @@ const OpenAIChatCompletionController = async (req, res) => {
|
|||
thread_id: conversationId,
|
||||
user_id: userId,
|
||||
agent_id: agent.id,
|
||||
agent_name: agent.name,
|
||||
...(agent.name != null && { agent_name: agent.name }),
|
||||
user: createSafeUser(req.user),
|
||||
requestBody: {
|
||||
messageId: responseId,
|
||||
|
|
|
|||
|
|
@ -487,7 +487,7 @@ const createResponse = async (req, res) => {
|
|||
thread_id: conversationId,
|
||||
user_id: userId,
|
||||
agent_id: agent.id,
|
||||
agent_name: agent.name,
|
||||
...(agent.name != null && { agent_name: agent.name }),
|
||||
user: createSafeUser(req.user),
|
||||
requestBody: {
|
||||
messageId: responseId,
|
||||
|
|
@ -643,7 +643,7 @@ const createResponse = async (req, res) => {
|
|||
thread_id: conversationId,
|
||||
user_id: userId,
|
||||
agent_id: agent.id,
|
||||
agent_name: agent.name,
|
||||
...(agent.name != null && { agent_name: agent.name }),
|
||||
user: createSafeUser(req.user),
|
||||
requestBody: {
|
||||
messageId: responseId,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue