@atlaskit/rovo-agent-components
Version:
This package host public components related to rovo agents, the components here are needed for other public atlaskit packages
68 lines (63 loc) • 3.59 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(_ref) {
var agentId = _ref.agentId,
agentName = _ref.agentName,
agentNamedId = _ref.agentNamedId,
agentIdentityAccountId = _ref.agentIdentityAccountId,
imageUrl = _ref.imageUrl,
creatorType = _ref.creatorType,
isForgeAgentOverride = _ref.isForgeAgent,
forgeAgentIconUrl = _ref.forgeAgentIconUrl,
defaultName = _ref.defaultName;
var trimmedAgentId = typeof agentId === 'string' ? agentId.trim() : undefined;
var specialistAgentId = trimmedAgentId && trimmedAgentId.length > 0 ? trimmedAgentId : undefined;
var trimmedAgentNamedId = typeof agentNamedId === 'string' ? agentNamedId.trim() : undefined;
var specialistAgentNamedId = trimmedAgentNamedId && trimmedAgentNamedId.length > 0 ? trimmedAgentNamedId : undefined;
var specialistIdentity = specialistAgentId !== null && specialistAgentId !== void 0 ? specialistAgentId : specialistAgentNamedId;
var trimmedAgentName = agentName === null || agentName === void 0 ? void 0 : agentName.trim();
var visibleName = specialistIdentity ? trimmedAgentName || undefined : defaultName;
var accessibleName = specialistIdentity ? trimmedAgentName || specialistIdentity : defaultName;
var 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.
var isForgeAgent = isForgeAgentOverride !== undefined ? isForgeAgentOverride : creatorType && isAgentCreatorType(creatorType) ? isForgeAgentByCreatorType(creatorType) : undefined;
return {
hasSpecialistIdentity: Boolean(specialistIdentity),
specialistAgentId: specialistAgentId,
visibleName: visibleName,
accessibleName: accessibleName,
avatarProps: {
agentId: specialistAgentId,
agentNamedId: specialistAgentNamedId,
agentIdentityAccountId: agentIdentityAccountId,
imageUrl: imageUrl,
isForgeAgent: a2aGateOn ? isForgeAgent : undefined,
forgeAgentIconUrl: a2aGateOn ? forgeAgentIconUrl : undefined
}
};
}