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:
Dustin Healy 2026-03-07 00:52:55 -08:00
parent 3919d005e5
commit 8797aa35be
5 changed files with 32 additions and 4 deletions

View file

@ -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);

View file

@ -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);

View file

@ -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,

View file

@ -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,

View file

@ -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,