@atlaskit/rovo-agent-components
Version:
This package host public components related to rovo agents, the components here are needed for other public atlaskit packages
69 lines (64 loc) • 3.34 kB
JavaScript
/**
* Shared identity-derivation helper used by AgentInputHat (above the prompt
* input) and AgentResponseHat (above an assistant message). Both components
* need to translate raw agent identity props into the inputs that AgentAvatar
* expects, plus an accessible/visible name pair, with the same fallback
* semantics. Centralising the logic here avoids drift between the two hats —
* historically every change to one needed a paired change to the other.
*/
import { fg } from '@atlaskit/platform-feature-flags';
import { isAgentCreatorType } from '../../common/utils/is-agent-creator-type';
import { isForgeAgentByCreatorType } from '../../common/utils/is-forge-agent';
/** Raw identity input — typically a subset of `Agent` or `message.author`. */
/** Derived props ready to forward to AgentAvatar + the visible name slot. */
/**
* Derive `AgentAvatar` inputs and visible/accessible labels from raw identity.
*
* Behaviour:
* - Specialist path (`agentId` or `agentNamedId` is a non-empty string):
* visible text is the supplied `agentName`, omitted entirely if absent (no
* "Rovo" text next to a specialist avatar). Accessible label falls back to
* the UUID id, then named id, so the avatar is never announced as "Rovo".
* - Default Rovo path (no `agentId` or `agentNamedId`): visible and accessible
* labels are the localized default name (typically "Rovo").
* - Forge identity props are gated internally via `rovo_agent_support_a2a_avatar`
* so callers don't have to.
*/
export function deriveAgentIdentity({
agentId,
agentName,
agentNamedId,
agentIdentityAccountId,
imageUrl,
creatorType,
isForgeAgent: isForgeAgentOverride,
forgeAgentIconUrl,
defaultName
}) {
const trimmedAgentId = typeof agentId === 'string' ? agentId.trim() : undefined;
const specialistAgentId = trimmedAgentId && trimmedAgentId.length > 0 ? trimmedAgentId : undefined;
const trimmedAgentNamedId = typeof agentNamedId === 'string' ? agentNamedId.trim() : undefined;
const specialistAgentNamedId = trimmedAgentNamedId && trimmedAgentNamedId.length > 0 ? trimmedAgentNamedId : undefined;
const specialistIdentity = specialistAgentId !== null && specialistAgentId !== void 0 ? specialistAgentId : specialistAgentNamedId;
const trimmedAgentName = agentName === null || agentName === void 0 ? void 0 : agentName.trim();
const visibleName = specialistIdentity ? trimmedAgentName || undefined : defaultName;
const accessibleName = specialistIdentity ? trimmedAgentName || specialistIdentity : defaultName;
const a2aGateOn = fg('rovo_agent_support_a2a_avatar');
// Prefer the explicit override; otherwise validate creatorType via the
// type guard so the call site doesn't need an unsafe cast.
const isForgeAgent = isForgeAgentOverride !== undefined ? isForgeAgentOverride : creatorType && isAgentCreatorType(creatorType) ? isForgeAgentByCreatorType(creatorType) : undefined;
return {
hasSpecialistIdentity: Boolean(specialistIdentity),
specialistAgentId,
visibleName,
accessibleName,
avatarProps: {
agentId: specialistAgentId,
agentNamedId: specialistAgentNamedId,
agentIdentityAccountId,
imageUrl,
isForgeAgent: a2aGateOn ? isForgeAgent : undefined,
forgeAgentIconUrl: a2aGateOn ? forgeAgentIconUrl : undefined
}
};
}