@lvce-editor/chat-view 1.6.0 → 1.7.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/chatViewWorkerMain.js +44 -22
- package/package.json +1 -1
|
@@ -1238,6 +1238,7 @@ const createDefaultState = () => {
|
|
|
1238
1238
|
errorCount: 0,
|
|
1239
1239
|
focus: 'composer',
|
|
1240
1240
|
focused: false,
|
|
1241
|
+
headerHeight: 50,
|
|
1241
1242
|
height: 0,
|
|
1242
1243
|
initial: true,
|
|
1243
1244
|
inputSource: 'script',
|
|
@@ -1421,6 +1422,20 @@ const delay = async ms => {
|
|
|
1421
1422
|
const getMockAiResponse = userMessage => {
|
|
1422
1423
|
return `Mock AI response: I received "${userMessage}".`;
|
|
1423
1424
|
};
|
|
1425
|
+
const getAiResponse = async (userText, nextMessageId) => {
|
|
1426
|
+
await delay(800);
|
|
1427
|
+
const assistantTime = new Date().toLocaleTimeString([], {
|
|
1428
|
+
hour: '2-digit',
|
|
1429
|
+
minute: '2-digit'
|
|
1430
|
+
});
|
|
1431
|
+
return {
|
|
1432
|
+
id: `message-${nextMessageId}`,
|
|
1433
|
+
role: 'assistant',
|
|
1434
|
+
text: getMockAiResponse(userText),
|
|
1435
|
+
time: assistantTime
|
|
1436
|
+
};
|
|
1437
|
+
};
|
|
1438
|
+
|
|
1424
1439
|
const handleSubmit = async state => {
|
|
1425
1440
|
const {
|
|
1426
1441
|
composerValue,
|
|
@@ -1483,17 +1498,7 @@ const handleSubmit = async state => {
|
|
|
1483
1498
|
set(state.uid, state, optimisticState);
|
|
1484
1499
|
// @ts-ignore
|
|
1485
1500
|
await invoke('Chat.rerender');
|
|
1486
|
-
await
|
|
1487
|
-
const assistantTime = new Date().toLocaleTimeString([], {
|
|
1488
|
-
hour: '2-digit',
|
|
1489
|
-
minute: '2-digit'
|
|
1490
|
-
});
|
|
1491
|
-
const assistantMessage = {
|
|
1492
|
-
id: `message-${optimisticState.nextMessageId}`,
|
|
1493
|
-
role: 'assistant',
|
|
1494
|
-
text: getMockAiResponse(userText),
|
|
1495
|
-
time: assistantTime
|
|
1496
|
-
};
|
|
1501
|
+
const assistantMessage = await getAiResponse(userText, optimisticState.nextMessageId);
|
|
1497
1502
|
const updatedSessions = optimisticState.sessions.map(session => {
|
|
1498
1503
|
if (session.id !== optimisticState.selectedSessionId) {
|
|
1499
1504
|
return session;
|
|
@@ -1511,8 +1516,13 @@ const handleSubmit = async state => {
|
|
|
1511
1516
|
};
|
|
1512
1517
|
|
|
1513
1518
|
const handleClickSend = async state => {
|
|
1514
|
-
const
|
|
1515
|
-
|
|
1519
|
+
const {
|
|
1520
|
+
selectedSessionId,
|
|
1521
|
+
sessions,
|
|
1522
|
+
viewMode
|
|
1523
|
+
} = state;
|
|
1524
|
+
const hasSelectedSession = sessions.some(session => session.id === selectedSessionId);
|
|
1525
|
+
const submitState = viewMode === 'list' && hasSelectedSession ? {
|
|
1516
1526
|
...state,
|
|
1517
1527
|
viewMode: 'detail'
|
|
1518
1528
|
} : state;
|
|
@@ -1533,7 +1543,10 @@ const selectSession = (state, id) => {
|
|
|
1533
1543
|
};
|
|
1534
1544
|
|
|
1535
1545
|
const startRename = (state, id) => {
|
|
1536
|
-
const
|
|
1546
|
+
const {
|
|
1547
|
+
sessions
|
|
1548
|
+
} = state;
|
|
1549
|
+
const session = sessions.find(item => item.id === id);
|
|
1537
1550
|
if (!session) {
|
|
1538
1551
|
return state;
|
|
1539
1552
|
}
|
|
@@ -1546,28 +1559,37 @@ const startRename = (state, id) => {
|
|
|
1546
1559
|
};
|
|
1547
1560
|
};
|
|
1548
1561
|
|
|
1549
|
-
const
|
|
1550
|
-
const handleClickList = async (state, eventX, eventY) => {
|
|
1562
|
+
const getListIndex = (state, eventX, eventY) => {
|
|
1551
1563
|
const {
|
|
1564
|
+
headerHeight,
|
|
1552
1565
|
height,
|
|
1553
1566
|
listItemHeight,
|
|
1554
|
-
sessions,
|
|
1555
1567
|
width,
|
|
1556
1568
|
x,
|
|
1557
1569
|
y
|
|
1558
1570
|
} = state;
|
|
1559
1571
|
if (eventX < x || eventY < y) {
|
|
1560
|
-
return
|
|
1572
|
+
return -1;
|
|
1561
1573
|
}
|
|
1562
1574
|
if (eventX >= x + width || eventY >= y + height) {
|
|
1563
|
-
return
|
|
1575
|
+
return -1;
|
|
1564
1576
|
}
|
|
1565
|
-
const listY = eventY - y -
|
|
1577
|
+
const listY = eventY - y - headerHeight;
|
|
1566
1578
|
if (listY < 0) {
|
|
1567
|
-
return
|
|
1579
|
+
return -1;
|
|
1568
1580
|
}
|
|
1569
1581
|
const itemHeight = listItemHeight > 0 ? listItemHeight : 40;
|
|
1570
|
-
|
|
1582
|
+
return Math.floor(listY / itemHeight);
|
|
1583
|
+
};
|
|
1584
|
+
|
|
1585
|
+
const handleClickList = async (state, eventX, eventY) => {
|
|
1586
|
+
const {
|
|
1587
|
+
sessions
|
|
1588
|
+
} = state;
|
|
1589
|
+
const index = getListIndex(state, eventX, eventY);
|
|
1590
|
+
if (index < 0) {
|
|
1591
|
+
return state;
|
|
1592
|
+
}
|
|
1571
1593
|
const session = sessions[index];
|
|
1572
1594
|
if (!session) {
|
|
1573
1595
|
return state;
|