UNPKG

@atlaskit/rovo-agent-components

Version:

This package host public components related to rovo agents, the components here are needed for other public atlaskit packages

73 lines (68 loc) 3.79 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.deriveAgentIdentity = deriveAgentIdentity; var _platformFeatureFlags = require("@atlaskit/platform-feature-flags"); var _isAgentCreatorType = require("../../common/utils/is-agent-creator-type"); var _isForgeAgent = require("../../common/utils/is-forge-agent"); /** * 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. */ /** 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. */ 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 = (0, _platformFeatureFlags.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 && (0, _isAgentCreatorType.isAgentCreatorType)(creatorType) ? (0, _isForgeAgent.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 } }; }