Skip to content

Enhanced ChatGPT Clone: Features Agents, MCP, Skills, DeepSeek, Anthropic, AWS, OpenAI, Responses API, Azure, Groq, o1, GPT-5, Mistral, OpenRouter, Vertex AI, Gemini, Artifacts, AI model switching, message search, Code Interpreter, langchain, DALL-E-3, OpenAPI Actions, Functions, Secure Multi-User Auth, Presets, open-source for self-hosting. Active

1.4 KB
Raw Blame
import { getResponseSender, getEphemeralSender, isEphemeralAgentId } from 'librechat-data-provider';
import type { Agent, TEndpointOption } from 'librechat-data-provider';

/**
 * Resolves the display name persisted as `message.sender` for a response.
 *
 * Real agents use their own name. Ephemeral agents run the same label chain
 * `loadEphemeralAgent` encodes into their id (`modelLabel` → spec label →
 * endpoint `modelDisplayLabel`), recomputed here from the exact source values
 * rather than decoded from the id — the id encoding is lossy for labels
 * containing `__`/`___` sequences, and the persisted sender must match the
 * configured label verbatim. `getResponseSender` remains the fallback for
 * label-less agents (model-derived names such as `Claude` or `GPT-5`, family
 * heuristics, `'AI'`).
 */
export function resolveSender({
  agent,
  specLabel,
  endpointOption,
}: {
  agent: Partial<Pick<Agent, 'id' | 'name'>>;
  specLabel?: string | null;
  endpointOption: Partial<TEndpointOption>;
}): string {
  if (agent.name != null) {
    return agent.name;
  }
  if (agent.id != null && isEphemeralAgentId(agent.id)) {
    const sender = getEphemeralSender({
      modelLabel: endpointOption.modelLabel,
      specLabel,
      modelDisplayLabel: endpointOption.modelDisplayLabel,
    });
    if (sender) {
      return sender;
    }
  }
  return getResponseSender(endpointOption);
}