Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

opt.: replay #131

Merged
merged 1 commit into from
Aug 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion lib/data/store/setting.dart
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ class SettingStore extends PersistentStore {
/// Only valid on iOS and macOS
late final icloudSync =
property('icloudSync', false, updateLastModified: false);
late final onlySyncOnLaunch = property('onlySyncOnLaunch', false);

late final initHelpShown = property('initHelpShown', false);
//late final imPro = property('imPro', false);
Expand Down
15 changes: 0 additions & 15 deletions lib/view/page/backup/view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ final class BackupPage extends StatelessWidget {
children: [
_buildTip(),
//_buildTitle(l10n.settings),
_buildSettings(context),
_buildTitle('App'),
if (isMacOS || isIOS) _buildIcloud(context),
if (!isWeb) _buildWebdav(context),
Expand Down Expand Up @@ -84,18 +83,4 @@ final class BackupPage extends StatelessWidget {
),
);
}

Widget _buildSettings(BuildContext context) {
return CardX(
child: Column(
children: [
ListTile(
leading: const Icon(MingCute.refresh_3_line),
title: Text(l10n.onlySyncOnLaunch),
trailing: StoreSwitch(prop: Stores.setting.onlySyncOnLaunch),
),
],
),
);
}
}
70 changes: 47 additions & 23 deletions lib/view/page/home/req.dart
Original file line number Diff line number Diff line change
Expand Up @@ -520,9 +520,6 @@ void _onReplay({

// If is receiving the reply, ignore this action
if (_loadingChatIds.contains(chatId)) {
final msg = 'Replay Chat($chatId) is receiving reply';
Loggers.app.warning(msg);
context.showSnackBar(msg);
return;
}

Expand All @@ -534,30 +531,57 @@ void _onReplay({
return;
}

final itemIdx = chatHistory.items.indexOf(item);
if (itemIdx == -1) {
final msg = 'Replay Chat($chatId) item($item) not found';
Loggers.app.warning(msg);
context.showSnackBar(msg);
return;
}

// tool
if (itemIdx + 1 < chatHistory.items.length) {
final item = chatHistory.items.elementAt(itemIdx + 1);
if (item.role.isAssist || item.role.isTool) {
chatHistory.items.removeAt(itemIdx + 1);
// final itemIdx = chatHistory.items.indexOf(item);
// if (itemIdx == -1) {
// final msg = 'Replay Chat($chatId) item($item) not found';
// Loggers.app.warning(msg);
// context.showSnackBar(msg);
// return;
// }

// // tool
// if (itemIdx + 1 < chatHistory.items.length) {
// final item = chatHistory.items.elementAt(itemIdx + 1);
// if (item.role.isAssist || item.role.isTool) {
// chatHistory.items.removeAt(itemIdx + 1);
// }
// }
// // assist
// if (itemIdx + 1 < chatHistory.items.length) {
// final item = chatHistory.items.elementAt(itemIdx + 1);
// if (item.role.isAssist || item.role.isTool) {
// chatHistory.items.removeAt(itemIdx + 1);
// }
// }

// chatHistory.items.removeAt(itemIdx);

// Find the item, then delete all items between the item and next user msg
var replayMsgIdx = -1;
var nextUserMsgIdx = -1;
for (var idx = 0; idx < chatHistory.items.length; idx++) {
final i = chatHistory.items[idx];
if (i.id == item.id && i.role == item.role) {
replayMsgIdx = idx;
continue;
}
}
// assist
if (itemIdx + 1 < chatHistory.items.length) {
final item = chatHistory.items.elementAt(itemIdx + 1);
if (item.role.isAssist || item.role.isTool) {
chatHistory.items.removeAt(itemIdx + 1);
if (replayMsgIdx == -1) {
continue;
}
if (replayMsgIdx != -1 && i.role.isUser) {
nextUserMsgIdx = idx;
break;
}
}

chatHistory.items.removeAt(itemIdx);
if (replayMsgIdx != -1 && nextUserMsgIdx != -1) {
chatHistory.items.removeRange(replayMsgIdx, nextUserMsgIdx);
} else {
final msg = 'Replay Chat($chatId) item($item) not found';
Loggers.app.warning(msg);
context.showSnackBar('${l10n.failed}: $msg');
return;
}

final text =
item.content.firstWhereOrNull((e) => e.type == ChatContentType.text)?.raw;
Expand Down
Loading