instantsearch-ui-components 0.11.2 → 0.13.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/components/Button.js +29 -0
- package/dist/cjs/components/Carousel.js +26 -6
- package/dist/cjs/components/autocomplete/Autocomplete.js +23 -0
- package/dist/cjs/components/autocomplete/AutocompleteIndex.js +44 -0
- package/dist/cjs/components/autocomplete/AutocompletePanel.js +25 -0
- package/dist/cjs/components/autocomplete/AutocompleteSearch.js +70 -0
- package/dist/cjs/components/autocomplete/AutocompleteSuggestion.js +20 -0
- package/dist/cjs/components/autocomplete/createAutocompletePropGetters.js +222 -0
- package/dist/cjs/components/autocomplete/icons.js +56 -0
- package/dist/cjs/components/autocomplete/index.js +71 -0
- package/dist/cjs/components/chat/Chat.js +79 -0
- package/dist/cjs/components/chat/ChatHeader.js +89 -0
- package/dist/cjs/components/chat/ChatMessage.js +138 -0
- package/dist/cjs/components/chat/ChatMessageError.js +57 -0
- package/dist/cjs/components/chat/ChatMessageLoader.js +47 -0
- package/dist/cjs/components/chat/ChatMessages.js +192 -0
- package/dist/cjs/components/chat/ChatPrompt.js +179 -0
- package/dist/cjs/components/chat/ChatToggleButton.js +46 -0
- package/dist/cjs/components/chat/icons.js +375 -0
- package/dist/cjs/components/chat/types.js +1 -0
- package/dist/cjs/components/index.js +132 -0
- package/dist/cjs/lib/index.js +22 -0
- package/dist/cjs/lib/stickToBottom.js +481 -0
- package/dist/cjs/lib/utils/find.js +15 -0
- package/dist/cjs/lib/utils/index.js +27 -0
- package/dist/cjs/lib/utils/startsWith.js +9 -0
- package/dist/cjs/version.js +1 -1
- package/dist/cjs/warn.js +40 -0
- package/dist/es/components/Button.d.ts +38 -0
- package/dist/es/components/Button.js +22 -0
- package/dist/es/components/Carousel.d.ts +11 -0
- package/dist/es/components/Carousel.js +26 -6
- package/dist/es/components/autocomplete/Autocomplete.d.ts +13 -0
- package/dist/es/components/autocomplete/Autocomplete.js +16 -0
- package/dist/es/components/autocomplete/AutocompleteIndex.d.ts +38 -0
- package/dist/es/components/autocomplete/AutocompleteIndex.js +37 -0
- package/dist/es/components/autocomplete/AutocompletePanel.d.ts +17 -0
- package/dist/es/components/autocomplete/AutocompletePanel.js +18 -0
- package/dist/es/components/autocomplete/AutocompleteSearch.d.ts +8 -0
- package/dist/es/components/autocomplete/AutocompleteSearch.js +63 -0
- package/dist/es/components/autocomplete/AutocompleteSuggestion.d.ts +16 -0
- package/dist/es/components/autocomplete/AutocompleteSuggestion.js +14 -0
- package/dist/es/components/autocomplete/createAutocompletePropGetters.d.ts +49 -0
- package/dist/es/components/autocomplete/createAutocompletePropGetters.js +215 -0
- package/dist/es/components/autocomplete/icons.d.ts +7 -0
- package/dist/es/components/autocomplete/icons.js +48 -0
- package/dist/es/components/autocomplete/index.d.ts +6 -0
- package/dist/es/components/autocomplete/index.js +6 -0
- package/dist/es/components/chat/Chat.d.ts +42 -0
- package/dist/es/components/chat/Chat.js +72 -0
- package/dist/es/components/chat/ChatHeader.d.ts +99 -0
- package/dist/es/components/chat/ChatHeader.js +82 -0
- package/dist/es/components/chat/ChatMessage.d.ts +124 -0
- package/dist/es/components/chat/ChatMessage.js +131 -0
- package/dist/es/components/chat/ChatMessageError.d.ts +27 -0
- package/dist/es/components/chat/ChatMessageError.js +50 -0
- package/dist/es/components/chat/ChatMessageLoader.d.ts +15 -0
- package/dist/es/components/chat/ChatMessageLoader.js +40 -0
- package/dist/es/components/chat/ChatMessages.d.ts +139 -0
- package/dist/es/components/chat/ChatMessages.js +185 -0
- package/dist/es/components/chat/ChatPrompt.d.ts +119 -0
- package/dist/es/components/chat/ChatPrompt.js +172 -0
- package/dist/es/components/chat/ChatToggleButton.d.ts +29 -0
- package/dist/es/components/chat/ChatToggleButton.js +39 -0
- package/dist/es/components/chat/icons.d.ts +22 -0
- package/dist/es/components/chat/icons.js +355 -0
- package/dist/es/components/chat/types.d.ts +29 -0
- package/dist/es/components/chat/types.js +1 -0
- package/dist/es/components/index.d.ts +12 -0
- package/dist/es/components/index.js +12 -0
- package/dist/es/lib/index.d.ts +2 -0
- package/dist/es/lib/index.js +3 -1
- package/dist/es/lib/stickToBottom.d.ts +114 -0
- package/dist/es/lib/stickToBottom.js +474 -0
- package/dist/es/lib/utils/find.d.ts +1 -0
- package/dist/es/lib/utils/find.js +9 -0
- package/dist/es/lib/utils/index.d.ts +2 -0
- package/dist/es/lib/utils/index.js +2 -0
- package/dist/es/lib/utils/startsWith.d.ts +1 -0
- package/dist/es/lib/utils/startsWith.js +3 -0
- package/dist/es/types/Renderer.d.ts +1 -1
- package/dist/es/version.d.ts +1 -1
- package/dist/es/version.js +1 -1
- package/dist/es/warn.d.ts +10 -0
- package/dist/es/warn.js +33 -0
- package/package.json +7 -3
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
import type { ComponentProps, Renderer } from '../../types';
|
|
2
|
+
import type { ChatMessageBase, ClientSideTools } from './types';
|
|
3
|
+
export type ChatMessageSide = 'left' | 'right';
|
|
4
|
+
export type ChatMessageVariant = 'neutral' | 'subtle';
|
|
5
|
+
export type ChatMessageTranslations = {
|
|
6
|
+
/**
|
|
7
|
+
* The label for the message
|
|
8
|
+
*/
|
|
9
|
+
messageLabel: string;
|
|
10
|
+
/**
|
|
11
|
+
* The label for message actions
|
|
12
|
+
*/
|
|
13
|
+
actionsLabel: string;
|
|
14
|
+
};
|
|
15
|
+
export type ChatMessageClassNames = {
|
|
16
|
+
/**
|
|
17
|
+
* Class names to apply to the root element
|
|
18
|
+
*/
|
|
19
|
+
root: string | string[];
|
|
20
|
+
/**
|
|
21
|
+
* Class names to apply to the container element
|
|
22
|
+
*/
|
|
23
|
+
container: string | string[];
|
|
24
|
+
/**
|
|
25
|
+
* Class names to apply to the leading element (avatar area)
|
|
26
|
+
*/
|
|
27
|
+
leading: string | string[];
|
|
28
|
+
/**
|
|
29
|
+
* Class names to apply to the content wrapper
|
|
30
|
+
*/
|
|
31
|
+
content: string | string[];
|
|
32
|
+
/**
|
|
33
|
+
* Class names to apply to the message element
|
|
34
|
+
*/
|
|
35
|
+
message: string | string[];
|
|
36
|
+
/**
|
|
37
|
+
* Class names to apply to the actions container
|
|
38
|
+
*/
|
|
39
|
+
actions: string | string[];
|
|
40
|
+
/**
|
|
41
|
+
* Class names to apply to the footer element
|
|
42
|
+
*/
|
|
43
|
+
footer: string | string[];
|
|
44
|
+
};
|
|
45
|
+
export type ChatMessageActionProps = {
|
|
46
|
+
/**
|
|
47
|
+
* The icon to display in the action button
|
|
48
|
+
*/
|
|
49
|
+
icon?: () => JSX.Element;
|
|
50
|
+
/**
|
|
51
|
+
* The title/tooltip for the action
|
|
52
|
+
*/
|
|
53
|
+
title?: string;
|
|
54
|
+
/**
|
|
55
|
+
* Whether the action is disabled
|
|
56
|
+
*/
|
|
57
|
+
disabled?: boolean;
|
|
58
|
+
/**
|
|
59
|
+
* Click handler for the action
|
|
60
|
+
*/
|
|
61
|
+
onClick?: (message: ChatMessageBase) => void;
|
|
62
|
+
};
|
|
63
|
+
export type ChatMessageProps = ComponentProps<'article'> & {
|
|
64
|
+
/**
|
|
65
|
+
* The message object associated with this chat message
|
|
66
|
+
*/
|
|
67
|
+
message: ChatMessageBase;
|
|
68
|
+
/**
|
|
69
|
+
* The side of the message
|
|
70
|
+
*/
|
|
71
|
+
side?: ChatMessageSide;
|
|
72
|
+
/**
|
|
73
|
+
* The variant of the message
|
|
74
|
+
*/
|
|
75
|
+
variant?: ChatMessageVariant;
|
|
76
|
+
/**
|
|
77
|
+
* Array of action buttons
|
|
78
|
+
*/
|
|
79
|
+
actions?: ChatMessageActionProps[];
|
|
80
|
+
/**
|
|
81
|
+
* Whether to auto-hide actions until hover
|
|
82
|
+
*/
|
|
83
|
+
autoHideActions?: boolean;
|
|
84
|
+
/**
|
|
85
|
+
* Leading content
|
|
86
|
+
*/
|
|
87
|
+
leadingComponent?: () => JSX.Element;
|
|
88
|
+
/**
|
|
89
|
+
* Custom actions renderer
|
|
90
|
+
*/
|
|
91
|
+
actionsComponent?: (props: {
|
|
92
|
+
actions: ChatMessageActionProps[];
|
|
93
|
+
message: ChatMessageBase;
|
|
94
|
+
}) => JSX.Element | null;
|
|
95
|
+
/**
|
|
96
|
+
* Footer content
|
|
97
|
+
*/
|
|
98
|
+
footerComponent?: () => JSX.Element;
|
|
99
|
+
/**
|
|
100
|
+
* The index UI state
|
|
101
|
+
*/
|
|
102
|
+
indexUiState: object;
|
|
103
|
+
/**
|
|
104
|
+
* Set the index UI state
|
|
105
|
+
*/
|
|
106
|
+
setIndexUiState: (state: object) => void;
|
|
107
|
+
/**
|
|
108
|
+
* Close the chat
|
|
109
|
+
*/
|
|
110
|
+
onClose: () => void;
|
|
111
|
+
/**
|
|
112
|
+
* Array of tools available for the assistant (for tool messages)
|
|
113
|
+
*/
|
|
114
|
+
tools: ClientSideTools;
|
|
115
|
+
/**
|
|
116
|
+
* Optional class names
|
|
117
|
+
*/
|
|
118
|
+
classNames?: Partial<ChatMessageClassNames>;
|
|
119
|
+
/**
|
|
120
|
+
* Optional translations
|
|
121
|
+
*/
|
|
122
|
+
translations?: Partial<ChatMessageTranslations>;
|
|
123
|
+
};
|
|
124
|
+
export declare function createChatMessageComponent({ createElement }: Renderer): (userProps: ChatMessageProps) => JSX.Element;
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
import _extends from "@babel/runtime/helpers/extends";
|
|
2
|
+
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
3
|
+
import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
|
|
4
|
+
var _excluded = ["classNames", "message", "side", "variant", "actions", "autoHideActions", "leadingComponent", "actionsComponent", "footerComponent", "tools", "indexUiState", "setIndexUiState", "onClose", "translations"];
|
|
5
|
+
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
6
|
+
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
7
|
+
import { compiler } from 'markdown-to-jsx';
|
|
8
|
+
import { cx, startsWith } from "../../lib/index.js";
|
|
9
|
+
import { createButtonComponent } from "../Button.js";
|
|
10
|
+
import { MenuIconComponent } from "./icons.js";
|
|
11
|
+
export function createChatMessageComponent(_ref) {
|
|
12
|
+
var createElement = _ref.createElement;
|
|
13
|
+
var Button = createButtonComponent({
|
|
14
|
+
createElement: createElement
|
|
15
|
+
});
|
|
16
|
+
return function ChatMessage(userProps) {
|
|
17
|
+
var _userProps$classNames = userProps.classNames,
|
|
18
|
+
classNames = _userProps$classNames === void 0 ? {} : _userProps$classNames,
|
|
19
|
+
message = userProps.message,
|
|
20
|
+
_userProps$side = userProps.side,
|
|
21
|
+
side = _userProps$side === void 0 ? 'left' : _userProps$side,
|
|
22
|
+
_userProps$variant = userProps.variant,
|
|
23
|
+
variant = _userProps$variant === void 0 ? 'subtle' : _userProps$variant,
|
|
24
|
+
_userProps$actions = userProps.actions,
|
|
25
|
+
actions = _userProps$actions === void 0 ? [] : _userProps$actions,
|
|
26
|
+
_userProps$autoHideAc = userProps.autoHideActions,
|
|
27
|
+
autoHideActions = _userProps$autoHideAc === void 0 ? false : _userProps$autoHideAc,
|
|
28
|
+
LeadingComponent = userProps.leadingComponent,
|
|
29
|
+
ActionsComponent = userProps.actionsComponent,
|
|
30
|
+
FooterComponent = userProps.footerComponent,
|
|
31
|
+
_userProps$tools = userProps.tools,
|
|
32
|
+
tools = _userProps$tools === void 0 ? {} : _userProps$tools,
|
|
33
|
+
indexUiState = userProps.indexUiState,
|
|
34
|
+
setIndexUiState = userProps.setIndexUiState,
|
|
35
|
+
onClose = userProps.onClose,
|
|
36
|
+
userTranslations = userProps.translations,
|
|
37
|
+
props = _objectWithoutProperties(userProps, _excluded);
|
|
38
|
+
var translations = _objectSpread({
|
|
39
|
+
messageLabel: 'Message',
|
|
40
|
+
actionsLabel: 'Message actions'
|
|
41
|
+
}, userTranslations);
|
|
42
|
+
var hasLeading = Boolean(LeadingComponent);
|
|
43
|
+
var hasActions = Boolean(actions.length > 0 || ActionsComponent);
|
|
44
|
+
var cssClasses = {
|
|
45
|
+
root: cx('ais-ChatMessage', "ais-ChatMessage--".concat(side), "ais-ChatMessage--".concat(variant), autoHideActions && 'ais-ChatMessage--auto-hide-actions', classNames.root),
|
|
46
|
+
container: cx('ais-ChatMessage-container', classNames.container),
|
|
47
|
+
leading: cx('ais-ChatMessage-leading', classNames.leading),
|
|
48
|
+
content: cx('ais-ChatMessage-content', classNames.content),
|
|
49
|
+
message: cx('ais-ChatMessage-message', classNames.message),
|
|
50
|
+
actions: cx('ais-ChatMessage-actions', classNames.actions),
|
|
51
|
+
footer: cx('ais-ChatMessage-footer', classNames.footer)
|
|
52
|
+
};
|
|
53
|
+
function renderMessagePart(part, index) {
|
|
54
|
+
if (part.type === 'step-start') {
|
|
55
|
+
return null;
|
|
56
|
+
}
|
|
57
|
+
if (part.type === 'text') {
|
|
58
|
+
var markdown = compiler(part.text, {
|
|
59
|
+
createElement: createElement,
|
|
60
|
+
disableParsingRawHTML: true
|
|
61
|
+
});
|
|
62
|
+
return createElement("span", {
|
|
63
|
+
key: "".concat(message.id, "-").concat(index)
|
|
64
|
+
}, markdown);
|
|
65
|
+
}
|
|
66
|
+
if (startsWith(part.type, 'tool-')) {
|
|
67
|
+
var toolName = part.type.replace('tool-', '');
|
|
68
|
+
var tool = tools[toolName];
|
|
69
|
+
if (tool) {
|
|
70
|
+
var ToolLayoutComponent = tool.layoutComponent;
|
|
71
|
+
var toolMessage = part;
|
|
72
|
+
var boundAddToolResult = function boundAddToolResult(params) {
|
|
73
|
+
var _tool$addToolResult;
|
|
74
|
+
return (_tool$addToolResult = tool.addToolResult) === null || _tool$addToolResult === void 0 ? void 0 : _tool$addToolResult.call(tool, {
|
|
75
|
+
output: params.output,
|
|
76
|
+
tool: part.type,
|
|
77
|
+
toolCallId: toolMessage.toolCallId
|
|
78
|
+
});
|
|
79
|
+
};
|
|
80
|
+
return createElement("div", {
|
|
81
|
+
key: "".concat(message.id, "-").concat(index),
|
|
82
|
+
className: "ais-ChatMessage-tool"
|
|
83
|
+
}, createElement(ToolLayoutComponent, {
|
|
84
|
+
message: toolMessage,
|
|
85
|
+
indexUiState: indexUiState,
|
|
86
|
+
setIndexUiState: setIndexUiState,
|
|
87
|
+
addToolResult: boundAddToolResult,
|
|
88
|
+
onClose: onClose
|
|
89
|
+
}));
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
return null;
|
|
93
|
+
}
|
|
94
|
+
return createElement("article", _extends({}, props, {
|
|
95
|
+
className: cx(cssClasses.root, props.className),
|
|
96
|
+
"aria-label": translations.messageLabel
|
|
97
|
+
}), createElement("div", {
|
|
98
|
+
className: cx(cssClasses.container)
|
|
99
|
+
}, hasLeading && createElement("div", {
|
|
100
|
+
className: cx(cssClasses.leading)
|
|
101
|
+
}, LeadingComponent && createElement(LeadingComponent, null)), createElement("div", {
|
|
102
|
+
className: cx(cssClasses.content)
|
|
103
|
+
}, createElement("div", {
|
|
104
|
+
className: cx(cssClasses.message)
|
|
105
|
+
}, message.parts.map(renderMessagePart)), hasActions && createElement("div", {
|
|
106
|
+
className: cx(cssClasses.actions),
|
|
107
|
+
"aria-label": translations.actionsLabel
|
|
108
|
+
}, ActionsComponent ? createElement(ActionsComponent, {
|
|
109
|
+
actions: actions,
|
|
110
|
+
message: message
|
|
111
|
+
}) : actions.map(function (action, index) {
|
|
112
|
+
return createElement(Button, {
|
|
113
|
+
key: index,
|
|
114
|
+
variant: "ghost",
|
|
115
|
+
size: "sm",
|
|
116
|
+
iconOnly: true,
|
|
117
|
+
className: "ais-ChatMessage-action",
|
|
118
|
+
disabled: action.disabled,
|
|
119
|
+
"aria-label": action.title,
|
|
120
|
+
onClick: function onClick() {
|
|
121
|
+
var _action$onClick;
|
|
122
|
+
return (_action$onClick = action.onClick) === null || _action$onClick === void 0 ? void 0 : _action$onClick.call(action, message);
|
|
123
|
+
}
|
|
124
|
+
}, action.icon ? createElement(action.icon, null) : createElement(MenuIconComponent, {
|
|
125
|
+
createElement: createElement
|
|
126
|
+
}));
|
|
127
|
+
})), FooterComponent && createElement("div", {
|
|
128
|
+
className: cx(cssClasses.footer)
|
|
129
|
+
}, createElement(FooterComponent, null)))));
|
|
130
|
+
};
|
|
131
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/** @jsx createElement */
|
|
2
|
+
import type { ComponentProps, Renderer } from '../../types';
|
|
3
|
+
export type ChatMessageErrorTranslations = {
|
|
4
|
+
/**
|
|
5
|
+
* Error message text
|
|
6
|
+
*/
|
|
7
|
+
errorMessage: string;
|
|
8
|
+
/**
|
|
9
|
+
* Retry button text
|
|
10
|
+
*/
|
|
11
|
+
retryText: string;
|
|
12
|
+
};
|
|
13
|
+
export type ChatMessageErrorProps = ComponentProps<'article'> & {
|
|
14
|
+
/**
|
|
15
|
+
* Callback for reload action
|
|
16
|
+
*/
|
|
17
|
+
onReload?: () => void;
|
|
18
|
+
/**
|
|
19
|
+
* Custom action buttons
|
|
20
|
+
*/
|
|
21
|
+
actions?: Array<ComponentProps<'button'>>;
|
|
22
|
+
/**
|
|
23
|
+
* Translations for error component texts
|
|
24
|
+
*/
|
|
25
|
+
translations?: Partial<ChatMessageErrorTranslations>;
|
|
26
|
+
};
|
|
27
|
+
export declare function createChatMessageErrorComponent({ createElement, }: Pick<Renderer, 'createElement'>): ({ onReload, actions, translations: userTranslations, ...props }: ChatMessageErrorProps) => JSX.Element;
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import _extends from "@babel/runtime/helpers/extends";
|
|
2
|
+
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
3
|
+
import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
|
|
4
|
+
var _excluded = ["onReload", "actions", "translations"];
|
|
5
|
+
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
6
|
+
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
7
|
+
import { createButtonComponent } from "../Button.js";
|
|
8
|
+
import { ReloadIconComponent } from "./icons.js";
|
|
9
|
+
export function createChatMessageErrorComponent(_ref) {
|
|
10
|
+
var createElement = _ref.createElement;
|
|
11
|
+
var Button = createButtonComponent({
|
|
12
|
+
createElement: createElement
|
|
13
|
+
});
|
|
14
|
+
return function ChatMessageError(_ref2) {
|
|
15
|
+
var onReload = _ref2.onReload,
|
|
16
|
+
actions = _ref2.actions,
|
|
17
|
+
userTranslations = _ref2.translations,
|
|
18
|
+
props = _objectWithoutProperties(_ref2, _excluded);
|
|
19
|
+
var translations = _objectSpread({
|
|
20
|
+
errorMessage: 'Sorry, we are not able to generate a response at the moment. Please retry or contact support.',
|
|
21
|
+
retryText: 'Retry'
|
|
22
|
+
}, userTranslations);
|
|
23
|
+
return createElement("article", _extends({
|
|
24
|
+
className: "ais-ChatMessageError ais-ChatMessage ais-ChatMessage--left ais-ChatMessage--subtle"
|
|
25
|
+
}, props), createElement("div", {
|
|
26
|
+
className: "ais-ChatMessage-container"
|
|
27
|
+
}, createElement("div", {
|
|
28
|
+
className: "ais-ChatMessage-content"
|
|
29
|
+
}, createElement("div", {
|
|
30
|
+
className: "ais-ChatMessage-message"
|
|
31
|
+
}, translations.errorMessage), (actions || onReload) && createElement("div", {
|
|
32
|
+
className: "ais-ChatMessage-actions"
|
|
33
|
+
}, actions ? actions.map(function (action, index) {
|
|
34
|
+
return createElement(Button, _extends({
|
|
35
|
+
key: index,
|
|
36
|
+
variant: "ghost",
|
|
37
|
+
className: "ais-ChatMessage-action"
|
|
38
|
+
}, action), action.children);
|
|
39
|
+
}) : createElement(Button, {
|
|
40
|
+
variant: "primary",
|
|
41
|
+
size: "md",
|
|
42
|
+
className: "ais-ChatMessage-errorAction",
|
|
43
|
+
onClick: function onClick() {
|
|
44
|
+
return onReload === null || onReload === void 0 ? void 0 : onReload();
|
|
45
|
+
}
|
|
46
|
+
}, createElement(ReloadIconComponent, {
|
|
47
|
+
createElement: createElement
|
|
48
|
+
}), translations.retryText)))));
|
|
49
|
+
};
|
|
50
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/** @jsx createElement */
|
|
2
|
+
import type { ComponentProps, Renderer } from '../../types';
|
|
3
|
+
export type ChatMessageLoaderTranslations = {
|
|
4
|
+
/**
|
|
5
|
+
* Text to display in the loader
|
|
6
|
+
*/
|
|
7
|
+
loaderText?: string;
|
|
8
|
+
};
|
|
9
|
+
export type ChatMessageLoaderProps = ComponentProps<'article'> & {
|
|
10
|
+
/**
|
|
11
|
+
* Translations for loader component texts
|
|
12
|
+
*/
|
|
13
|
+
translations?: Partial<ChatMessageLoaderTranslations>;
|
|
14
|
+
};
|
|
15
|
+
export declare function createChatMessageLoaderComponent({ createElement, }: Pick<Renderer, 'createElement'>): ({ translations: userTranslations, ...props }: ChatMessageLoaderProps) => JSX.Element;
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import _extends from "@babel/runtime/helpers/extends";
|
|
2
|
+
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
3
|
+
import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
|
|
4
|
+
var _excluded = ["translations"];
|
|
5
|
+
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
6
|
+
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
7
|
+
import { LoadingSpinnerIconComponent } from "./icons.js";
|
|
8
|
+
export function createChatMessageLoaderComponent(_ref) {
|
|
9
|
+
var createElement = _ref.createElement;
|
|
10
|
+
return function ChatMessageLoader(_ref2) {
|
|
11
|
+
var userTranslations = _ref2.translations,
|
|
12
|
+
props = _objectWithoutProperties(_ref2, _excluded);
|
|
13
|
+
var translations = _objectSpread({
|
|
14
|
+
loaderText: 'Thinking...'
|
|
15
|
+
}, userTranslations);
|
|
16
|
+
return createElement("article", _extends({
|
|
17
|
+
className: "ais-ChatMessageLoader ais-ChatMessage ais-ChatMessage--left ais-ChatMessage--subtle"
|
|
18
|
+
}, props), createElement("div", {
|
|
19
|
+
className: "ais-ChatMessage-container"
|
|
20
|
+
}, createElement("div", {
|
|
21
|
+
className: "ais-ChatMessage-leading"
|
|
22
|
+
}, createElement("div", {
|
|
23
|
+
className: "ais-ChatMessageLoader-spinner"
|
|
24
|
+
}, createElement(LoadingSpinnerIconComponent, {
|
|
25
|
+
createElement: createElement
|
|
26
|
+
}))), createElement("div", {
|
|
27
|
+
className: "ais-ChatMessage-content"
|
|
28
|
+
}, createElement("div", {
|
|
29
|
+
className: "ais-ChatMessage-message"
|
|
30
|
+
}, translations.loaderText && createElement("div", {
|
|
31
|
+
className: "ais-ChatMessageLoader-text"
|
|
32
|
+
}, translations.loaderText), createElement("div", {
|
|
33
|
+
className: "ais-ChatMessageLoader-skeletonWrapper"
|
|
34
|
+
}, createElement("div", {
|
|
35
|
+
className: "ais-ChatMessageLoader-skeletonItem"
|
|
36
|
+
}), createElement("div", {
|
|
37
|
+
className: "ais-ChatMessageLoader-skeletonItem"
|
|
38
|
+
}))))));
|
|
39
|
+
};
|
|
40
|
+
}
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
/** @jsx createElement */
|
|
2
|
+
import type { ComponentProps, MutableRef, Renderer } from '../../types';
|
|
3
|
+
import type { ChatMessageProps } from './ChatMessage';
|
|
4
|
+
import type { ChatMessageErrorProps } from './ChatMessageError';
|
|
5
|
+
import type { ChatMessageLoaderProps } from './ChatMessageLoader';
|
|
6
|
+
import type { ChatMessageBase, ChatStatus, ClientSideTools } from './types';
|
|
7
|
+
export type ChatMessagesTranslations = {
|
|
8
|
+
/**
|
|
9
|
+
* Label for the scroll to bottom button
|
|
10
|
+
*/
|
|
11
|
+
scrollToBottomLabel: string;
|
|
12
|
+
/**
|
|
13
|
+
* Text to display in the loader
|
|
14
|
+
*/
|
|
15
|
+
loaderText?: string;
|
|
16
|
+
/**
|
|
17
|
+
* Label for the copy to clipboard action
|
|
18
|
+
*/
|
|
19
|
+
copyToClipboardLabel?: string;
|
|
20
|
+
/**
|
|
21
|
+
* Label for the regenerate action
|
|
22
|
+
*/
|
|
23
|
+
regenerateLabel?: string;
|
|
24
|
+
};
|
|
25
|
+
export type ChatMessagesClassNames = {
|
|
26
|
+
/**
|
|
27
|
+
* Class names to apply to the root element
|
|
28
|
+
*/
|
|
29
|
+
root: string | string[];
|
|
30
|
+
/**
|
|
31
|
+
* Class names to apply to the scroll container
|
|
32
|
+
*/
|
|
33
|
+
scroll: string | string[];
|
|
34
|
+
/**
|
|
35
|
+
* Class names to apply to the content container
|
|
36
|
+
*/
|
|
37
|
+
content: string | string[];
|
|
38
|
+
/**
|
|
39
|
+
* Class names to apply to the scroll to bottom button
|
|
40
|
+
*/
|
|
41
|
+
scrollToBottom: string | string[];
|
|
42
|
+
/**
|
|
43
|
+
* Class names to apply to the scroll to bottom button when hidden
|
|
44
|
+
*/
|
|
45
|
+
scrollToBottomHidden: string | string[];
|
|
46
|
+
};
|
|
47
|
+
export type ChatMessagesProps<TMessage extends ChatMessageBase = ChatMessageBase> = ComponentProps<'div'> & {
|
|
48
|
+
/**
|
|
49
|
+
* Array of messages to display
|
|
50
|
+
*/
|
|
51
|
+
messages: TMessage[];
|
|
52
|
+
/**
|
|
53
|
+
* Custom message renderer
|
|
54
|
+
*/
|
|
55
|
+
messageComponent?: (props: {
|
|
56
|
+
message: TMessage;
|
|
57
|
+
}) => JSX.Element;
|
|
58
|
+
/**
|
|
59
|
+
* Custom loader component
|
|
60
|
+
*/
|
|
61
|
+
loaderComponent?: (props: ChatMessageLoaderProps) => JSX.Element;
|
|
62
|
+
/**
|
|
63
|
+
* Custom error component
|
|
64
|
+
*/
|
|
65
|
+
errorComponent?: (props: ChatMessageErrorProps) => JSX.Element;
|
|
66
|
+
/**
|
|
67
|
+
* Custom actions component
|
|
68
|
+
*/
|
|
69
|
+
actionsComponent?: ChatMessageProps['actionsComponent'];
|
|
70
|
+
/**
|
|
71
|
+
* The index UI state
|
|
72
|
+
*/
|
|
73
|
+
indexUiState: object;
|
|
74
|
+
/**
|
|
75
|
+
* Set the index UI state
|
|
76
|
+
*/
|
|
77
|
+
setIndexUiState: (state: object) => void;
|
|
78
|
+
/**
|
|
79
|
+
* Tools available for the assistant
|
|
80
|
+
*/
|
|
81
|
+
tools: ClientSideTools;
|
|
82
|
+
/**
|
|
83
|
+
* Current chat status
|
|
84
|
+
*/
|
|
85
|
+
status?: ChatStatus;
|
|
86
|
+
/**
|
|
87
|
+
* Whether to hide the scroll to bottom button
|
|
88
|
+
*/
|
|
89
|
+
hideScrollToBottom?: boolean;
|
|
90
|
+
/**
|
|
91
|
+
* Callback for reload action
|
|
92
|
+
*/
|
|
93
|
+
onReload: (messageId?: string) => void;
|
|
94
|
+
/**
|
|
95
|
+
* Function to close the chat
|
|
96
|
+
*/
|
|
97
|
+
onClose: () => void;
|
|
98
|
+
/**
|
|
99
|
+
* Optional class names
|
|
100
|
+
*/
|
|
101
|
+
classNames?: Partial<ChatMessagesClassNames>;
|
|
102
|
+
/**
|
|
103
|
+
* Optional translations
|
|
104
|
+
*/
|
|
105
|
+
translations?: Partial<ChatMessagesTranslations>;
|
|
106
|
+
/**
|
|
107
|
+
* Optional user message props
|
|
108
|
+
*/
|
|
109
|
+
userMessageProps?: Partial<Omit<ChatMessageProps, 'ref' | 'key'>>;
|
|
110
|
+
/**
|
|
111
|
+
* Optional assistant message props
|
|
112
|
+
*/
|
|
113
|
+
assistantMessageProps?: Partial<Omit<ChatMessageProps, 'ref' | 'key'>>;
|
|
114
|
+
/**
|
|
115
|
+
* Whether the scroll is at the bottom (controlled state)
|
|
116
|
+
*/
|
|
117
|
+
isScrollAtBottom?: boolean;
|
|
118
|
+
/**
|
|
119
|
+
* Whether the messages are clearing (for animation)
|
|
120
|
+
*/
|
|
121
|
+
isClearing?: boolean;
|
|
122
|
+
/**
|
|
123
|
+
* Callback for when clearing transition ends
|
|
124
|
+
*/
|
|
125
|
+
onClearTransitionEnd?: () => void;
|
|
126
|
+
/**
|
|
127
|
+
* Ref callback for the scroll container element
|
|
128
|
+
*/
|
|
129
|
+
scrollRef?: MutableRef<HTMLDivElement | null>;
|
|
130
|
+
/**
|
|
131
|
+
* Ref callback for the content element
|
|
132
|
+
*/
|
|
133
|
+
contentRef?: MutableRef<HTMLDivElement | null>;
|
|
134
|
+
/**
|
|
135
|
+
* Callback to scroll to bottom
|
|
136
|
+
*/
|
|
137
|
+
onScrollToBottom?: () => void;
|
|
138
|
+
};
|
|
139
|
+
export declare function createChatMessagesComponent({ createElement, Fragment, }: Renderer): <TMessage extends ChatMessageBase = ChatMessageBase>(userProps: ChatMessagesProps<TMessage>) => JSX.Element;
|