@atlaskit/rovo-agent-components
Version:
This package host public components related to rovo agents, the components here are needed for other public atlaskit packages
137 lines • 6.1 kB
JavaScript
/* index.tsx generated by @compiled/babel-plugin v0.39.1 */
import _extends from "@babel/runtime/helpers/extends";
import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";
var _excluded = ["userDefinedConversationStarters", "isAgentDefault"];
import "./index.compiled.css";
import { ax, ix } from "@compiled/react/runtime";
import React, { useMemo } from 'react';
import { useIntl } from 'react-intl';
import { IconButton } from '@atlaskit/button/new';
import RetryIcon from '@atlaskit/icon/core/retry';
import { Box, Inline, Pressable, Stack } from '@atlaskit/primitives/compiled';
import { AgentChatIcon } from '../../common/ui/agent-chat-icon';
import { BrowseAgentsPill } from '../../common/ui/chat-pill';
import { messages } from './messages';
var styles = {
conversationStartersList: "_qtt8glyw _ca0qidpf _u5f3idpf _n3tdidpf _19bvidpf _1bsb1osq",
conversationStarterIcon: "_1o9zidpf",
conversationStarterText: "_1reo15vq _18m915vq _1bto1l2s _o5721q9c _1o9zkb7n _1ul9idpf",
button: "_11c8fhey _2rko12b0 _syazazsu _ca0q12x7 _u5f312x7 _n3td12x7 _19bv12x7 _k48p1wq8 _1bto1l2s _o5721q9c _1o9zkb7n _1bsb1osq _bfhksm61 _irr31dpa _1di6fcek"
};
export var getConversationStarters = function getConversationStarters(_ref) {
var userDefinedConversationStartersParam = _ref.userDefinedConversationStarters,
isAgentDefault = _ref.isAgentDefault;
var type = 'static';
var customAgentConversationStarters = [{
message: messages.agentEmptyStateSuggestion1,
type: type
}, {
message: messages.agentEmptyStateSuggestion2,
type: type
}, {
message: messages.agentEmptyStateSuggestion3,
type: type
}];
var userDefinedConversationStarters = userDefinedConversationStartersParam !== null && userDefinedConversationStartersParam !== void 0 ? userDefinedConversationStartersParam : [];
var defaultAgentConversationStarters = [{
message: messages.emptyStateSuggestion1,
type: type
}, {
message: messages.emptyStateSuggestion2,
type: type
}, {
message: messages.emptyStateSuggestion3,
type: type
}];
var getCombinedConversationStarters = function getCombinedConversationStarters() {
var shouldCombine = !isAgentDefault;
if (shouldCombine) {
// Return user defined suggestions + static fallback suggestions with a max of 3 suggestions (user defined taking precendence over fallback)
return [].concat(_toConsumableArray(userDefinedConversationStarters), customAgentConversationStarters).slice(0, 3);
}
return defaultAgentConversationStarters;
};
return {
userDefinedConversationStarters: userDefinedConversationStarters,
customAgentConversationStarters: customAgentConversationStarters,
defaultAgentConversationStarters: defaultAgentConversationStarters,
combinedConversationStarters: getCombinedConversationStarters()
};
};
export var AgentConversationStarters = function AgentConversationStarters(_ref2) {
var userDefinedConversationStarters = _ref2.userDefinedConversationStarters,
isAgentDefault = _ref2.isAgentDefault,
props = _objectWithoutProperties(_ref2, _excluded);
var _useIntl = useIntl(),
formatMessage = _useIntl.formatMessage;
var _useMemo = useMemo(function () {
return getConversationStarters({
userDefinedConversationStarters: userDefinedConversationStarters,
isAgentDefault: isAgentDefault
});
}, [userDefinedConversationStarters, isAgentDefault]),
combinedConversationStarters = _useMemo.combinedConversationStarters;
var starters = useMemo(function () {
return combinedConversationStarters.map(function (starter) {
return typeof starter.message === 'string' ? {
message: starter.message,
type: starter.type
} : {
message: formatMessage(starter.message),
type: starter.type
};
});
}, [combinedConversationStarters, formatMessage]);
return /*#__PURE__*/React.createElement(ConversationStarters, _extends({
starters: starters
}, props));
};
export var ConversationStarters = function ConversationStarters(_ref3) {
var starters = _ref3.starters,
onConversationStarterClick = _ref3.onConversationStarterClick,
_ref3$showReloadButto = _ref3.showReloadButton,
showReloadButton = _ref3$showReloadButto === void 0 ? false : _ref3$showReloadButto,
_ref3$onReloadButtonC = _ref3.onReloadButtonClick,
onReloadButtonClick = _ref3$onReloadButtonC === void 0 ? function () {} : _ref3$onReloadButtonC,
onBrowseAgentsClick = _ref3.onBrowseAgentsClick;
return /*#__PURE__*/React.createElement(Stack, {
as: "ul",
space: "space.050",
xcss: styles.conversationStartersList
}, starters.map(function (starter, index) {
var isLastStarter = index === starters.length - 1;
var chatPill = /*#__PURE__*/React.createElement(Box, {
as: "li",
key: starter.message
}, /*#__PURE__*/React.createElement(Pressable, {
xcss: styles.button,
onClick: function onClick() {
return onConversationStarterClick(starter);
},
testId: "conversation-starter"
}, /*#__PURE__*/React.createElement(Inline, {
space: "space.150",
alignBlock: "center"
}, /*#__PURE__*/React.createElement(Box, {
xcss: styles.conversationStarterIcon
}, /*#__PURE__*/React.createElement(AgentChatIcon, null)), /*#__PURE__*/React.createElement(Box, {
xcss: styles.conversationStarterText
}, starter.message))));
return isLastStarter && showReloadButton ? /*#__PURE__*/React.createElement(Inline, {
space: "space.050",
grow: "fill",
alignInline: "end",
key: starter.message
}, chatPill, /*#__PURE__*/React.createElement(IconButton, {
icon: RetryIcon,
onClick: onReloadButtonClick,
appearance: "subtle",
label: ""
})) : chatPill;
}), !!onBrowseAgentsClick && /*#__PURE__*/React.createElement(Box, {
as: "li"
}, /*#__PURE__*/React.createElement(BrowseAgentsPill, {
onClick: onBrowseAgentsClick
})));
};