@aws-amplify/ui-react-ai 1.4.0 → 1.4.1

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.
@@ -1,6 +1,6 @@
1
1
  import * as React from 'react';
2
2
  import { Flex, ScrollView } from '@aws-amplify/ui-react';
3
- import { useIcons, IconAssistant, IconUser } from '@aws-amplify/ui-react/internal';
3
+ import { useIcons, IconUser, IconAssistant } from '@aws-amplify/ui-react/internal';
4
4
  import { MessagesControl } from './views/Controls/MessagesControl.mjs';
5
5
  import { FormControl } from './views/Controls/FormControl.mjs';
6
6
  import { MessageList } from './views/default/MessageList.mjs';
@@ -17,15 +17,15 @@ const ListItemElement = defineBaseElementWithRef({
17
17
  type: 'li',
18
18
  displayName: 'ListItem',
19
19
  });
20
- const HeadingElement = defineBaseElementWithRef({
20
+ defineBaseElementWithRef({
21
21
  type: 'h2',
22
22
  displayName: 'Title',
23
23
  });
24
- const ImageElement = defineBaseElementWithRef({
24
+ defineBaseElementWithRef({
25
25
  type: 'img',
26
26
  displayName: 'Image',
27
27
  });
28
- const InputElement = defineBaseElementWithRef({
28
+ defineBaseElementWithRef({
29
29
  type: 'input',
30
30
  displayName: 'Input',
31
31
  });
@@ -44,10 +44,7 @@ const TextAreaElement = defineBaseElementWithRef({
44
44
  });
45
45
  const AIConversationElements = {
46
46
  Button: ButtonElement,
47
- Heading: HeadingElement,
48
47
  Icon: IconElement,
49
- Input: InputElement,
50
- Image: ImageElement,
51
48
  Label: LabelElement,
52
49
  ListItem: ListItemElement,
53
50
  Span: SpanElement,
@@ -57,4 +54,4 @@ const AIConversationElements = {
57
54
  View: ViewElement,
58
55
  };
59
56
 
60
- export { AIConversationElements, ButtonElement, HeadingElement, ImageElement, InputElement, LabelElement, ListItemElement, SpanElement, TextAreaElement, TextElement, UnorderedListElement, ViewElement };
57
+ export { AIConversationElements, ButtonElement, LabelElement, ListItemElement, SpanElement, TextAreaElement, TextElement, UnorderedListElement, ViewElement };
@@ -27,11 +27,11 @@ function createUseAIConversation(client) {
27
27
  // it will create a new conversation when it is executed
28
28
  // we don't want to create 2 conversations
29
29
  const initRef = React__default.useRef('initial');
30
- const [dataState, setDataState] = React__default.useState(() => ({
30
+ const [clientState, setClientState] = React__default.useState(() => ({
31
31
  ...INITIAL_STATE,
32
32
  data: { messages: [], conversation: undefined },
33
33
  }));
34
- const { conversation } = dataState.data;
34
+ const { conversation } = clientState.data;
35
35
  const { id, onInitialize, onMessage } = input;
36
36
  React__default.useEffect(() => {
37
37
  async function initialize() {
@@ -43,7 +43,7 @@ function createUseAIConversation(client) {
43
43
  // Only show component loading state if we are
44
44
  // actually loading messages
45
45
  if (id) {
46
- setDataState({
46
+ setClientState({
47
47
  ...LOADING_STATE,
48
48
  data: { messages: [], conversation: undefined },
49
49
  });
@@ -52,7 +52,7 @@ function createUseAIConversation(client) {
52
52
  ? await clientRoute.get({ id })
53
53
  : await clientRoute.create();
54
54
  if (errors ?? !conversation) {
55
- setDataState({
55
+ setClientState({
56
56
  ...ERROR_STATE,
57
57
  data: { messages: [] },
58
58
  messages: errors,
@@ -63,13 +63,13 @@ function createUseAIConversation(client) {
63
63
  const { data: messages } = await exhaustivelyListMessages({
64
64
  conversation,
65
65
  });
66
- setDataState({
66
+ setClientState({
67
67
  ...INITIAL_STATE,
68
68
  data: { messages, conversation },
69
69
  });
70
70
  }
71
71
  else {
72
- setDataState({
72
+ setClientState({
73
73
  ...INITIAL_STATE,
74
74
  data: { conversation, messages: [] },
75
75
  });
@@ -87,7 +87,7 @@ function createUseAIConversation(client) {
87
87
  errorInfo: null,
88
88
  errorType: '',
89
89
  };
90
- setDataState({
90
+ setClientState({
91
91
  ...ERROR_STATE,
92
92
  data: { messages: [] },
93
93
  // TODO in MV bump: remove `messages`
@@ -101,12 +101,12 @@ function createUseAIConversation(client) {
101
101
  contentBlocksRef.current = undefined;
102
102
  if (hasStarted(initRef.current))
103
103
  return;
104
- setDataState({
104
+ setClientState({
105
105
  ...INITIAL_STATE,
106
106
  data: { messages: [], conversation: undefined },
107
107
  });
108
108
  };
109
- }, [clientRoute, id, setDataState]);
109
+ }, [clientRoute, id, setClientState]);
110
110
  // Run a separate effect that is triggered by the conversation state
111
111
  // so that we know we have a conversation object to set up the subscription
112
112
  // and also unsubscribe on cleanup
@@ -134,7 +134,7 @@ function createUseAIConversation(client) {
134
134
  // stop reason will signify end of conversation turn
135
135
  if (stopReason) {
136
136
  // remove loading state from streamed message
137
- setDataState((prev) => {
137
+ setClientState((prev) => {
138
138
  return {
139
139
  ...prev,
140
140
  data: {
@@ -181,7 +181,7 @@ function createUseAIConversation(client) {
181
181
  ];
182
182
  }
183
183
  }
184
- setDataState((prev) => {
184
+ setClientState((prev) => {
185
185
  const message = {
186
186
  id,
187
187
  conversationId,
@@ -202,7 +202,7 @@ function createUseAIConversation(client) {
202
202
  });
203
203
  },
204
204
  error: (error) => {
205
- setDataState((prev) => {
205
+ setClientState((prev) => {
206
206
  return {
207
207
  ...prev,
208
208
  ...ERROR_STATE,
@@ -220,11 +220,11 @@ function createUseAIConversation(client) {
220
220
  contentBlocksRef.current = undefined;
221
221
  subscription.unsubscribe();
222
222
  };
223
- }, [conversation, onInitialize, onMessage, setDataState]);
223
+ }, [conversation, onInitialize, onMessage, setClientState]);
224
224
  const handleSendMessage = React__default.useCallback((input) => {
225
225
  const { content } = input;
226
226
  if (conversation) {
227
- setDataState((prevState) => ({
227
+ setClientState((prevState) => ({
228
228
  ...prevState,
229
229
  data: {
230
230
  ...prevState.data,
@@ -257,7 +257,7 @@ function createUseAIConversation(client) {
257
257
  errorInfo: null,
258
258
  errorType: '',
259
259
  };
260
- setDataState((prev) => ({
260
+ setClientState((prev) => ({
261
261
  ...prev,
262
262
  ...ERROR_STATE,
263
263
  // TODO in MV bump: remove `messages`
@@ -266,7 +266,7 @@ function createUseAIConversation(client) {
266
266
  }));
267
267
  }
268
268
  }, [conversation]);
269
- return [dataState, handleSendMessage];
269
+ return [clientState, handleSendMessage];
270
270
  };
271
271
  return useAIConversation;
272
272
  }
@@ -3,26 +3,19 @@ import { INITIAL_STATE, LOADING_STATE, ERROR_STATE } from './shared.mjs';
3
3
 
4
4
  function createUseAIGeneration(client) {
5
5
  const useAIGeneration = (routeName) => {
6
- const [dataState, setDataState] = React.useState(() => ({
7
- ...INITIAL_STATE,
8
- data: undefined,
9
- }));
6
+ const [clientState, setClientState] = React.useState(() => ({ ...INITIAL_STATE, data: undefined }));
10
7
  const handleGeneration = React.useCallback(async (input) => {
11
- setDataState(({ data }) => ({ ...LOADING_STATE, data }));
8
+ setClientState(({ data }) => ({ ...LOADING_STATE, data }));
12
9
  const result = await client.generations[routeName](input);
13
10
  const { data, errors } = result;
14
11
  if (errors) {
15
- setDataState({
16
- ...ERROR_STATE,
17
- data,
18
- messages: errors,
19
- });
12
+ setClientState({ ...ERROR_STATE, data, messages: errors });
20
13
  }
21
14
  else {
22
- setDataState({ ...INITIAL_STATE, data });
15
+ setClientState({ ...INITIAL_STATE, data });
23
16
  }
24
17
  }, [routeName]);
25
- return [dataState, handleGeneration];
18
+ return [clientState, handleGeneration];
26
19
  };
27
20
  return useAIGeneration;
28
21
  }
@@ -1,3 +1,3 @@
1
- const VERSION = '1.4.0';
1
+ const VERSION = '1.4.1';
2
2
 
3
3
  export { VERSION };
package/dist/index.js CHANGED
@@ -342,15 +342,15 @@ const ListItemElement = elements.defineBaseElementWithRef({
342
342
  type: 'li',
343
343
  displayName: 'ListItem',
344
344
  });
345
- const HeadingElement = elements.defineBaseElementWithRef({
345
+ elements.defineBaseElementWithRef({
346
346
  type: 'h2',
347
347
  displayName: 'Title',
348
348
  });
349
- const ImageElement = elements.defineBaseElementWithRef({
349
+ elements.defineBaseElementWithRef({
350
350
  type: 'img',
351
351
  displayName: 'Image',
352
352
  });
353
- const InputElement = elements.defineBaseElementWithRef({
353
+ elements.defineBaseElementWithRef({
354
354
  type: 'input',
355
355
  displayName: 'Input',
356
356
  });
@@ -369,10 +369,7 @@ const TextAreaElement = elements.defineBaseElementWithRef({
369
369
  });
370
370
  const AIConversationElements = {
371
371
  Button: ButtonElement,
372
- Heading: HeadingElement,
373
372
  Icon: IconElement,
374
- Input: InputElement,
375
- Image: ImageElement,
376
373
  Label: LabelElement$1,
377
374
  ListItem: ListItemElement,
378
375
  Span: SpanElement,
@@ -1193,7 +1190,7 @@ const PromptList = ({ setInput, suggestedPrompts = [], }) => {
1193
1190
  })));
1194
1191
  };
1195
1192
 
1196
- const VERSION = '1.4.0';
1193
+ const VERSION = '1.4.1';
1197
1194
 
1198
1195
  function AIConversationBase({ avatars, controls, ...rest }) {
1199
1196
  uiReactCore.useSetUserAgent({
@@ -1254,26 +1251,19 @@ const ERROR_STATE = { hasError: true, isLoading: false };
1254
1251
 
1255
1252
  function createUseAIGeneration(client) {
1256
1253
  const useAIGeneration = (routeName) => {
1257
- const [dataState, setDataState] = React__namespace.useState(() => ({
1258
- ...INITIAL_STATE,
1259
- data: undefined,
1260
- }));
1254
+ const [clientState, setClientState] = React__namespace.useState(() => ({ ...INITIAL_STATE, data: undefined }));
1261
1255
  const handleGeneration = React__namespace.useCallback(async (input) => {
1262
- setDataState(({ data }) => ({ ...LOADING_STATE, data }));
1256
+ setClientState(({ data }) => ({ ...LOADING_STATE, data }));
1263
1257
  const result = await client.generations[routeName](input);
1264
1258
  const { data, errors } = result;
1265
1259
  if (errors) {
1266
- setDataState({
1267
- ...ERROR_STATE,
1268
- data,
1269
- messages: errors,
1270
- });
1260
+ setClientState({ ...ERROR_STATE, data, messages: errors });
1271
1261
  }
1272
1262
  else {
1273
- setDataState({ ...INITIAL_STATE, data });
1263
+ setClientState({ ...INITIAL_STATE, data });
1274
1264
  }
1275
1265
  }, [routeName]);
1276
- return [dataState, handleGeneration];
1266
+ return [clientState, handleGeneration];
1277
1267
  };
1278
1268
  return useAIGeneration;
1279
1269
  }
@@ -1340,11 +1330,11 @@ function createUseAIConversation(client) {
1340
1330
  // it will create a new conversation when it is executed
1341
1331
  // we don't want to create 2 conversations
1342
1332
  const initRef = React__namespace["default"].useRef('initial');
1343
- const [dataState, setDataState] = React__namespace["default"].useState(() => ({
1333
+ const [clientState, setClientState] = React__namespace["default"].useState(() => ({
1344
1334
  ...INITIAL_STATE,
1345
1335
  data: { messages: [], conversation: undefined },
1346
1336
  }));
1347
- const { conversation } = dataState.data;
1337
+ const { conversation } = clientState.data;
1348
1338
  const { id, onInitialize, onMessage } = input;
1349
1339
  React__namespace["default"].useEffect(() => {
1350
1340
  async function initialize() {
@@ -1356,7 +1346,7 @@ function createUseAIConversation(client) {
1356
1346
  // Only show component loading state if we are
1357
1347
  // actually loading messages
1358
1348
  if (id) {
1359
- setDataState({
1349
+ setClientState({
1360
1350
  ...LOADING_STATE,
1361
1351
  data: { messages: [], conversation: undefined },
1362
1352
  });
@@ -1365,7 +1355,7 @@ function createUseAIConversation(client) {
1365
1355
  ? await clientRoute.get({ id })
1366
1356
  : await clientRoute.create();
1367
1357
  if (errors ?? !conversation) {
1368
- setDataState({
1358
+ setClientState({
1369
1359
  ...ERROR_STATE,
1370
1360
  data: { messages: [] },
1371
1361
  messages: errors,
@@ -1376,13 +1366,13 @@ function createUseAIConversation(client) {
1376
1366
  const { data: messages } = await exhaustivelyListMessages({
1377
1367
  conversation,
1378
1368
  });
1379
- setDataState({
1369
+ setClientState({
1380
1370
  ...INITIAL_STATE,
1381
1371
  data: { messages, conversation },
1382
1372
  });
1383
1373
  }
1384
1374
  else {
1385
- setDataState({
1375
+ setClientState({
1386
1376
  ...INITIAL_STATE,
1387
1377
  data: { conversation, messages: [] },
1388
1378
  });
@@ -1400,7 +1390,7 @@ function createUseAIConversation(client) {
1400
1390
  errorInfo: null,
1401
1391
  errorType: '',
1402
1392
  };
1403
- setDataState({
1393
+ setClientState({
1404
1394
  ...ERROR_STATE,
1405
1395
  data: { messages: [] },
1406
1396
  // TODO in MV bump: remove `messages`
@@ -1414,12 +1404,12 @@ function createUseAIConversation(client) {
1414
1404
  contentBlocksRef.current = undefined;
1415
1405
  if (hasStarted(initRef.current))
1416
1406
  return;
1417
- setDataState({
1407
+ setClientState({
1418
1408
  ...INITIAL_STATE,
1419
1409
  data: { messages: [], conversation: undefined },
1420
1410
  });
1421
1411
  };
1422
- }, [clientRoute, id, setDataState]);
1412
+ }, [clientRoute, id, setClientState]);
1423
1413
  // Run a separate effect that is triggered by the conversation state
1424
1414
  // so that we know we have a conversation object to set up the subscription
1425
1415
  // and also unsubscribe on cleanup
@@ -1447,7 +1437,7 @@ function createUseAIConversation(client) {
1447
1437
  // stop reason will signify end of conversation turn
1448
1438
  if (stopReason) {
1449
1439
  // remove loading state from streamed message
1450
- setDataState((prev) => {
1440
+ setClientState((prev) => {
1451
1441
  return {
1452
1442
  ...prev,
1453
1443
  data: {
@@ -1494,7 +1484,7 @@ function createUseAIConversation(client) {
1494
1484
  ];
1495
1485
  }
1496
1486
  }
1497
- setDataState((prev) => {
1487
+ setClientState((prev) => {
1498
1488
  const message = {
1499
1489
  id,
1500
1490
  conversationId,
@@ -1515,7 +1505,7 @@ function createUseAIConversation(client) {
1515
1505
  });
1516
1506
  },
1517
1507
  error: (error) => {
1518
- setDataState((prev) => {
1508
+ setClientState((prev) => {
1519
1509
  return {
1520
1510
  ...prev,
1521
1511
  ...ERROR_STATE,
@@ -1533,11 +1523,11 @@ function createUseAIConversation(client) {
1533
1523
  contentBlocksRef.current = undefined;
1534
1524
  subscription.unsubscribe();
1535
1525
  };
1536
- }, [conversation, onInitialize, onMessage, setDataState]);
1526
+ }, [conversation, onInitialize, onMessage, setClientState]);
1537
1527
  const handleSendMessage = React__namespace["default"].useCallback((input) => {
1538
1528
  const { content } = input;
1539
1529
  if (conversation) {
1540
- setDataState((prevState) => ({
1530
+ setClientState((prevState) => ({
1541
1531
  ...prevState,
1542
1532
  data: {
1543
1533
  ...prevState.data,
@@ -1570,7 +1560,7 @@ function createUseAIConversation(client) {
1570
1560
  errorInfo: null,
1571
1561
  errorType: '',
1572
1562
  };
1573
- setDataState((prev) => ({
1563
+ setClientState((prev) => ({
1574
1564
  ...prev,
1575
1565
  ...ERROR_STATE,
1576
1566
  // TODO in MV bump: remove `messages`
@@ -1579,7 +1569,7 @@ function createUseAIConversation(client) {
1579
1569
  }));
1580
1570
  }
1581
1571
  }, [conversation]);
1582
- return [dataState, handleSendMessage];
1572
+ return [clientState, handleSendMessage];
1583
1573
  };
1584
1574
  return useAIConversation;
1585
1575
  }
@@ -1,6 +1,8 @@
1
- import { DataState } from '@aws-amplify/ui-react-core';
2
1
  import { GraphQLFormattedError } from '../types';
3
- export type DataClientState<T> = Omit<DataState<T>, 'message'> & {
2
+ export interface AiClientState<T> {
3
+ data: T;
4
+ hasError: boolean;
5
+ isLoading: boolean;
4
6
  /**
5
7
  * @deprecated will be removed in a future major version. Superseded by `errors`
6
8
  * @description errors returned from the websocket connection
@@ -10,11 +12,11 @@ export type DataClientState<T> = Omit<DataState<T>, 'message'> & {
10
12
  * @description errors returned from the websocket connection
11
13
  */
12
14
  errors?: GraphQLFormattedError[];
13
- };
14
- export type DataClientResponse<T> = {
15
+ }
16
+ export interface AiClientResponse<T> {
15
17
  data: T | null;
16
18
  errors?: GraphQLFormattedError[];
17
- };
19
+ }
18
20
  export declare const INITIAL_STATE: {
19
21
  hasError: boolean;
20
22
  isLoading: boolean;
@@ -1,5 +1,5 @@
1
1
  import { Conversation, ConversationMessage, ConversationRoute, SendMessage } from '../types';
2
- import { DataClientState } from './shared';
2
+ import { AiClientState } from './shared';
3
3
  interface UseAIConversationInput {
4
4
  id?: string;
5
5
  onMessage?: (message: ConversationMessage) => void;
@@ -9,6 +9,6 @@ interface AIConversationState {
9
9
  messages: ConversationMessage[];
10
10
  conversation?: Conversation;
11
11
  }
12
- export type UseAIConversationHook<T extends string> = (routeName: T, input?: UseAIConversationInput) => [DataClientState<AIConversationState>, SendMessage];
12
+ export type UseAIConversationHook<T extends string> = (routeName: T, input?: UseAIConversationInput) => [AiClientState<AIConversationState>, SendMessage];
13
13
  export declare function createUseAIConversation<T extends Record<'conversations', Record<string, ConversationRoute>>>(client: T): UseAIConversationHook<Extract<keyof T['conversations'], string>>;
14
14
  export {};
@@ -1,14 +1,14 @@
1
1
  import type { ClientExtensions } from '@aws-amplify/data-schema/runtime';
2
2
  import { getSchema } from '../types';
3
- import { DataClientState } from './shared';
3
+ import { AiClientState } 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<DataClientState<Schema[U]['returnType']>>,
6
+ Awaited<AiClientState<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<DataClientState<Schema[Key]['returnType']>>,
11
+ Awaited<AiClientState<Schema[Key]['returnType']>>,
12
12
  (input: Schema[Key]['args']) => void
13
13
  ];
14
14
  type AIGenerationClient<T extends Record<any, any>> = Pick<ClientExtensions<T>, 'generations'>;
@@ -1 +1 @@
1
- export declare const VERSION = "1.4.0";
1
+ export declare const VERSION = "1.4.1";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aws-amplify/ui-react-ai",
3
- "version": "1.4.0",
3
+ "version": "1.4.1",
4
4
  "main": "dist/index.js",
5
5
  "module": "dist/esm/index.mjs",
6
6
  "exports": {
@@ -43,14 +43,14 @@
43
43
  },
44
44
  "peerDependencies": {
45
45
  "@aws-amplify/data-schema": "^1.19.0",
46
- "aws-amplify": "^6.9.0",
46
+ "aws-amplify": "^6.14.3",
47
47
  "react": "^16.14 || ^17 || ^18 || ^19",
48
48
  "react-dom": "^16.14 || ^17 || ^18 || ^19"
49
49
  },
50
50
  "dependencies": {
51
- "@aws-amplify/ui": "^6.10.1",
52
- "@aws-amplify/ui-react": "^6.11.0",
53
- "@aws-amplify/ui-react-core": "^3.4.1"
51
+ "@aws-amplify/ui": "^6.10.2",
52
+ "@aws-amplify/ui-react": "^6.11.1",
53
+ "@aws-amplify/ui-react-core": "^3.4.2"
54
54
  },
55
55
  "size-limit": [
56
56
  {