@aws-amplify/ui-react-ai 1.5.0 → 1.5.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.
|
@@ -2,19 +2,19 @@ const contentFromEvents = (contentBlocks) => {
|
|
|
2
2
|
if (!contentBlocks)
|
|
3
3
|
return [];
|
|
4
4
|
return contentBlocks.map((contentBlock) => {
|
|
5
|
-
|
|
5
|
+
// Filter out sparse array holes from out-of-order direct index assignment
|
|
6
|
+
const events = contentBlock.filter(Boolean);
|
|
7
|
+
const isTextBlock = events.some((event) => event.text);
|
|
6
8
|
if (isTextBlock) {
|
|
7
9
|
return {
|
|
8
|
-
text:
|
|
9
|
-
.map((event) =>
|
|
10
|
-
return event.text;
|
|
11
|
-
})
|
|
10
|
+
text: events
|
|
11
|
+
.map((event) => event.text ?? '')
|
|
12
12
|
.join(''),
|
|
13
13
|
};
|
|
14
14
|
}
|
|
15
15
|
// tool use is never chunked
|
|
16
|
-
if (
|
|
17
|
-
return { toolUse:
|
|
16
|
+
if (events[0]?.toolUse) {
|
|
17
|
+
return { toolUse: events[0].toolUse };
|
|
18
18
|
}
|
|
19
19
|
});
|
|
20
20
|
};
|
|
@@ -174,11 +174,13 @@ function createUseAIConversation(client) {
|
|
|
174
174
|
contentBlocksRef.current[contentBlockIndex] = [event];
|
|
175
175
|
}
|
|
176
176
|
else {
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
event
|
|
180
|
-
|
|
181
|
-
|
|
177
|
+
// Direct index assignment: idempotent, handles out-of-order and duplicates
|
|
178
|
+
if (contentBlockDeltaIndex !== undefined) {
|
|
179
|
+
currentBlock[contentBlockDeltaIndex] = event;
|
|
180
|
+
}
|
|
181
|
+
else {
|
|
182
|
+
currentBlock.push(event);
|
|
183
|
+
}
|
|
182
184
|
}
|
|
183
185
|
}
|
|
184
186
|
setClientState((prev) => {
|
|
@@ -190,13 +192,20 @@ function createUseAIConversation(client) {
|
|
|
190
192
|
role: 'assistant',
|
|
191
193
|
isLoading: true,
|
|
192
194
|
};
|
|
195
|
+
// Match by message ID instead of assuming last message
|
|
196
|
+
const existingIndex = prev.data.messages.findIndex((m) => m.id === id);
|
|
197
|
+
const updatedMessages = existingIndex >= 0
|
|
198
|
+
? [
|
|
199
|
+
...prev.data.messages.slice(0, existingIndex),
|
|
200
|
+
message,
|
|
201
|
+
...prev.data.messages.slice(existingIndex + 1),
|
|
202
|
+
]
|
|
203
|
+
: [...prev.data.messages, message];
|
|
193
204
|
return {
|
|
194
205
|
...prev,
|
|
195
206
|
data: {
|
|
196
207
|
...prev.data,
|
|
197
|
-
|
|
198
|
-
// message, but maybe we should match it by message ID?
|
|
199
|
-
messages: [...prev.data.messages.slice(0, -1), message],
|
|
208
|
+
messages: updatedMessages,
|
|
200
209
|
},
|
|
201
210
|
};
|
|
202
211
|
});
|
package/dist/esm/version.mjs
CHANGED
package/dist/index.js
CHANGED
|
@@ -1230,7 +1230,7 @@ const PromptList = ({ setInput, suggestedPrompts = [], }) => {
|
|
|
1230
1230
|
})));
|
|
1231
1231
|
};
|
|
1232
1232
|
|
|
1233
|
-
const VERSION = '1.5.
|
|
1233
|
+
const VERSION = '1.5.1';
|
|
1234
1234
|
|
|
1235
1235
|
function AIConversationBase({ avatars, controls, messages, ...rest }) {
|
|
1236
1236
|
uiReactCore.useSetUserAgent({
|
|
@@ -1306,19 +1306,19 @@ const contentFromEvents = (contentBlocks) => {
|
|
|
1306
1306
|
if (!contentBlocks)
|
|
1307
1307
|
return [];
|
|
1308
1308
|
return contentBlocks.map((contentBlock) => {
|
|
1309
|
-
|
|
1309
|
+
// Filter out sparse array holes from out-of-order direct index assignment
|
|
1310
|
+
const events = contentBlock.filter(Boolean);
|
|
1311
|
+
const isTextBlock = events.some((event) => event.text);
|
|
1310
1312
|
if (isTextBlock) {
|
|
1311
1313
|
return {
|
|
1312
|
-
text:
|
|
1313
|
-
.map((event) =>
|
|
1314
|
-
return event.text;
|
|
1315
|
-
})
|
|
1314
|
+
text: events
|
|
1315
|
+
.map((event) => event.text ?? '')
|
|
1316
1316
|
.join(''),
|
|
1317
1317
|
};
|
|
1318
1318
|
}
|
|
1319
1319
|
// tool use is never chunked
|
|
1320
|
-
if (
|
|
1321
|
-
return { toolUse:
|
|
1320
|
+
if (events[0]?.toolUse) {
|
|
1321
|
+
return { toolUse: events[0].toolUse };
|
|
1322
1322
|
}
|
|
1323
1323
|
});
|
|
1324
1324
|
};
|
|
@@ -1511,11 +1511,13 @@ function createUseAIConversation(client) {
|
|
|
1511
1511
|
contentBlocksRef.current[contentBlockIndex] = [event];
|
|
1512
1512
|
}
|
|
1513
1513
|
else {
|
|
1514
|
-
|
|
1515
|
-
|
|
1516
|
-
event
|
|
1517
|
-
|
|
1518
|
-
|
|
1514
|
+
// Direct index assignment: idempotent, handles out-of-order and duplicates
|
|
1515
|
+
if (contentBlockDeltaIndex !== undefined) {
|
|
1516
|
+
currentBlock[contentBlockDeltaIndex] = event;
|
|
1517
|
+
}
|
|
1518
|
+
else {
|
|
1519
|
+
currentBlock.push(event);
|
|
1520
|
+
}
|
|
1519
1521
|
}
|
|
1520
1522
|
}
|
|
1521
1523
|
setClientState((prev) => {
|
|
@@ -1527,13 +1529,20 @@ function createUseAIConversation(client) {
|
|
|
1527
1529
|
role: 'assistant',
|
|
1528
1530
|
isLoading: true,
|
|
1529
1531
|
};
|
|
1532
|
+
// Match by message ID instead of assuming last message
|
|
1533
|
+
const existingIndex = prev.data.messages.findIndex((m) => m.id === id);
|
|
1534
|
+
const updatedMessages = existingIndex >= 0
|
|
1535
|
+
? [
|
|
1536
|
+
...prev.data.messages.slice(0, existingIndex),
|
|
1537
|
+
message,
|
|
1538
|
+
...prev.data.messages.slice(existingIndex + 1),
|
|
1539
|
+
]
|
|
1540
|
+
: [...prev.data.messages, message];
|
|
1530
1541
|
return {
|
|
1531
1542
|
...prev,
|
|
1532
1543
|
data: {
|
|
1533
1544
|
...prev.data,
|
|
1534
|
-
|
|
1535
|
-
// message, but maybe we should match it by message ID?
|
|
1536
|
-
messages: [...prev.data.messages.slice(0, -1), message],
|
|
1545
|
+
messages: updatedMessages,
|
|
1537
1546
|
},
|
|
1538
1547
|
};
|
|
1539
1548
|
});
|
package/dist/types/version.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const VERSION = "1.5.
|
|
1
|
+
export declare const VERSION = "1.5.1";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aws-amplify/ui-react-ai",
|
|
3
|
-
"version": "1.5.
|
|
3
|
+
"version": "1.5.1",
|
|
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 || ^17 || ^18 || ^19"
|
|
49
49
|
},
|
|
50
50
|
"dependencies": {
|
|
51
|
-
"@aws-amplify/ui": "^6.
|
|
52
|
-
"@aws-amplify/ui-react": "^6.
|
|
53
|
-
"@aws-amplify/ui-react-core": "^3.
|
|
51
|
+
"@aws-amplify/ui": "^6.15.2",
|
|
52
|
+
"@aws-amplify/ui-react": "^6.15.2",
|
|
53
|
+
"@aws-amplify/ui-react-core": "^3.6.2"
|
|
54
54
|
},
|
|
55
55
|
"size-limit": [
|
|
56
56
|
{
|