@aws-amplify/ui-react-ai 0.0.0-storage-browser-alpha-da8934f-20241119010337 → 0.0.0-storage-browser-alpha-e18d186-20241119023645
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/esm/components/AIConversation/AIConversation.mjs +1 -7
- package/dist/esm/components/AIConversation/AIConversationProvider.mjs +17 -17
- package/dist/esm/components/AIConversation/context/AIContextContext.mjs +8 -0
- package/dist/esm/components/AIConversation/createAIConversation.mjs +1 -5
- package/dist/esm/components/AIConversation/views/Controls/ActionsBarControl.mjs +1 -0
- package/dist/esm/components/AIConversation/views/Controls/AttachFileControl.mjs +1 -0
- package/dist/esm/components/AIConversation/views/Controls/AttachmentListControl.mjs +1 -0
- package/dist/esm/components/AIConversation/views/Controls/AvatarControl.mjs +1 -0
- package/dist/esm/components/AIConversation/views/Controls/DefaultMessageControl.mjs +1 -0
- package/dist/esm/components/AIConversation/views/Controls/FormControl.mjs +7 -2
- package/dist/esm/components/AIConversation/views/Controls/MessagesControl.mjs +11 -25
- package/dist/esm/components/AIConversation/views/Controls/PromptControl.mjs +1 -0
- package/dist/esm/components/AIConversation/views/default/Form.mjs +1 -3
- package/dist/esm/components/AIConversation/views/default/MessageList.mjs +1 -0
- package/dist/esm/hooks/createAIHooks.mjs +0 -3
- package/dist/index.js +45 -68
- package/dist/types/components/AIConversation/AIConversation.d.ts +0 -3
- package/dist/types/components/AIConversation/AIConversationProvider.d.ts +1 -1
- package/dist/types/components/AIConversation/context/AIContextContext.d.ts +6 -0
- package/dist/types/components/AIConversation/context/ControlsContext.d.ts +1 -0
- package/dist/types/components/AIConversation/context/index.d.ts +1 -0
- package/dist/types/components/AIConversation/createAIConversation.d.ts +0 -3
- package/dist/types/components/AIConversation/types.d.ts +1 -2
- package/dist/types/components/AIConversation/views/Controls/MessagesControl.d.ts +1 -5
- package/dist/types/hooks/createAIHooks.d.ts +0 -3
- package/package.json +4 -4
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
|
-
import {
|
|
2
|
+
import { Flex, ScrollView } from '@aws-amplify/ui-react';
|
|
3
3
|
import { useIcons, IconAssistant, IconUser } from '@aws-amplify/ui-react/internal';
|
|
4
4
|
import { MessagesControl } from './views/Controls/MessagesControl.mjs';
|
|
5
5
|
import { FormControl } from './views/Controls/FormControl.mjs';
|
|
@@ -35,9 +35,6 @@ function AIConversationBase({ avatars, controls, ...rest }) {
|
|
|
35
35
|
...defaultAvatars,
|
|
36
36
|
...avatars,
|
|
37
37
|
},
|
|
38
|
-
elements: {
|
|
39
|
-
Text,
|
|
40
|
-
},
|
|
41
38
|
controls: {
|
|
42
39
|
MessageList,
|
|
43
40
|
PromptList,
|
|
@@ -52,9 +49,6 @@ function AIConversationBase({ avatars, controls, ...rest }) {
|
|
|
52
49
|
React.createElement(MessagesControl, null)),
|
|
53
50
|
React.createElement(FormControl, null))));
|
|
54
51
|
}
|
|
55
|
-
/**
|
|
56
|
-
* @experimental
|
|
57
|
-
*/
|
|
58
52
|
const AIConversation = Object.assign(AIConversationBase, {
|
|
59
53
|
Provider: AIConversationProvider,
|
|
60
54
|
DefaultMessage: DefaultMessageControl,
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import React__default from 'react';
|
|
2
|
-
import { ElementsProvider } from '@aws-amplify/ui-react-core/elements';
|
|
3
2
|
import { defaultAIConversationDisplayTextEn } from './displayText.mjs';
|
|
3
|
+
import { AIContextProvider } from './context/AIContextContext.mjs';
|
|
4
4
|
import { ActionsProvider } from './context/ActionsContext.mjs';
|
|
5
5
|
import { AvatarsProvider } from './context/AvatarsContext.mjs';
|
|
6
6
|
import { ConversationInputContextProvider } from './context/ConversationInputContext.mjs';
|
|
@@ -18,26 +18,26 @@ import { WelcomeMessageProvider } from './context/WelcomeMessageContext.mjs';
|
|
|
18
18
|
import { FallbackComponentProvider } from './context/FallbackComponentContext.mjs';
|
|
19
19
|
import './context/elements/definitions.mjs';
|
|
20
20
|
|
|
21
|
-
const AIConversationProvider = ({ actions, allowAttachments, avatars, children, controls, displayText,
|
|
21
|
+
const AIConversationProvider = ({ aiContext, actions, allowAttachments, avatars, children, controls, displayText, handleSendMessage, isLoading, messages, messageRenderer, responseComponents, suggestedPrompts, variant, welcomeMessage, FallbackResponseComponent, }) => {
|
|
22
22
|
const _displayText = {
|
|
23
23
|
...defaultAIConversationDisplayTextEn,
|
|
24
24
|
...displayText,
|
|
25
25
|
};
|
|
26
|
-
return (React__default.createElement(
|
|
27
|
-
React__default.createElement(
|
|
28
|
-
React__default.createElement(
|
|
29
|
-
React__default.createElement(
|
|
30
|
-
React__default.createElement(
|
|
31
|
-
React__default.createElement(
|
|
32
|
-
React__default.createElement(
|
|
33
|
-
React__default.createElement(
|
|
34
|
-
React__default.createElement(
|
|
35
|
-
React__default.createElement(
|
|
36
|
-
React__default.createElement(
|
|
37
|
-
React__default.createElement(
|
|
38
|
-
React__default.createElement(
|
|
39
|
-
React__default.createElement(
|
|
40
|
-
React__default.createElement(
|
|
26
|
+
return (React__default.createElement(ControlsProvider, { controls: controls },
|
|
27
|
+
React__default.createElement(SuggestedPromptProvider, { suggestedPrompts: suggestedPrompts },
|
|
28
|
+
React__default.createElement(WelcomeMessageProvider, { welcomeMessage: welcomeMessage },
|
|
29
|
+
React__default.createElement(FallbackComponentProvider, { FallbackComponent: FallbackResponseComponent },
|
|
30
|
+
React__default.createElement(MessageRendererProvider, { ...messageRenderer },
|
|
31
|
+
React__default.createElement(ResponseComponentsProvider, { responseComponents: responseComponents },
|
|
32
|
+
React__default.createElement(AttachmentProvider, { allowAttachments: allowAttachments },
|
|
33
|
+
React__default.createElement(ConversationDisplayTextProvider, { ..._displayText },
|
|
34
|
+
React__default.createElement(ConversationInputContextProvider, null,
|
|
35
|
+
React__default.createElement(SendMessageContextProvider, { handleSendMessage: handleSendMessage },
|
|
36
|
+
React__default.createElement(AvatarsProvider, { avatars: avatars },
|
|
37
|
+
React__default.createElement(ActionsProvider, { actions: actions },
|
|
38
|
+
React__default.createElement(MessageVariantProvider, { variant: variant },
|
|
39
|
+
React__default.createElement(MessagesProvider, { messages: messages },
|
|
40
|
+
React__default.createElement(AIContextProvider, { aiContext: aiContext },
|
|
41
41
|
React__default.createElement(LoadingContextProvider, { isLoading: isLoading }, children)))))))))))))))));
|
|
42
42
|
};
|
|
43
43
|
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import React__default from 'react';
|
|
2
|
+
|
|
3
|
+
const AIContextContext = React__default.createContext(undefined);
|
|
4
|
+
const AIContextProvider = ({ children, aiContext, }) => {
|
|
5
|
+
return (React__default.createElement(AIContextContext.Provider, { value: aiContext }, children));
|
|
6
|
+
};
|
|
7
|
+
|
|
8
|
+
export { AIContextContext, AIContextProvider };
|
|
@@ -8,15 +8,11 @@ import { ViewElement } from './context/elements/definitions.mjs';
|
|
|
8
8
|
import { AIConversationProvider } from './AIConversationProvider.mjs';
|
|
9
9
|
import { DefaultMessageControl } from './views/Controls/DefaultMessageControl.mjs';
|
|
10
10
|
|
|
11
|
-
/**
|
|
12
|
-
* @experimental
|
|
13
|
-
*/
|
|
14
11
|
function createAIConversation(input = {}) {
|
|
15
|
-
const {
|
|
12
|
+
const { suggestedPrompts, actions, responseComponents, variant, controls, displayText, allowAttachments, messageRenderer, FallbackResponseComponent, } = input;
|
|
16
13
|
function AIConversation(props) {
|
|
17
14
|
const { messages, avatars, handleSendMessage, isLoading } = props;
|
|
18
15
|
const providerProps = {
|
|
19
|
-
elements,
|
|
20
16
|
actions,
|
|
21
17
|
suggestedPrompts,
|
|
22
18
|
responseComponents,
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import React__default from 'react';
|
|
2
2
|
import { withBaseElementProps } from '@aws-amplify/ui-react-core/elements';
|
|
3
|
+
import '../../context/AIContextContext.mjs';
|
|
3
4
|
import { ActionsContext } from '../../context/ActionsContext.mjs';
|
|
4
5
|
import '../../context/AvatarsContext.mjs';
|
|
5
6
|
import '../../context/ConversationInputContext.mjs';
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import React__default from 'react';
|
|
2
2
|
import { withBaseElementProps } from '@aws-amplify/ui-react-core/elements';
|
|
3
|
+
import '../../context/AIContextContext.mjs';
|
|
3
4
|
import '../../context/ActionsContext.mjs';
|
|
4
5
|
import '../../context/AvatarsContext.mjs';
|
|
5
6
|
import { ConversationInputContext } from '../../context/ConversationInputContext.mjs';
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import React__default from 'react';
|
|
2
2
|
import { withBaseElementProps } from '@aws-amplify/ui-react-core/elements';
|
|
3
|
+
import '../../context/AIContextContext.mjs';
|
|
3
4
|
import '../../context/ActionsContext.mjs';
|
|
4
5
|
import '../../context/AvatarsContext.mjs';
|
|
5
6
|
import { ConversationInputContext } from '../../context/ConversationInputContext.mjs';
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import React__default from 'react';
|
|
2
2
|
import { withBaseElementProps } from '@aws-amplify/ui-react-core/elements';
|
|
3
|
+
import '../../context/AIContextContext.mjs';
|
|
3
4
|
import '../../context/ActionsContext.mjs';
|
|
4
5
|
import { AvatarsContext } from '../../context/AvatarsContext.mjs';
|
|
5
6
|
import '../../context/ConversationInputContext.mjs';
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import React__default from 'react';
|
|
2
2
|
import { withBaseElementProps } from '@aws-amplify/ui-react-core/elements';
|
|
3
|
+
import { AIContextContext } from '../../context/AIContextContext.mjs';
|
|
3
4
|
import '../../context/ActionsContext.mjs';
|
|
4
5
|
import '../../context/AvatarsContext.mjs';
|
|
5
6
|
import { ConversationInputContext } from '../../context/ConversationInputContext.mjs';
|
|
@@ -19,6 +20,7 @@ import { AIConversationElements } from '../../context/elements/definitions.mjs';
|
|
|
19
20
|
import { AttachFileControl } from './AttachFileControl.mjs';
|
|
20
21
|
import { AttachmentListControl } from './AttachmentListControl.mjs';
|
|
21
22
|
import { getImageTypeFromMimeType } from '../../utils.mjs';
|
|
23
|
+
import { isFunction } from '@aws-amplify/ui';
|
|
22
24
|
|
|
23
25
|
const { Button, Icon, Label: LabelElement, TextArea, View, } = AIConversationElements;
|
|
24
26
|
const FIELD_BLOCK = 'ai-field';
|
|
@@ -104,8 +106,10 @@ const FormControl = () => {
|
|
|
104
106
|
const { input, setInput } = React__default.useContext(ConversationInputContext);
|
|
105
107
|
const handleSendMessage = React__default.useContext(SendMessageContext);
|
|
106
108
|
const allowAttachments = React__default.useContext(AttachmentContext);
|
|
107
|
-
const ref = React__default.useRef(null);
|
|
108
109
|
const responseComponents = React__default.useContext(ResponseComponentsContext);
|
|
110
|
+
const isLoading = React__default.useContext(LoadingContext);
|
|
111
|
+
const aiContext = React__default.useContext(AIContextContext);
|
|
112
|
+
const ref = React__default.useRef(null);
|
|
109
113
|
const controls = React__default.useContext(ControlsContext);
|
|
110
114
|
const [composing, setComposing] = React__default.useState(false);
|
|
111
115
|
const submitMessage = async () => {
|
|
@@ -132,6 +136,7 @@ const FormControl = () => {
|
|
|
132
136
|
if (handleSendMessage) {
|
|
133
137
|
handleSendMessage({
|
|
134
138
|
content: submittedContent,
|
|
139
|
+
aiContext: isFunction(aiContext) ? aiContext() : undefined,
|
|
135
140
|
toolConfiguration: convertResponseComponentsToToolConfiguration(responseComponents),
|
|
136
141
|
});
|
|
137
142
|
}
|
|
@@ -153,7 +158,7 @@ const FormControl = () => {
|
|
|
153
158
|
}
|
|
154
159
|
};
|
|
155
160
|
if (controls?.Form) {
|
|
156
|
-
return (React__default.createElement(controls.Form, { handleSubmit: handleSubmit, input: input, setInput: setInput, allowAttachments: allowAttachments }));
|
|
161
|
+
return (React__default.createElement(controls.Form, { handleSubmit: handleSubmit, input: input, setInput: setInput, allowAttachments: allowAttachments, isLoading: isLoading }));
|
|
157
162
|
}
|
|
158
163
|
return (React__default.createElement("form", { className: `${FIELD_BLOCK}__form`, onSubmit: handleSubmit, method: "post", ref: ref },
|
|
159
164
|
allowAttachments ? React__default.createElement(AttachFileControl, null) : null,
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import React__default from 'react';
|
|
2
|
+
import { Image } from '@aws-amplify/ui-react';
|
|
2
3
|
import { withBaseElementProps } from '@aws-amplify/ui-react-core/elements';
|
|
4
|
+
import '../../context/AIContextContext.mjs';
|
|
3
5
|
import '../../context/ActionsContext.mjs';
|
|
4
6
|
import '../../context/AvatarsContext.mjs';
|
|
5
7
|
import '../../context/ConversationInputContext.mjs';
|
|
@@ -19,25 +21,19 @@ import { AIConversationElements } from '../../context/elements/definitions.mjs';
|
|
|
19
21
|
import { convertBufferToBase64 } from '../../utils.mjs';
|
|
20
22
|
import { ActionsBarControl } from './ActionsBarControl.mjs';
|
|
21
23
|
import { AvatarControl } from './AvatarControl.mjs';
|
|
24
|
+
import { classNames } from '@aws-amplify/ui';
|
|
22
25
|
|
|
23
|
-
const {
|
|
24
|
-
const MESSAGES_BLOCK = 'ai-
|
|
25
|
-
const MESSAGE_BLOCK = 'ai-
|
|
26
|
-
const
|
|
27
|
-
alt: 'Image attachment',
|
|
28
|
-
});
|
|
29
|
-
const MediaContent = React__default.forwardRef(function MediaContent(props, ref) {
|
|
26
|
+
const { Text, View } = AIConversationElements;
|
|
27
|
+
const MESSAGES_BLOCK = 'amplify-ai-conversation__message__list';
|
|
28
|
+
const MESSAGE_BLOCK = 'amplify-ai-conversation__message';
|
|
29
|
+
const MediaContent = (props) => {
|
|
30
30
|
const variant = React__default.useContext(MessageVariantContext);
|
|
31
31
|
const role = React__default.useContext(RoleContext);
|
|
32
|
-
return (React__default.createElement(
|
|
33
|
-
}
|
|
32
|
+
return (React__default.createElement(Image, { className: classNames(`${MESSAGE_BLOCK}__image`, variant && `${MESSAGE_BLOCK}__image--${variant}`, `${MESSAGE_BLOCK}__image--${role}`), ...props }));
|
|
33
|
+
};
|
|
34
34
|
const TextContent = React__default.forwardRef(function TextContent(props, ref) {
|
|
35
35
|
return React__default.createElement(Text, { ref: ref, className: `${MESSAGE_BLOCK}__text`, ...props });
|
|
36
36
|
});
|
|
37
|
-
const ContentContainer = React__default.forwardRef(function ContentContainer(props, ref) {
|
|
38
|
-
const variant = React__default.useContext(MessageVariantContext);
|
|
39
|
-
return (React__default.createElement(View, { "data-testid": 'content', className: `${MESSAGE_BLOCK}__content ${MESSAGE_BLOCK}__content--${variant}`, ref: ref, ...props }));
|
|
40
|
-
});
|
|
41
37
|
const ToolContent = ({ toolUse, }) => {
|
|
42
38
|
const responseComponents = React__default.useContext(ResponseComponentsContext) ?? {};
|
|
43
39
|
const FallbackComponent = React__default.useContext(FallbackComponentContext);
|
|
@@ -61,26 +57,18 @@ const ToolContent = ({ toolUse, }) => {
|
|
|
61
57
|
};
|
|
62
58
|
const MessageControl = ({ message }) => {
|
|
63
59
|
const messageRenderer = React__default.useContext(MessageRendererContext);
|
|
64
|
-
return (React__default.createElement(
|
|
60
|
+
return (React__default.createElement(React__default.Fragment, null, message.content.map((content, index) => {
|
|
65
61
|
if (content.text) {
|
|
66
62
|
return messageRenderer?.text ? (React__default.createElement(React__default.Fragment, { key: index }, messageRenderer.text({ text: content.text }))) : (React__default.createElement(TextContent, { "data-testid": 'text-content', key: index }, content.text));
|
|
67
63
|
}
|
|
68
64
|
else if (content.image) {
|
|
69
|
-
return messageRenderer?.image ? (React__default.createElement(React__default.Fragment, { key: index }, messageRenderer?.image({ image: content.image }))) : (React__default.createElement(MediaContent, { "data-testid": 'image-content', key: index, src: convertBufferToBase64(content.image?.source.bytes, content.image?.format) }));
|
|
65
|
+
return messageRenderer?.image ? (React__default.createElement(React__default.Fragment, { key: index }, messageRenderer?.image({ image: content.image }))) : (React__default.createElement(MediaContent, { "data-testid": 'image-content', key: index, alt: "", src: convertBufferToBase64(content.image?.source.bytes, content.image?.format) }));
|
|
70
66
|
}
|
|
71
67
|
else if (content.toolUse) {
|
|
72
68
|
return React__default.createElement(ToolContent, { toolUse: content.toolUse, key: index });
|
|
73
69
|
}
|
|
74
70
|
})));
|
|
75
71
|
};
|
|
76
|
-
MessageControl.Container = ContentContainer;
|
|
77
|
-
MessageControl.MediaContent = MediaContent;
|
|
78
|
-
MessageControl.TextContent = TextContent;
|
|
79
|
-
const Separator = withBaseElementProps(Span, {
|
|
80
|
-
'aria-hidden': true,
|
|
81
|
-
children: '|',
|
|
82
|
-
className: `${MESSAGE_BLOCK}__separator`,
|
|
83
|
-
});
|
|
84
72
|
const Timestamp = withBaseElementProps(Text, {
|
|
85
73
|
className: `${MESSAGE_BLOCK}__timestamp`,
|
|
86
74
|
});
|
|
@@ -141,7 +129,6 @@ const MessagesControl = () => {
|
|
|
141
129
|
React__default.createElement(MessageContainer, { "data-testid": `message`, key: `message-${index}`, tabIndex: focusedItemIndex === index ? 0 : -1, onFocus: () => handleFocus(index), onKeyDown: (event) => onKeyDown(index, event), ref: (el) => (messagesRef.current[index] = el) },
|
|
142
130
|
React__default.createElement(HeaderContainer, null,
|
|
143
131
|
React__default.createElement(AvatarControl, null),
|
|
144
|
-
React__default.createElement(Separator, null),
|
|
145
132
|
React__default.createElement(Timestamp, null, getMessageTimestampText(new Date(message.createdAt)))),
|
|
146
133
|
React__default.createElement(MessageControl, { message: message }),
|
|
147
134
|
message.role === 'assistant' ? (React__default.createElement(ActionsBarControl, { message: message, focusable: focusedItemIndex === index })) : null)));
|
|
@@ -153,6 +140,5 @@ MessagesControl.Container = MessageContainer;
|
|
|
153
140
|
MessagesControl.HeaderContainer = HeaderContainer;
|
|
154
141
|
MessagesControl.Layout = Layout;
|
|
155
142
|
MessagesControl.Message = MessageControl;
|
|
156
|
-
MessagesControl.Separator = Separator;
|
|
157
143
|
|
|
158
144
|
export { MessageControl, MessagesControl };
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import React__default from 'react';
|
|
2
2
|
import { withBaseElementProps } from '@aws-amplify/ui-react-core/elements';
|
|
3
|
+
import '../../context/AIContextContext.mjs';
|
|
3
4
|
import '../../context/ActionsContext.mjs';
|
|
4
5
|
import '../../context/AvatarsContext.mjs';
|
|
5
6
|
import { ConversationInputContext } from '../../context/ConversationInputContext.mjs';
|
|
@@ -3,7 +3,6 @@ import { View, Button, VisuallyHidden, TextAreaField, DropZone } from '@aws-ampl
|
|
|
3
3
|
import { useIcons, IconSend, IconAttach } from '@aws-amplify/ui-react/internal';
|
|
4
4
|
import { ComponentClassName } from '@aws-amplify/ui';
|
|
5
5
|
import { Attachments } from './Attachments.mjs';
|
|
6
|
-
import { LoadingContext } from '../../context/LoadingContext.mjs';
|
|
7
6
|
|
|
8
7
|
function isHTMLFormElement(target) {
|
|
9
8
|
return 'form' in target;
|
|
@@ -25,12 +24,11 @@ const FormWrapper = ({ children, allowAttachments, setInput, }) => {
|
|
|
25
24
|
return children;
|
|
26
25
|
}
|
|
27
26
|
};
|
|
28
|
-
const Form = ({ setInput, input, handleSubmit, allowAttachments, }) => {
|
|
27
|
+
const Form = ({ setInput, input, handleSubmit, allowAttachments, isLoading, }) => {
|
|
29
28
|
const icons = useIcons('aiConversation');
|
|
30
29
|
const sendIcon = icons?.send ?? React.createElement(IconSend, null);
|
|
31
30
|
const attachIcon = icons?.attach ?? React.createElement(IconAttach, null);
|
|
32
31
|
const hiddenInput = React.useRef(null);
|
|
33
|
-
const isLoading = React.useContext(LoadingContext);
|
|
34
32
|
const [composing, setComposing] = React.useState(false);
|
|
35
33
|
const isInputEmpty = !input?.text?.length && !input?.files?.length;
|
|
36
34
|
return (React.createElement(FormWrapper, { allowAttachments: allowAttachments, setInput: setInput },
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
2
|
import { View, Avatar, Placeholder, Text, Button } from '@aws-amplify/ui-react';
|
|
3
3
|
import { MessageControl } from '../Controls/MessagesControl.mjs';
|
|
4
|
+
import '../../context/AIContextContext.mjs';
|
|
4
5
|
import { ActionsContext } from '../../context/ActionsContext.mjs';
|
|
5
6
|
import { AvatarsContext } from '../../context/AvatarsContext.mjs';
|
|
6
7
|
import '../../context/ConversationInputContext.mjs';
|
|
@@ -1,9 +1,6 @@
|
|
|
1
1
|
import { createUseAIGeneration } from './useAIGeneration.mjs';
|
|
2
2
|
import { createUseAIConversation } from './useAIConversation.mjs';
|
|
3
3
|
|
|
4
|
-
/**
|
|
5
|
-
* @experimental
|
|
6
|
-
*/
|
|
7
4
|
function createAIHooks(_client) {
|
|
8
5
|
const useAIConversation = createUseAIConversation(_client);
|
|
9
6
|
const useAIGeneration = createUseAIGeneration(_client);
|
package/dist/index.js
CHANGED
|
@@ -5,9 +5,9 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
5
5
|
var React = require('react');
|
|
6
6
|
var elements = require('@aws-amplify/ui-react-core/elements');
|
|
7
7
|
var uiReactCore = require('@aws-amplify/ui-react-core');
|
|
8
|
+
var ui = require('@aws-amplify/ui');
|
|
8
9
|
var uiReact = require('@aws-amplify/ui-react');
|
|
9
10
|
var internal = require('@aws-amplify/ui-react/internal');
|
|
10
|
-
var ui = require('@aws-amplify/ui');
|
|
11
11
|
|
|
12
12
|
function _interopNamespace(e) {
|
|
13
13
|
if (e && e.__esModule) return e;
|
|
@@ -29,6 +29,11 @@ function _interopNamespace(e) {
|
|
|
29
29
|
|
|
30
30
|
var React__namespace = /*#__PURE__*/_interopNamespace(React);
|
|
31
31
|
|
|
32
|
+
const AIContextContext = React__namespace["default"].createContext(undefined);
|
|
33
|
+
const AIContextProvider = ({ children, aiContext, }) => {
|
|
34
|
+
return (React__namespace["default"].createElement(AIContextContext.Provider, { value: aiContext }, children));
|
|
35
|
+
};
|
|
36
|
+
|
|
32
37
|
const ActionsContext = React__namespace["default"].createContext(undefined);
|
|
33
38
|
const ActionsProvider = ({ children, actions, }) => {
|
|
34
39
|
return (React__namespace["default"].createElement(ActionsContext.Provider, { value: actions }, children));
|
|
@@ -278,9 +283,9 @@ const AIConversationElements = {
|
|
|
278
283
|
View: ViewElement,
|
|
279
284
|
};
|
|
280
285
|
|
|
281
|
-
const { Button: Button$4, Span: Span$
|
|
286
|
+
const { Button: Button$4, Span: Span$2, View: View$6 } = AIConversationElements;
|
|
282
287
|
const ACTIONS_BAR_BLOCK = 'ai-actions-bar';
|
|
283
|
-
const ActionIcon = elements.withBaseElementProps(Span$
|
|
288
|
+
const ActionIcon = elements.withBaseElementProps(Span$2, {
|
|
284
289
|
'aria-hidden': 'true',
|
|
285
290
|
className: `${ACTIONS_BAR_BLOCK}__icon`,
|
|
286
291
|
});
|
|
@@ -301,7 +306,7 @@ ActionsBarControl.Button = ActionButton;
|
|
|
301
306
|
ActionsBarControl.Container = Container$3;
|
|
302
307
|
ActionsBarControl.Icon = ActionIcon;
|
|
303
308
|
|
|
304
|
-
const { Icon: Icon$3, Span: Span$
|
|
309
|
+
const { Icon: Icon$3, Span: Span$1, Text: Text$2, View: View$5 } = AIConversationElements;
|
|
305
310
|
const AVATAR_BLOCK = 'ai-avatar';
|
|
306
311
|
const DEFAULT_USER_ICON = elements.withBaseElementProps(Icon$3, {
|
|
307
312
|
variant: 'user-avatar',
|
|
@@ -312,7 +317,7 @@ const DEFAULT_AI_ICON = () => (React__namespace["default"].createElement("svg",
|
|
|
312
317
|
const AvatarDisplayName = elements.withBaseElementProps(Text$2, {
|
|
313
318
|
className: `${AVATAR_BLOCK}__display-name`,
|
|
314
319
|
});
|
|
315
|
-
const AvatarIcon = elements.withBaseElementProps(Span$
|
|
320
|
+
const AvatarIcon = elements.withBaseElementProps(Span$1, {
|
|
316
321
|
'aria-hidden': true,
|
|
317
322
|
className: `${AVATAR_BLOCK}__icon`,
|
|
318
323
|
});
|
|
@@ -393,7 +398,7 @@ AttachFileControl.Icon = AttachFileIcon;
|
|
|
393
398
|
AttachFileControl.Button = AttachFileButton;
|
|
394
399
|
AttachFileControl.Container = AttachFileContainer;
|
|
395
400
|
|
|
396
|
-
const { Button: Button$2, Icon: Icon$1, ListItem, UnorderedList: ListElement, Span
|
|
401
|
+
const { Button: Button$2, Icon: Icon$1, ListItem, UnorderedList: ListElement, Span, Text: Text$1, View: View$3, } = AIConversationElements;
|
|
397
402
|
const IMAGE_LIST_BLOCK = 'ai-attachment-list';
|
|
398
403
|
const IMAGE_ITEM_BLOCK = 'ai-attachment';
|
|
399
404
|
const REMOVE_IMAGE_BLOCK = 'ai-remove-attachment';
|
|
@@ -424,7 +429,7 @@ const FileNameText = elements.withBaseElementProps(Text$1, {
|
|
|
424
429
|
const FileSizeText = elements.withBaseElementProps(Text$1, {
|
|
425
430
|
className: `${IMAGE_TEXT_BLOCK}__file-size`,
|
|
426
431
|
});
|
|
427
|
-
const Separator
|
|
432
|
+
const Separator = elements.withBaseElementProps(Span, {
|
|
428
433
|
'aria-hidden': true,
|
|
429
434
|
className: `${IMAGE_TEXT_BLOCK}__separator`,
|
|
430
435
|
children: '|',
|
|
@@ -435,13 +440,13 @@ const TextContainer = elements.withBaseElementProps(View$3, {
|
|
|
435
440
|
const TextControl = ({ fileName, fileSize }) => {
|
|
436
441
|
return (React__namespace["default"].createElement(TextContainer, null,
|
|
437
442
|
React__namespace["default"].createElement(FileNameText, null, fileName),
|
|
438
|
-
React__namespace["default"].createElement(Separator
|
|
443
|
+
React__namespace["default"].createElement(Separator, null),
|
|
439
444
|
React__namespace["default"].createElement(FileSizeText, null, fileSize)));
|
|
440
445
|
};
|
|
441
446
|
TextControl.Container = TextContainer;
|
|
442
447
|
TextControl.FileName = FileNameText;
|
|
443
448
|
TextControl.FileSize = FileSizeText;
|
|
444
|
-
TextControl.Separator = Separator
|
|
449
|
+
TextControl.Separator = Separator;
|
|
445
450
|
const Container$1 = elements.withBaseElementProps(ListItem, {
|
|
446
451
|
className: `${IMAGE_ITEM_BLOCK}__list-item`,
|
|
447
452
|
});
|
|
@@ -559,8 +564,10 @@ const FormControl = () => {
|
|
|
559
564
|
const { input, setInput } = React__namespace["default"].useContext(ConversationInputContext);
|
|
560
565
|
const handleSendMessage = React__namespace["default"].useContext(SendMessageContext);
|
|
561
566
|
const allowAttachments = React__namespace["default"].useContext(AttachmentContext);
|
|
562
|
-
const ref = React__namespace["default"].useRef(null);
|
|
563
567
|
const responseComponents = React__namespace["default"].useContext(ResponseComponentsContext);
|
|
568
|
+
const isLoading = React__namespace["default"].useContext(LoadingContext);
|
|
569
|
+
const aiContext = React__namespace["default"].useContext(AIContextContext);
|
|
570
|
+
const ref = React__namespace["default"].useRef(null);
|
|
564
571
|
const controls = React__namespace["default"].useContext(ControlsContext);
|
|
565
572
|
const [composing, setComposing] = React__namespace["default"].useState(false);
|
|
566
573
|
const submitMessage = async () => {
|
|
@@ -587,6 +594,7 @@ const FormControl = () => {
|
|
|
587
594
|
if (handleSendMessage) {
|
|
588
595
|
handleSendMessage({
|
|
589
596
|
content: submittedContent,
|
|
597
|
+
aiContext: ui.isFunction(aiContext) ? aiContext() : undefined,
|
|
590
598
|
toolConfiguration: convertResponseComponentsToToolConfiguration(responseComponents),
|
|
591
599
|
});
|
|
592
600
|
}
|
|
@@ -608,7 +616,7 @@ const FormControl = () => {
|
|
|
608
616
|
}
|
|
609
617
|
};
|
|
610
618
|
if (controls?.Form) {
|
|
611
|
-
return (React__namespace["default"].createElement(controls.Form, { handleSubmit: handleSubmit, input: input, setInput: setInput, allowAttachments: allowAttachments }));
|
|
619
|
+
return (React__namespace["default"].createElement(controls.Form, { handleSubmit: handleSubmit, input: input, setInput: setInput, allowAttachments: allowAttachments, isLoading: isLoading }));
|
|
612
620
|
}
|
|
613
621
|
return (React__namespace["default"].createElement("form", { className: `${FIELD_BLOCK}__form`, onSubmit: handleSubmit, method: "post", ref: ref },
|
|
614
622
|
allowAttachments ? React__namespace["default"].createElement(AttachFileControl, null) : null,
|
|
@@ -627,24 +635,17 @@ FormControl.TextInput = TextInput;
|
|
|
627
635
|
FormControl.SendButton = SendButton;
|
|
628
636
|
FormControl.SendIcon = SendIcon;
|
|
629
637
|
|
|
630
|
-
const {
|
|
631
|
-
const MESSAGES_BLOCK = 'ai-
|
|
632
|
-
const MESSAGE_BLOCK = 'ai-
|
|
633
|
-
const
|
|
634
|
-
alt: 'Image attachment',
|
|
635
|
-
});
|
|
636
|
-
const MediaContent = React__namespace["default"].forwardRef(function MediaContent(props, ref) {
|
|
638
|
+
const { Text, View: View$1 } = AIConversationElements;
|
|
639
|
+
const MESSAGES_BLOCK = 'amplify-ai-conversation__message__list';
|
|
640
|
+
const MESSAGE_BLOCK = 'amplify-ai-conversation__message';
|
|
641
|
+
const MediaContent = (props) => {
|
|
637
642
|
const variant = React__namespace["default"].useContext(MessageVariantContext);
|
|
638
643
|
const role = React__namespace["default"].useContext(RoleContext);
|
|
639
|
-
return (React__namespace["default"].createElement(
|
|
640
|
-
}
|
|
644
|
+
return (React__namespace["default"].createElement(uiReact.Image, { className: ui.classNames(`${MESSAGE_BLOCK}__image`, variant && `${MESSAGE_BLOCK}__image--${variant}`, `${MESSAGE_BLOCK}__image--${role}`), ...props }));
|
|
645
|
+
};
|
|
641
646
|
const TextContent = React__namespace["default"].forwardRef(function TextContent(props, ref) {
|
|
642
647
|
return React__namespace["default"].createElement(Text, { ref: ref, className: `${MESSAGE_BLOCK}__text`, ...props });
|
|
643
648
|
});
|
|
644
|
-
const ContentContainer = React__namespace["default"].forwardRef(function ContentContainer(props, ref) {
|
|
645
|
-
const variant = React__namespace["default"].useContext(MessageVariantContext);
|
|
646
|
-
return (React__namespace["default"].createElement(View$1, { "data-testid": 'content', className: `${MESSAGE_BLOCK}__content ${MESSAGE_BLOCK}__content--${variant}`, ref: ref, ...props }));
|
|
647
|
-
});
|
|
648
649
|
const ToolContent = ({ toolUse, }) => {
|
|
649
650
|
const responseComponents = React__namespace["default"].useContext(ResponseComponentsContext) ?? {};
|
|
650
651
|
const FallbackComponent = React__namespace["default"].useContext(FallbackComponentContext);
|
|
@@ -668,26 +669,18 @@ const ToolContent = ({ toolUse, }) => {
|
|
|
668
669
|
};
|
|
669
670
|
const MessageControl = ({ message }) => {
|
|
670
671
|
const messageRenderer = React__namespace["default"].useContext(MessageRendererContext);
|
|
671
|
-
return (React__namespace["default"].createElement(
|
|
672
|
+
return (React__namespace["default"].createElement(React__namespace["default"].Fragment, null, message.content.map((content, index) => {
|
|
672
673
|
if (content.text) {
|
|
673
674
|
return messageRenderer?.text ? (React__namespace["default"].createElement(React__namespace["default"].Fragment, { key: index }, messageRenderer.text({ text: content.text }))) : (React__namespace["default"].createElement(TextContent, { "data-testid": 'text-content', key: index }, content.text));
|
|
674
675
|
}
|
|
675
676
|
else if (content.image) {
|
|
676
|
-
return messageRenderer?.image ? (React__namespace["default"].createElement(React__namespace["default"].Fragment, { key: index }, messageRenderer?.image({ image: content.image }))) : (React__namespace["default"].createElement(MediaContent, { "data-testid": 'image-content', key: index, src: convertBufferToBase64(content.image?.source.bytes, content.image?.format) }));
|
|
677
|
+
return messageRenderer?.image ? (React__namespace["default"].createElement(React__namespace["default"].Fragment, { key: index }, messageRenderer?.image({ image: content.image }))) : (React__namespace["default"].createElement(MediaContent, { "data-testid": 'image-content', key: index, alt: "", src: convertBufferToBase64(content.image?.source.bytes, content.image?.format) }));
|
|
677
678
|
}
|
|
678
679
|
else if (content.toolUse) {
|
|
679
680
|
return React__namespace["default"].createElement(ToolContent, { toolUse: content.toolUse, key: index });
|
|
680
681
|
}
|
|
681
682
|
})));
|
|
682
683
|
};
|
|
683
|
-
MessageControl.Container = ContentContainer;
|
|
684
|
-
MessageControl.MediaContent = MediaContent;
|
|
685
|
-
MessageControl.TextContent = TextContent;
|
|
686
|
-
const Separator = elements.withBaseElementProps(Span, {
|
|
687
|
-
'aria-hidden': true,
|
|
688
|
-
children: '|',
|
|
689
|
-
className: `${MESSAGE_BLOCK}__separator`,
|
|
690
|
-
});
|
|
691
684
|
const Timestamp = elements.withBaseElementProps(Text, {
|
|
692
685
|
className: `${MESSAGE_BLOCK}__timestamp`,
|
|
693
686
|
});
|
|
@@ -748,7 +741,6 @@ const MessagesControl = () => {
|
|
|
748
741
|
React__namespace["default"].createElement(MessageContainer, { "data-testid": `message`, key: `message-${index}`, tabIndex: focusedItemIndex === index ? 0 : -1, onFocus: () => handleFocus(index), onKeyDown: (event) => onKeyDown(index, event), ref: (el) => (messagesRef.current[index] = el) },
|
|
749
742
|
React__namespace["default"].createElement(HeaderContainer, null,
|
|
750
743
|
React__namespace["default"].createElement(AvatarControl, null),
|
|
751
|
-
React__namespace["default"].createElement(Separator, null),
|
|
752
744
|
React__namespace["default"].createElement(Timestamp, null, getMessageTimestampText(new Date(message.createdAt)))),
|
|
753
745
|
React__namespace["default"].createElement(MessageControl, { message: message }),
|
|
754
746
|
message.role === 'assistant' ? (React__namespace["default"].createElement(ActionsBarControl, { message: message, focusable: focusedItemIndex === index })) : null)));
|
|
@@ -760,7 +752,6 @@ MessagesControl.Container = MessageContainer;
|
|
|
760
752
|
MessagesControl.HeaderContainer = HeaderContainer;
|
|
761
753
|
MessagesControl.Layout = Layout;
|
|
762
754
|
MessagesControl.Message = MessageControl;
|
|
763
|
-
MessagesControl.Separator = Separator;
|
|
764
755
|
|
|
765
756
|
const { View, Button } = AIConversationElements;
|
|
766
757
|
const PROMPT_BLOCK = 'ai-prompts';
|
|
@@ -804,26 +795,26 @@ PromptControl.Container = Container;
|
|
|
804
795
|
PromptControl.PromptGroup = PromptGroup;
|
|
805
796
|
PromptControl.PromptCard = PromptCard;
|
|
806
797
|
|
|
807
|
-
const AIConversationProvider = ({ actions, allowAttachments, avatars, children, controls, displayText,
|
|
798
|
+
const AIConversationProvider = ({ aiContext, actions, allowAttachments, avatars, children, controls, displayText, handleSendMessage, isLoading, messages, messageRenderer, responseComponents, suggestedPrompts, variant, welcomeMessage, FallbackResponseComponent, }) => {
|
|
808
799
|
const _displayText = {
|
|
809
800
|
...defaultAIConversationDisplayTextEn,
|
|
810
801
|
...displayText,
|
|
811
802
|
};
|
|
812
|
-
return (React__namespace["default"].createElement(
|
|
813
|
-
React__namespace["default"].createElement(
|
|
814
|
-
React__namespace["default"].createElement(
|
|
815
|
-
React__namespace["default"].createElement(
|
|
816
|
-
React__namespace["default"].createElement(
|
|
817
|
-
React__namespace["default"].createElement(
|
|
818
|
-
React__namespace["default"].createElement(
|
|
819
|
-
React__namespace["default"].createElement(
|
|
820
|
-
React__namespace["default"].createElement(
|
|
821
|
-
React__namespace["default"].createElement(
|
|
822
|
-
React__namespace["default"].createElement(
|
|
823
|
-
React__namespace["default"].createElement(
|
|
824
|
-
React__namespace["default"].createElement(
|
|
825
|
-
React__namespace["default"].createElement(
|
|
826
|
-
React__namespace["default"].createElement(
|
|
803
|
+
return (React__namespace["default"].createElement(ControlsProvider, { controls: controls },
|
|
804
|
+
React__namespace["default"].createElement(SuggestedPromptProvider, { suggestedPrompts: suggestedPrompts },
|
|
805
|
+
React__namespace["default"].createElement(WelcomeMessageProvider, { welcomeMessage: welcomeMessage },
|
|
806
|
+
React__namespace["default"].createElement(FallbackComponentProvider, { FallbackComponent: FallbackResponseComponent },
|
|
807
|
+
React__namespace["default"].createElement(MessageRendererProvider, { ...messageRenderer },
|
|
808
|
+
React__namespace["default"].createElement(ResponseComponentsProvider, { responseComponents: responseComponents },
|
|
809
|
+
React__namespace["default"].createElement(AttachmentProvider, { allowAttachments: allowAttachments },
|
|
810
|
+
React__namespace["default"].createElement(ConversationDisplayTextProvider, { ..._displayText },
|
|
811
|
+
React__namespace["default"].createElement(ConversationInputContextProvider, null,
|
|
812
|
+
React__namespace["default"].createElement(SendMessageContextProvider, { handleSendMessage: handleSendMessage },
|
|
813
|
+
React__namespace["default"].createElement(AvatarsProvider, { avatars: avatars },
|
|
814
|
+
React__namespace["default"].createElement(ActionsProvider, { actions: actions },
|
|
815
|
+
React__namespace["default"].createElement(MessageVariantProvider, { variant: variant },
|
|
816
|
+
React__namespace["default"].createElement(MessagesProvider, { messages: messages },
|
|
817
|
+
React__namespace["default"].createElement(AIContextProvider, { aiContext: aiContext },
|
|
827
818
|
React__namespace["default"].createElement(LoadingContextProvider, { isLoading: isLoading }, children)))))))))))))))));
|
|
828
819
|
};
|
|
829
820
|
|
|
@@ -837,15 +828,11 @@ const DefaultMessageControl = () => {
|
|
|
837
828
|
}
|
|
838
829
|
};
|
|
839
830
|
|
|
840
|
-
/**
|
|
841
|
-
* @experimental
|
|
842
|
-
*/
|
|
843
831
|
function createAIConversation(input = {}) {
|
|
844
|
-
const {
|
|
832
|
+
const { suggestedPrompts, actions, responseComponents, variant, controls, displayText, allowAttachments, messageRenderer, FallbackResponseComponent, } = input;
|
|
845
833
|
function AIConversation(props) {
|
|
846
834
|
const { messages, avatars, handleSendMessage, isLoading } = props;
|
|
847
835
|
const providerProps = {
|
|
848
|
-
elements,
|
|
849
836
|
actions,
|
|
850
837
|
suggestedPrompts,
|
|
851
838
|
responseComponents,
|
|
@@ -976,12 +963,11 @@ const FormWrapper = ({ children, allowAttachments, setInput, }) => {
|
|
|
976
963
|
return children;
|
|
977
964
|
}
|
|
978
965
|
};
|
|
979
|
-
const Form = ({ setInput, input, handleSubmit, allowAttachments, }) => {
|
|
966
|
+
const Form = ({ setInput, input, handleSubmit, allowAttachments, isLoading, }) => {
|
|
980
967
|
const icons = internal.useIcons('aiConversation');
|
|
981
968
|
const sendIcon = icons?.send ?? React__namespace.createElement(internal.IconSend, null);
|
|
982
969
|
const attachIcon = icons?.attach ?? React__namespace.createElement(internal.IconAttach, null);
|
|
983
970
|
const hiddenInput = React__namespace.useRef(null);
|
|
984
|
-
const isLoading = React__namespace.useContext(LoadingContext);
|
|
985
971
|
const [composing, setComposing] = React__namespace.useState(false);
|
|
986
972
|
const isInputEmpty = !input?.text?.length && !input?.files?.length;
|
|
987
973
|
return (React__namespace.createElement(FormWrapper, { allowAttachments: allowAttachments, setInput: setInput },
|
|
@@ -1061,9 +1047,6 @@ function AIConversationBase({ avatars, controls, ...rest }) {
|
|
|
1061
1047
|
...defaultAvatars,
|
|
1062
1048
|
...avatars,
|
|
1063
1049
|
},
|
|
1064
|
-
elements: {
|
|
1065
|
-
Text: uiReact.Text,
|
|
1066
|
-
},
|
|
1067
1050
|
controls: {
|
|
1068
1051
|
MessageList,
|
|
1069
1052
|
PromptList,
|
|
@@ -1078,9 +1061,6 @@ function AIConversationBase({ avatars, controls, ...rest }) {
|
|
|
1078
1061
|
React__namespace.createElement(MessagesControl, null)),
|
|
1079
1062
|
React__namespace.createElement(FormControl, null))));
|
|
1080
1063
|
}
|
|
1081
|
-
/**
|
|
1082
|
-
* @experimental
|
|
1083
|
-
*/
|
|
1084
1064
|
const AIConversation = Object.assign(AIConversationBase, {
|
|
1085
1065
|
Provider: AIConversationProvider,
|
|
1086
1066
|
DefaultMessage: DefaultMessageControl,
|
|
@@ -1429,9 +1409,6 @@ function createUseAIConversation(client) {
|
|
|
1429
1409
|
return useAIConversation;
|
|
1430
1410
|
}
|
|
1431
1411
|
|
|
1432
|
-
/**
|
|
1433
|
-
* @experimental
|
|
1434
|
-
*/
|
|
1435
1412
|
function createAIHooks(_client) {
|
|
1436
1413
|
const useAIConversation = createUseAIConversation(_client);
|
|
1437
1414
|
const useAIGeneration = createUseAIGeneration(_client);
|
|
@@ -1,8 +1,5 @@
|
|
|
1
1
|
import { AIConversation as AIConversationType, AIConversationInput, AIConversationProps } from './types';
|
|
2
2
|
interface AIConversationBaseProps extends AIConversationProps, AIConversationInput {
|
|
3
3
|
}
|
|
4
|
-
/**
|
|
5
|
-
* @experimental
|
|
6
|
-
*/
|
|
7
4
|
export declare const AIConversation: AIConversationType<AIConversationBaseProps>;
|
|
8
5
|
export {};
|
|
@@ -3,4 +3,4 @@ import { AIConversationInput, AIConversationProps } from './types';
|
|
|
3
3
|
export interface AIConversationProviderProps extends AIConversationInput, AIConversationProps {
|
|
4
4
|
children?: React.ReactNode;
|
|
5
5
|
}
|
|
6
|
-
export declare const AIConversationProvider: ({ actions, allowAttachments, avatars, children, controls, displayText,
|
|
6
|
+
export declare const AIConversationProvider: ({ aiContext, actions, allowAttachments, avatars, children, controls, displayText, handleSendMessage, isLoading, messages, messageRenderer, responseComponents, suggestedPrompts, variant, welcomeMessage, FallbackResponseComponent, }: AIConversationProviderProps) => React.JSX.Element;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
export declare const AIContextContext: React.Context<(() => object) | undefined>;
|
|
3
|
+
export declare const AIContextProvider: ({ children, aiContext, }: {
|
|
4
|
+
children?: React.ReactNode;
|
|
5
|
+
aiContext?: (() => object) | undefined;
|
|
6
|
+
}) => JSX.Element;
|
|
@@ -6,6 +6,7 @@ export interface ControlsContextProps {
|
|
|
6
6
|
Form?: React.ComponentType<{
|
|
7
7
|
handleSubmit: (e: React.FormEvent<HTMLFormElement>) => void;
|
|
8
8
|
allowAttachments?: boolean;
|
|
9
|
+
isLoading?: boolean;
|
|
9
10
|
} & Required<ConversationInputContext>>;
|
|
10
11
|
MessageList?: React.ComponentType<{
|
|
11
12
|
messages: ConversationMessage[];
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
export { AIContextContext, AIContextProvider } from './AIContextContext';
|
|
1
2
|
export { ActionsContext, ActionsProvider } from './ActionsContext';
|
|
2
3
|
export { AvatarsContext, AvatarsProvider } from './AvatarsContext';
|
|
3
4
|
export { ConversationInputContext, ConversationInput, ConversationInputContextProvider, } from './ConversationInputContext';
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import { AIConversationElements } from './context/elements';
|
|
3
2
|
import { ActionsBarControl, AvatarControl, FormControl, MessagesControl, PromptControl } from './views';
|
|
4
3
|
import { DisplayTextTemplate } from '@aws-amplify/ui';
|
|
5
4
|
import { AIConversationDisplayText } from './displayText';
|
|
@@ -14,7 +13,6 @@ export interface Controls {
|
|
|
14
13
|
SuggestedPrompts: PromptControl;
|
|
15
14
|
}
|
|
16
15
|
export interface AIConversationInput {
|
|
17
|
-
elements?: Partial<AIConversationElements>;
|
|
18
16
|
displayText?: DisplayTextTemplate<AIConversationDisplayText>;
|
|
19
17
|
welcomeMessage?: React.ReactNode;
|
|
20
18
|
suggestedPrompts?: SuggestedPrompt[];
|
|
@@ -31,6 +29,7 @@ export interface AIConversationProps {
|
|
|
31
29
|
handleSendMessage: SendMessage;
|
|
32
30
|
avatars?: Avatars;
|
|
33
31
|
isLoading?: boolean;
|
|
32
|
+
aiContext?: () => object;
|
|
34
33
|
}
|
|
35
34
|
export interface AIConversation<PropsType extends AIConversationProps = AIConversationProps> {
|
|
36
35
|
(props: PropsType): JSX.Element;
|
|
@@ -4,13 +4,10 @@ import { ActionsBarControl } from './ActionsBarControl';
|
|
|
4
4
|
import { AvatarControl } from './AvatarControl';
|
|
5
5
|
import { ConversationMessage } from '../../../../types';
|
|
6
6
|
export declare const MessageControl: MessageControl;
|
|
7
|
-
interface MessageControl
|
|
7
|
+
interface MessageControl {
|
|
8
8
|
(props: {
|
|
9
9
|
message: ConversationMessage;
|
|
10
10
|
}): JSX.Element;
|
|
11
|
-
Container: T['View'];
|
|
12
|
-
MediaContent: T['Image'];
|
|
13
|
-
TextContent: T['Text'];
|
|
14
11
|
}
|
|
15
12
|
export declare const MessagesControl: MessagesControl;
|
|
16
13
|
export interface MessagesControl {
|
|
@@ -21,6 +18,5 @@ export interface MessagesControl {
|
|
|
21
18
|
HeaderContainer: AIConversationElements['View'];
|
|
22
19
|
Layout: AIConversationElements['View'];
|
|
23
20
|
Message: MessageControl;
|
|
24
|
-
Separator: AIConversationElements['Span'];
|
|
25
21
|
}
|
|
26
22
|
export {};
|
|
@@ -4,8 +4,5 @@ import { getSchema } from '../types';
|
|
|
4
4
|
type UseAIHooks<Client extends Record<'generations' | 'conversations', Record<string, any>>, Schema extends Record<any, any>> = {
|
|
5
5
|
useAIConversation: UseAIConversationHook<Extract<keyof Client['conversations'], string>>;
|
|
6
6
|
} & UseAIGenerationHookWrapper<keyof Client['generations'], Schema>;
|
|
7
|
-
/**
|
|
8
|
-
* @experimental
|
|
9
|
-
*/
|
|
10
7
|
export declare function createAIHooks<Client extends Record<'generations' | 'conversations', Record<string, any>>, Schema extends getSchema<Client>>(_client: Client): UseAIHooks<Client, Schema>;
|
|
11
8
|
export {};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aws-amplify/ui-react-ai",
|
|
3
|
-
"version": "0.0.0-storage-browser-alpha-
|
|
3
|
+
"version": "0.0.0-storage-browser-alpha-e18d186-20241119023645",
|
|
4
4
|
"main": "dist/index.js",
|
|
5
5
|
"module": "dist/esm/index.mjs",
|
|
6
6
|
"exports": {
|
|
@@ -48,9 +48,9 @@
|
|
|
48
48
|
"react-dom": "^16.14.0 || ^17.0 || ^18.0"
|
|
49
49
|
},
|
|
50
50
|
"dependencies": {
|
|
51
|
-
"@aws-amplify/ui": "0.0.0-storage-browser-alpha-
|
|
52
|
-
"@aws-amplify/ui-react": "0.0.0-storage-browser-alpha-
|
|
53
|
-
"@aws-amplify/ui-react-core": "0.0.0-storage-browser-alpha-
|
|
51
|
+
"@aws-amplify/ui": "0.0.0-storage-browser-alpha-e18d186-20241119023645",
|
|
52
|
+
"@aws-amplify/ui-react": "0.0.0-storage-browser-alpha-e18d186-20241119023645",
|
|
53
|
+
"@aws-amplify/ui-react-core": "0.0.0-storage-browser-alpha-e18d186-20241119023645"
|
|
54
54
|
},
|
|
55
55
|
"devDependencies": {
|
|
56
56
|
"@types/jest-when": "^3.5.0",
|