Extract the shared assistant-name predicate (resolveAssistantName: trimmed name or null) used by typing-indicator + message-item, and unit-test the branches (name shown; whitespace-only -> 'AI agent' fallback; undefined -> fallback). Behavior-identical (|| -> ?? since the helper returns null). Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
17 lines
782 B
TypeScript
17 lines
782 B
TypeScript
// Pure helper for resolving the assistant's display name. Kept free of React so
|
|
// it can be unit-tested in isolation (see assistant-name.test.ts) and shared by
|
|
// the components that render the assistant identity (TypingIndicator, MessageItem).
|
|
|
|
/**
|
|
* Resolve the assistant's display name from the optional configured identity.
|
|
*
|
|
* Returns the trimmed name when it has visible (non-whitespace) characters, or
|
|
* `null` when the name is absent or whitespace-only. Callers fall back to a
|
|
* generic "AI agent" label on `null`. The `.trim()` is why a name of " " must
|
|
* resolve to `null` rather than rendering an empty label.
|
|
*/
|
|
export function resolveAssistantName(assistantName?: string): string | null {
|
|
const name = assistantName?.trim();
|
|
return name ? name : null;
|
|
}
|