LibreChat/api/server/controllers/agents/__tests__/client.traceContext.spec.js
Danny Avila b181ef0232
🪬 feat: Configure Langfuse Trace User Identity and Metadata (#15667)
* 🪪 feat: Configurable Langfuse Trace User Identity and Metadata

* 🪪 fix: Prefer createRun's conversationId and warn once on an unset userIdField

* 🪪 fix: Validate Langfuse trace field names at the point of use

* 🧹 chore: Sort identity imports

* 🪪 fix: Source the trace model label from the initializer, not a prompt-affecting option

* 🧪 fix: Build the trace context without a prototype so partial client contexts resume

* 📦 chore: Bump `@librechat/agents` to v3.8.0 for the Langfuse trace userId override
2026-09-06 17:30:23 -04:00

38 lines
1.1 KiB
JavaScript

const AgentClient = require('../client');
const { buildTraceContext } = AgentClient;
describe('AgentClient.buildTraceContext', () => {
it('reads the model label from the trace-only option the initializer sets', () => {
expect(
buildTraceContext({
endpoint: 'agents',
endpointType: undefined,
spec: 'support-bot',
traceContext: { modelLabel: 'Helper' },
}),
).toEqual({
endpoint: 'agents',
endpointType: undefined,
modelLabel: 'Helper',
spec: 'support-bot',
});
});
it('falls back to a top-level modelLabel option when no trace context is given', () => {
expect(buildTraceContext({ endpoint: 'openAI', modelLabel: 'Custom' })).toMatchObject({
endpoint: 'openAI',
modelLabel: 'Custom',
});
expect(buildTraceContext({ endpoint: 'openAI' }).modelLabel).toBeUndefined();
});
it('tolerates a client context without options', () => {
expect(buildTraceContext(undefined)).toEqual({
endpoint: undefined,
endpointType: undefined,
modelLabel: undefined,
spec: undefined,
});
});
});