@aws-amplify/ui-react-ai 0.4.0 → 1.0.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/esm/components/AIConversation/AIConversation.mjs +8 -26
- package/dist/esm/components/AIConversation/AIConversationProvider.mjs +20 -17
- package/dist/esm/components/AIConversation/context/AIContextContext.mjs +8 -0
- package/dist/esm/components/AIConversation/context/FallbackComponentContext.mjs +8 -0
- package/dist/esm/components/AIConversation/context/ResponseComponentsContext.mjs +6 -2
- package/dist/esm/components/AIConversation/createAIConversation.mjs +2 -5
- package/dist/esm/components/AIConversation/views/Controls/ActionsBarControl.mjs +3 -2
- package/dist/esm/components/AIConversation/views/Controls/AttachFileControl.mjs +2 -0
- package/dist/esm/components/AIConversation/views/Controls/AttachmentListControl.mjs +2 -0
- package/dist/esm/components/AIConversation/views/Controls/AvatarControl.mjs +2 -0
- package/dist/esm/components/AIConversation/views/Controls/DefaultMessageControl.mjs +2 -0
- package/dist/esm/components/AIConversation/views/Controls/FormControl.mjs +11 -4
- package/dist/esm/components/AIConversation/views/Controls/MessagesControl.mjs +24 -31
- package/dist/esm/components/AIConversation/views/Controls/PromptControl.mjs +2 -0
- package/dist/esm/components/AIConversation/views/default/Form.mjs +4 -5
- package/dist/esm/components/AIConversation/views/default/MessageList.mjs +31 -16
- package/dist/esm/hooks/contentFromEvents.mjs +22 -0
- package/dist/esm/hooks/createAIHooks.mjs +0 -3
- package/dist/esm/hooks/exhaustivelyListMessages.mjs +19 -0
- package/dist/esm/hooks/shared.mjs +14 -0
- package/dist/esm/hooks/useAIConversation.mjs +246 -106
- package/dist/esm/hooks/useAIGeneration.mjs +1 -8
- package/dist/esm/index.mjs +0 -1
- package/dist/esm/version.mjs +1 -1
- package/dist/index.js +396 -236
- 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/FallbackComponentContext.d.ts +7 -0
- package/dist/types/components/AIConversation/context/ResponseComponentsContext.d.ts +2 -2
- package/dist/types/components/AIConversation/context/elements/definitions.d.ts +1 -1
- package/dist/types/components/AIConversation/context/index.d.ts +2 -0
- package/dist/types/components/AIConversation/createAIConversation.d.ts +0 -3
- package/dist/types/components/AIConversation/index.d.ts +2 -1
- package/dist/types/components/AIConversation/types.d.ts +4 -24
- package/dist/types/components/AIConversation/views/Controls/MessagesControl.d.ts +1 -5
- package/dist/types/components/AIConversation/views/default/Form.d.ts +1 -1
- package/dist/types/components/AIConversation/views/default/MessageList.d.ts +1 -1
- package/dist/types/components/AIConversation/views/default/PromptList.d.ts +1 -1
- package/dist/types/hooks/contentFromEvents.d.ts +2 -0
- package/dist/types/hooks/createAIHooks.d.ts +0 -3
- package/dist/types/hooks/exhaustivelyListMessages.d.ts +8 -0
- package/dist/types/hooks/index.d.ts +1 -2
- package/dist/types/hooks/shared.d.ts +23 -0
- package/dist/types/hooks/useAIConversation.d.ts +6 -4
- package/dist/types/hooks/useAIGeneration.d.ts +3 -13
- package/dist/types/index.d.ts +1 -1
- package/dist/types/types.d.ts +32 -1
- package/dist/types/version.d.ts +1 -1
- package/package.json +4 -4
- package/dist/ai-conversation-styles.css +0 -195
- package/dist/ai-conversation-styles.js +0 -2
- package/dist/esm/hooks/AIContextProvider.mjs +0 -20
- package/dist/types/ai-conversation-styles.d.ts +0 -1
- package/dist/types/hooks/AIContextProvider.d.ts +0 -17
|
@@ -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[];
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { AIConversationInput } from '../types';
|
|
3
|
+
export declare const FallbackComponentContext: React.Context<React.ComponentType<any> | undefined>;
|
|
4
|
+
export declare const FallbackComponentProvider: ({ children, FallbackComponent, }: {
|
|
5
|
+
children?: React.ReactNode;
|
|
6
|
+
FallbackComponent?: AIConversationInput['FallbackResponseComponent'];
|
|
7
|
+
}) => JSX.Element;
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import { ResponseComponents } from '
|
|
3
|
-
import { ToolConfiguration } from '../../../types';
|
|
2
|
+
import { ToolConfiguration, ResponseComponents } from '../../../types';
|
|
4
3
|
type ResponseComponentsContextProps = ResponseComponents | undefined;
|
|
5
4
|
export declare const RESPONSE_COMPONENT_PREFIX = "AMPLIFY_UI_";
|
|
6
5
|
export declare const ResponseComponentsContext: React.Context<ResponseComponentsContextProps>;
|
|
6
|
+
export declare const prependResponseComponents: (responseComponents?: ResponseComponents) => ResponseComponents | undefined;
|
|
7
7
|
export declare const ResponseComponentsProvider: ({ children, responseComponents, }: {
|
|
8
8
|
children?: React.ReactNode;
|
|
9
9
|
responseComponents?: ResponseComponents | undefined;
|
|
@@ -29,7 +29,7 @@ export declare const ButtonElement: import("@aws-amplify/ui-react-core/dist/type
|
|
|
29
29
|
type ViewElementProps = 'onFocus' | 'tabIndex' | 'onKeyDown';
|
|
30
30
|
export declare const ViewElement: import("@aws-amplify/ui-react-core/dist/types/elements/types").BaseElement<import("@aws-amplify/ui-react-core/dist/types/elements/types").BaseElementProps<ViewElementProps, string, import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLDivElement>, HTMLDivElement>>, HTMLDivElement>;
|
|
31
31
|
export declare const SpanElement: import("@aws-amplify/ui-react-core/dist/types/elements/types").BaseElement<import("@aws-amplify/ui-react-core/dist/types/elements/types").BaseElementProps<never, string, import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLSpanElement>, HTMLSpanElement>>, HTMLSpanElement>;
|
|
32
|
-
type TextAreaElementProps = 'id' | 'name' | 'onChange' | 'placeholder' | 'autoFocus' | 'onKeyDown';
|
|
32
|
+
type TextAreaElementProps = 'id' | 'name' | 'onChange' | 'placeholder' | 'autoFocus' | 'onCompositionStart' | 'onCompositionEnd' | 'onKeyDown';
|
|
33
33
|
export declare const TextAreaElement: import("@aws-amplify/ui-react-core/dist/types/elements/types").BaseElement<import("@aws-amplify/ui-react-core/dist/types/elements/types").BaseElementProps<TextAreaElementProps, string, import("react").DetailedHTMLProps<import("react").TextareaHTMLAttributes<HTMLTextAreaElement>, HTMLTextAreaElement>>, HTMLTextAreaElement>;
|
|
34
34
|
export declare const AIConversationElements: AIConversationElements;
|
|
35
35
|
export {};
|
|
@@ -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';
|
|
@@ -12,4 +13,5 @@ export { SendMessageContextProvider } from './SendMessageContext';
|
|
|
12
13
|
export { MessageRendererProvider, MessageRendererContext, useMessageRenderer, } from './MessageRenderContext';
|
|
13
14
|
export { AttachmentProvider, AttachmentContext } from './AttachmentContext';
|
|
14
15
|
export { WelcomeMessageContext, WelcomeMessageProvider, } from './WelcomeMessageContext';
|
|
16
|
+
export { FallbackComponentContext, FallbackComponentProvider, } from './FallbackComponentContext';
|
|
15
17
|
export * from './elements';
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { createAIConversation } from './createAIConversation';
|
|
2
2
|
import { AIConversation } from './AIConversation';
|
|
3
|
-
import { Avatars, CustomAction,
|
|
3
|
+
import { Avatars, CustomAction, SuggestedPrompt } from './types';
|
|
4
|
+
import { ResponseComponent } from '../../types';
|
|
4
5
|
export { createAIConversation, AIConversation, Avatars, CustomAction, ResponseComponent, SuggestedPrompt, };
|
|
@@ -1,9 +1,8 @@
|
|
|
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';
|
|
6
|
-
import { ConversationMessage,
|
|
5
|
+
import { ConversationMessage, SendMessage, ResponseComponents, TextContentBlock, ImageContentBlock } from '../../types';
|
|
7
6
|
import { ControlsContextProps } from './context/ControlsContext';
|
|
8
7
|
import { AIConversationProviderProps } from './AIConversationProvider';
|
|
9
8
|
export interface Controls {
|
|
@@ -14,12 +13,12 @@ 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[];
|
|
21
19
|
actions?: CustomAction[];
|
|
22
20
|
responseComponents?: ResponseComponents;
|
|
21
|
+
FallbackResponseComponent?: React.ComponentType<any>;
|
|
23
22
|
variant?: MessageVariant;
|
|
24
23
|
controls?: ControlsContextProps;
|
|
25
24
|
allowAttachments?: boolean;
|
|
@@ -30,6 +29,7 @@ export interface AIConversationProps {
|
|
|
30
29
|
handleSendMessage: SendMessage;
|
|
31
30
|
avatars?: Avatars;
|
|
32
31
|
isLoading?: boolean;
|
|
32
|
+
aiContext?: () => object;
|
|
33
33
|
}
|
|
34
34
|
export interface AIConversation<PropsType extends AIConversationProps = AIConversationProps> {
|
|
35
35
|
(props: PropsType): JSX.Element;
|
|
@@ -56,30 +56,10 @@ export interface Avatars {
|
|
|
56
56
|
ai?: Avatar;
|
|
57
57
|
}
|
|
58
58
|
export interface CustomAction {
|
|
59
|
-
displayName: string;
|
|
60
59
|
handler: (message: ConversationMessage) => void;
|
|
61
|
-
|
|
60
|
+
component?: React.ReactNode;
|
|
62
61
|
}
|
|
63
62
|
export interface SuggestedPrompt {
|
|
64
63
|
component?: React.ReactNode;
|
|
65
64
|
inputText: string;
|
|
66
65
|
}
|
|
67
|
-
type JSONType = 'string' | 'number' | 'integer' | 'boolean' | 'object' | 'array' | 'null' | 'any';
|
|
68
|
-
interface ResponseComponentProp {
|
|
69
|
-
type: JSONType;
|
|
70
|
-
enum?: string[];
|
|
71
|
-
description?: string;
|
|
72
|
-
required?: boolean;
|
|
73
|
-
}
|
|
74
|
-
interface ResponseComponentPropMap {
|
|
75
|
-
[key: string]: ResponseComponentProp;
|
|
76
|
-
}
|
|
77
|
-
export interface ResponseComponent {
|
|
78
|
-
component: React.ComponentType<any>;
|
|
79
|
-
description?: string;
|
|
80
|
-
props: ResponseComponentPropMap;
|
|
81
|
-
}
|
|
82
|
-
export interface ResponseComponents {
|
|
83
|
-
[key: string]: ResponseComponent;
|
|
84
|
-
}
|
|
85
|
-
export {};
|
|
@@ -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 {};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import { ControlsContextProps } from '../../context/ControlsContext';
|
|
2
|
-
export declare const Form:
|
|
2
|
+
export declare const Form: Required<ControlsContextProps>['Form'];
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import { ControlsContextProps } from '../../context/ControlsContext';
|
|
2
|
-
export declare const MessageList: ControlsContextProps['MessageList'];
|
|
2
|
+
export declare const MessageList: Required<ControlsContextProps>['MessageList'];
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import { ControlsContextProps } from '../../context/ControlsContext';
|
|
2
|
-
export declare const PromptList: ControlsContextProps['PromptList'];
|
|
2
|
+
export declare const PromptList: Required<ControlsContextProps>['PromptList'];
|
|
@@ -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 {};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { Conversation, ConversationMessage } from '../types';
|
|
2
|
+
interface ExhaustivelyListMessagesParams {
|
|
3
|
+
conversation: Conversation;
|
|
4
|
+
messages?: ConversationMessage[];
|
|
5
|
+
nextToken?: string;
|
|
6
|
+
}
|
|
7
|
+
export declare function exhaustivelyListMessages({ conversation, messages, nextToken, }: ExhaustivelyListMessagesParams): ReturnType<Conversation['listMessages']>;
|
|
8
|
+
export {};
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { DataState } from '@aws-amplify/ui-react-core';
|
|
2
|
+
import { GraphQLFormattedError } from '../types';
|
|
3
|
+
export type DataClientState<T> = Omit<DataState<T>, 'message'> & {
|
|
4
|
+
messages?: GraphQLFormattedError[];
|
|
5
|
+
};
|
|
6
|
+
export type DataClientResponse<T> = {
|
|
7
|
+
data: T | null;
|
|
8
|
+
errors?: GraphQLFormattedError[];
|
|
9
|
+
};
|
|
10
|
+
export declare const INITIAL_STATE: {
|
|
11
|
+
hasError: boolean;
|
|
12
|
+
isLoading: boolean;
|
|
13
|
+
messages: undefined;
|
|
14
|
+
};
|
|
15
|
+
export declare const LOADING_STATE: {
|
|
16
|
+
hasError: boolean;
|
|
17
|
+
isLoading: boolean;
|
|
18
|
+
messages: undefined;
|
|
19
|
+
};
|
|
20
|
+
export declare const ERROR_STATE: {
|
|
21
|
+
hasError: boolean;
|
|
22
|
+
isLoading: boolean;
|
|
23
|
+
};
|
|
@@ -1,12 +1,14 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { Conversation, ConversationMessage, ConversationRoute, SendMessage } from '../types';
|
|
2
|
+
import { DataClientState } from './shared';
|
|
3
3
|
interface UseAIConversationInput {
|
|
4
4
|
id?: string;
|
|
5
|
-
|
|
5
|
+
onMessage?: (message: ConversationMessage) => void;
|
|
6
|
+
onInitialize?: (conversation: Conversation) => void;
|
|
6
7
|
}
|
|
7
8
|
interface AIConversationState {
|
|
8
9
|
messages: ConversationMessage[];
|
|
10
|
+
conversation?: Conversation;
|
|
9
11
|
}
|
|
10
|
-
export type UseAIConversationHook<T extends string> = (routeName: T, input?: UseAIConversationInput) => [
|
|
12
|
+
export type UseAIConversationHook<T extends string> = (routeName: T, input?: UseAIConversationInput) => [DataClientState<AIConversationState>, SendMessage];
|
|
11
13
|
export declare function createUseAIConversation<T extends Record<'conversations', Record<string, ConversationRoute>>>(client: T): UseAIConversationHook<Extract<keyof T['conversations'], string>>;
|
|
12
14
|
export {};
|
|
@@ -1,26 +1,16 @@
|
|
|
1
|
-
import { DataState } from '@aws-amplify/ui-react-core';
|
|
2
1
|
import { V6Client } from '@aws-amplify/api-graphql';
|
|
3
2
|
import { getSchema } from '../types';
|
|
3
|
+
import { DataClientState } from './shared';
|
|
4
4
|
export interface UseAIGenerationHookWrapper<Key extends keyof AIGenerationClient<Schema>['generations'], Schema extends Record<any, any>> {
|
|
5
5
|
useAIGeneration: <U extends Key>(routeName: U) => [
|
|
6
|
-
Awaited<
|
|
6
|
+
Awaited<DataClientState<Schema[U]['returnType']>>,
|
|
7
7
|
(input: Schema[U]['args']) => void
|
|
8
8
|
];
|
|
9
9
|
}
|
|
10
10
|
export type UseAIGenerationHook<Key extends keyof AIGenerationClient<Schema>['generations'], Schema extends Record<any, any>> = (routeName: Key) => [
|
|
11
|
-
Awaited<
|
|
11
|
+
Awaited<DataClientState<Schema[Key]['returnType']>>,
|
|
12
12
|
(input: Schema[Key]['args']) => void
|
|
13
13
|
];
|
|
14
14
|
type AIGenerationClient<T extends Record<any, any>> = Pick<V6Client<T>, 'generations'>;
|
|
15
|
-
interface GraphQLFormattedError {
|
|
16
|
-
readonly message: string;
|
|
17
|
-
readonly errorType: string;
|
|
18
|
-
readonly errorInfo: null | {
|
|
19
|
-
[key: string]: unknown;
|
|
20
|
-
};
|
|
21
|
-
}
|
|
22
|
-
type GenerationState<T> = Omit<DataState<T>, 'message'> & {
|
|
23
|
-
messages?: GraphQLFormattedError[];
|
|
24
|
-
};
|
|
25
15
|
export declare function createUseAIGeneration<Client extends Record<'generations' | 'conversations', Record<string, any>>, Schema extends getSchema<Client>>(client: Client): UseAIGenerationHook<keyof Client['generations'], Client>;
|
|
26
16
|
export {};
|
package/dist/types/index.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
export { createAIConversation, AIConversation, Avatars, CustomAction, ResponseComponent, SuggestedPrompt, } from './components';
|
|
2
|
-
export { createAIHooks
|
|
2
|
+
export { createAIHooks } from './hooks';
|
|
3
3
|
export { ConversationMessage, ConversationMessageContent, SendMessage, SendMesageParameters, } from './types';
|
package/dist/types/types.d.ts
CHANGED
|
@@ -1,10 +1,16 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
1
2
|
import { V6Client } from '@aws-amplify/api-graphql';
|
|
2
3
|
export type ConversationRoute = V6Client<any>['conversations'][string];
|
|
3
4
|
export type Conversation = NonNullable<Awaited<ReturnType<ConversationRoute['create']>>['data']>;
|
|
4
|
-
export type
|
|
5
|
+
export type ConversationStreamEvent = Parameters<Parameters<Conversation['onStreamEvent']>[0]['next']>[0];
|
|
6
|
+
export type ConversationMessage = NonNullable<Awaited<ReturnType<Conversation['sendMessage']>>['data']> & {
|
|
7
|
+
isLoading?: boolean;
|
|
8
|
+
};
|
|
5
9
|
export type ConversationMessageContent = ConversationMessage['content'][number];
|
|
6
10
|
export type TextContentBlock = NonNullable<ConversationMessageContent['text']>;
|
|
7
11
|
export type ImageContentBlock = NonNullable<ConversationMessageContent['image']>;
|
|
12
|
+
export type ToolUseContent = NonNullable<ConversationMessageContent['toolUse']>;
|
|
13
|
+
export type ToolResultContent = NonNullable<ConversationMessageContent['toolResult']>;
|
|
8
14
|
export type InputContent = Exclude<Parameters<Conversation['sendMessage']>[0], string>['content'][number];
|
|
9
15
|
export type SendMessageContent = Exclude<Parameters<Conversation['sendMessage']>[0], string>['content'];
|
|
10
16
|
export type SendMessageContext = Exclude<Parameters<Conversation['sendMessage']>[0], string>['aiContext'];
|
|
@@ -17,4 +23,29 @@ export interface SendMesageParameters {
|
|
|
17
23
|
export type SendMessage = (input: SendMesageParameters) => void;
|
|
18
24
|
type AIClient<T extends Record<any, any>> = Pick<V6Client<T>, 'generations' | 'conversations'>;
|
|
19
25
|
export type getSchema<T> = T extends AIClient<infer Schema> ? Schema : never;
|
|
26
|
+
export interface GraphQLFormattedError {
|
|
27
|
+
readonly message: string;
|
|
28
|
+
readonly errorType: string;
|
|
29
|
+
readonly errorInfo?: null | {
|
|
30
|
+
[key: string]: unknown;
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
type JSONType = 'string' | 'number' | 'integer' | 'boolean' | 'object' | 'array' | 'null' | 'any';
|
|
34
|
+
interface ResponseComponentProp {
|
|
35
|
+
type: JSONType;
|
|
36
|
+
enum?: string[];
|
|
37
|
+
description?: string;
|
|
38
|
+
required?: boolean;
|
|
39
|
+
}
|
|
40
|
+
interface ResponseComponentPropMap {
|
|
41
|
+
[key: string]: ResponseComponentProp;
|
|
42
|
+
}
|
|
43
|
+
export interface ResponseComponent {
|
|
44
|
+
component: React.ComponentType<any>;
|
|
45
|
+
description?: string;
|
|
46
|
+
props: ResponseComponentPropMap;
|
|
47
|
+
}
|
|
48
|
+
export interface ResponseComponents {
|
|
49
|
+
[key: string]: ResponseComponent;
|
|
50
|
+
}
|
|
20
51
|
export {};
|
package/dist/types/version.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const VERSION = "0.
|
|
1
|
+
export declare const VERSION = "1.0.0";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aws-amplify/ui-react-ai",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "1.0.0",
|
|
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": "^6.6.
|
|
52
|
-
"@aws-amplify/ui-react": "^6.
|
|
53
|
-
"@aws-amplify/ui-react-core": "^3.0.
|
|
51
|
+
"@aws-amplify/ui": "^6.6.6",
|
|
52
|
+
"@aws-amplify/ui-react": "^6.6.0",
|
|
53
|
+
"@aws-amplify/ui-react-core": "^3.0.30"
|
|
54
54
|
},
|
|
55
55
|
"devDependencies": {
|
|
56
56
|
"@types/jest-when": "^3.5.0",
|
|
@@ -1,195 +0,0 @@
|
|
|
1
|
-
.ai-header__container {
|
|
2
|
-
display: flex;
|
|
3
|
-
flex-direction: row;
|
|
4
|
-
flex: 0 0 auto;
|
|
5
|
-
justify-content: space-between;
|
|
6
|
-
border: 1px solid rgb(220, 222, 224);
|
|
7
|
-
border-radius: 16px 16px 0px 0px;
|
|
8
|
-
padding: 0px 16px;
|
|
9
|
-
box-shadow: rgba(0, 0, 0, 0.07) 0px 12px 30px 0px;
|
|
10
|
-
background-color: rgb(250, 250, 250);
|
|
11
|
-
flex-grow: 1;
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
.ai-header__button {
|
|
15
|
-
border: none;
|
|
16
|
-
background: none;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
.ai-prompts__prompt__buttongroup {
|
|
20
|
-
display: flex;
|
|
21
|
-
gap: 8px;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
.ai-prompts__prompt__card {
|
|
25
|
-
display: flex;
|
|
26
|
-
flex-direction: column;
|
|
27
|
-
flex: 1;
|
|
28
|
-
border-radius: 8px;
|
|
29
|
-
border-width: 0px;
|
|
30
|
-
text-align: left;
|
|
31
|
-
white-space: nowrap;
|
|
32
|
-
padding: 12px;
|
|
33
|
-
cursor: pointer;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
.ai-prompts__prompt__card__header {
|
|
37
|
-
font-weight: bold;
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
.ai-prompts__prompt__card__text {
|
|
41
|
-
margin: 0px;
|
|
42
|
-
overflow: hidden;
|
|
43
|
-
text-overflow: ellipsis;
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
.ai-messages__container {
|
|
47
|
-
display: flex;
|
|
48
|
-
flex-direction: column;
|
|
49
|
-
width: 100%;
|
|
50
|
-
justify-content: flex-end;
|
|
51
|
-
align-items: flex-start;
|
|
52
|
-
gap: 16px;
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
.ai-message {
|
|
56
|
-
display: flex;
|
|
57
|
-
flex-direction: column;
|
|
58
|
-
width: 480px;
|
|
59
|
-
align-items: flex-start;
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
.ai-message__text {
|
|
63
|
-
white-space: pre-wrap;
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
.ai-message--bubble-2.ai-message--user {
|
|
67
|
-
justify-content: flex-end;
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
.ai-message__header__container {
|
|
71
|
-
display: flex;
|
|
72
|
-
flex-direction: row;
|
|
73
|
-
align-items: center;
|
|
74
|
-
gap: 12px;
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
.ai-message__image {
|
|
78
|
-
width: 100%;
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
.ai-avatar__container {
|
|
82
|
-
display: flex;
|
|
83
|
-
flex-direction: row;
|
|
84
|
-
gap: 12px;
|
|
85
|
-
align-items: center;
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
.ai-avatar__icon {
|
|
89
|
-
width: 40px;
|
|
90
|
-
height: 40px;
|
|
91
|
-
border-radius: 50%;
|
|
92
|
-
display: flex;
|
|
93
|
-
overflow: hidden;
|
|
94
|
-
justify-content: center;
|
|
95
|
-
align-items: center;
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
.ai-actions-bar__container {
|
|
99
|
-
display: flex;
|
|
100
|
-
align-items: flex-start;
|
|
101
|
-
gap: 8px;
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
.ai-actions-bar__icon {
|
|
105
|
-
width: 100%;
|
|
106
|
-
height: 100%;
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
.ai-actions-bar__button {
|
|
110
|
-
display: flex;
|
|
111
|
-
width: 28px;
|
|
112
|
-
height: 28px;
|
|
113
|
-
justify-content: center;
|
|
114
|
-
align-items: center;
|
|
115
|
-
gap: 4px;
|
|
116
|
-
overflow: hidden;
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
.ai-field__form {
|
|
120
|
-
display: flex;
|
|
121
|
-
flex-direction: row;
|
|
122
|
-
align-items: flex-start;
|
|
123
|
-
gap: 8px;
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
.ai-field__input-container {
|
|
127
|
-
display: flex;
|
|
128
|
-
flex-direction: column;
|
|
129
|
-
align-items: flex-start;
|
|
130
|
-
gap: 8px;
|
|
131
|
-
flex: 1 0 0;
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
.ai-attachment-list__unordered-list {
|
|
135
|
-
gap: 8px;
|
|
136
|
-
display: flex;
|
|
137
|
-
flex-direction: column;
|
|
138
|
-
width: 70%;
|
|
139
|
-
padding: 0px;
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
.ai-attachment__list-item {
|
|
143
|
-
display: flex;
|
|
144
|
-
align-items: center;
|
|
145
|
-
gap: 8px;
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
.ai-attachment-text__container {
|
|
149
|
-
display: flex;
|
|
150
|
-
align-items: center;
|
|
151
|
-
flex: 1;
|
|
152
|
-
overflow: hidden;
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
.ai-attachment-text__separator {
|
|
156
|
-
flex-shrink: 0;
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
.ai-attachment-text__file-name {
|
|
160
|
-
flex: 1;
|
|
161
|
-
overflow: hidden;
|
|
162
|
-
text-overflow: ellipsis;
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
.ai-attachment-text__file-size {
|
|
166
|
-
flex-shrink: 0;
|
|
167
|
-
margin-left: 8px;
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
.ai-field__input {
|
|
171
|
-
align-self: stretch;
|
|
172
|
-
overflow: hidden;
|
|
173
|
-
resize: none;
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
.ai-field__button {
|
|
177
|
-
display: flex;
|
|
178
|
-
width: 40px;
|
|
179
|
-
height: 40px;
|
|
180
|
-
justify-content: center;
|
|
181
|
-
align-items: center;
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
.ai-field__visually-hidden {
|
|
185
|
-
position: absolute;
|
|
186
|
-
width: 1px;
|
|
187
|
-
height: 1px;
|
|
188
|
-
padding: 0;
|
|
189
|
-
margin: -1px;
|
|
190
|
-
fill: transparent;
|
|
191
|
-
overflow: hidden;
|
|
192
|
-
clip: rect(0, 0, 0, 0);
|
|
193
|
-
white-space: nowrap;
|
|
194
|
-
border-width: 0;
|
|
195
|
-
}
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import React__default from 'react';
|
|
2
|
-
|
|
3
|
-
const AIContext = React__default.createContext(undefined);
|
|
4
|
-
const useAIContext = () => {
|
|
5
|
-
const context = React__default.useContext(AIContext);
|
|
6
|
-
const [routeToConversationsMap, setRouteToConversationsMap] = React__default.useState({});
|
|
7
|
-
if (context) {
|
|
8
|
-
return context;
|
|
9
|
-
}
|
|
10
|
-
return { routeToConversationsMap, setRouteToConversationsMap };
|
|
11
|
-
};
|
|
12
|
-
/**
|
|
13
|
-
* @experimental
|
|
14
|
-
*/
|
|
15
|
-
const AIContextProvider = ({ children, }) => {
|
|
16
|
-
const context = useAIContext();
|
|
17
|
-
return React__default.createElement(AIContext.Provider, { value: context }, children);
|
|
18
|
-
};
|
|
19
|
-
|
|
20
|
-
export { AIContext, AIContextProvider, useAIContext };
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import './ai-conversation-styles.css';
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import { ConversationMessage } from '../types';
|
|
3
|
-
type ConversationToMessages = Record<string, ConversationMessage[]>;
|
|
4
|
-
export type RouteToConversations = Record<string, ConversationToMessages>;
|
|
5
|
-
interface ContextType {
|
|
6
|
-
routeToConversationsMap: RouteToConversations;
|
|
7
|
-
setRouteToConversationsMap: React.Dispatch<React.SetStateAction<RouteToConversations>>;
|
|
8
|
-
}
|
|
9
|
-
export declare const AIContext: React.Context<ContextType | undefined>;
|
|
10
|
-
export declare const useAIContext: () => ContextType;
|
|
11
|
-
/**
|
|
12
|
-
* @experimental
|
|
13
|
-
*/
|
|
14
|
-
export declare const AIContextProvider: ({ children, }: {
|
|
15
|
-
children: React.ReactNode;
|
|
16
|
-
}) => React.ReactNode;
|
|
17
|
-
export {};
|