feat: write the UI in English, select only conversation content
- source strings are English again; Chinese comes from lib/l10n/zh.dart through tr()/trArgs() and AppText, and a language without a table (Spanish, ...) reads English instead of Chinese - server and user data (titles, messages, file names, notes, task names) is drawn with plain Text, so it is never looked up in the table - SelectionArea moved from the whole message list to the messages, the answer text, an opened tool call's details and the turn footer; status lines and folded tool rows no longer start a selection - a message the transcript does not know (its start event was lost while the stream was down) fetches the tail once, so a turn continued from another client comes in with its prompt - bump to 0.5.3
This commit is contained in:
1 parent
7b5bccf28f
commit
511c3b006b
43 files changed
+1620
-1791
No files matched your search
+39
-27
@@ -175,7 +175,7 @@ class AppState extends ChangeNotifier {
|
||||
/// The name of the connected server, for the sidebar footer.
|
||||
String get connectionName {
|
||||
final c = conn;
|
||||
if (c == null) return tr('未连接');
|
||||
if (c == null) return tr('Not connected');
|
||||
final label = c.label.trim();
|
||||
if (label.isNotEmpty) return label;
|
||||
final host = Uri.tryParse(c.url)?.host ?? '';
|
||||
@@ -254,7 +254,7 @@ class AppState extends ChangeNotifier {
|
||||
} catch (e) {
|
||||
if (client == cl) {
|
||||
followUpBehavior = before;
|
||||
_lastError = trArgs('保存失败:{0}', [e]);
|
||||
_lastError = trArgs('Couldn\'t save: {0}', [e]);
|
||||
notifyListeners();
|
||||
}
|
||||
return false;
|
||||
@@ -301,7 +301,7 @@ class AppState extends ChangeNotifier {
|
||||
final payload = parsePairingLink(link);
|
||||
if (payload == null) {
|
||||
debugPrint('pair: invalid link (${link.length} chars)');
|
||||
_lastError = tr('配对链接无效或已过期');
|
||||
_lastError = tr('Pairing link is invalid or expired');
|
||||
notifyListeners();
|
||||
return false;
|
||||
}
|
||||
@@ -338,7 +338,7 @@ class AppState extends ChangeNotifier {
|
||||
? const Duration(seconds: 30)
|
||||
: const Duration(seconds: 15));
|
||||
if (redeemed.token.isEmpty) {
|
||||
throw ApiError(401, tr('服务器没有返回设备令牌'));
|
||||
throw ApiError(401, tr('Server did not return a device token'));
|
||||
}
|
||||
final connection = _pairingConnection(candidate, payload, redeemed.response);
|
||||
await storage.saveToken(connection.id, redeemed.token);
|
||||
@@ -359,7 +359,7 @@ class AppState extends ChangeNotifier {
|
||||
}
|
||||
}
|
||||
busy = false;
|
||||
final message = friendlyConnectError(failure ?? tr('配对失败'));
|
||||
final message = friendlyConnectError(failure ?? tr('Pairing failed'));
|
||||
debugPrint('pair: failed: $message');
|
||||
error = message;
|
||||
_lastError = message;
|
||||
@@ -390,7 +390,7 @@ class AppState extends ChangeNotifier {
|
||||
if (candidate.isRelay) {
|
||||
return Connection(
|
||||
id: existing?.id ?? Storage.newId(),
|
||||
label: label.isNotEmpty ? label : (existing?.label ?? tr('Relay 服务器')),
|
||||
label: label.isNotEmpty ? label : (existing?.label ?? tr('Relay server')),
|
||||
url: 'relay://${candidate.serverId}',
|
||||
relayUrl: candidate.relayUrl,
|
||||
serverId: candidate.serverId,
|
||||
@@ -419,7 +419,7 @@ class AppState extends ChangeNotifier {
|
||||
if (c.isRelay) {
|
||||
// A relay connection is created by pairing; a missing token means it
|
||||
// was never stored or was revoked.
|
||||
throw ApiError(401, tr('配对已失效,请重新配对'));
|
||||
throw ApiError(401, tr('Pairing expired, please pair again'));
|
||||
}
|
||||
// No saved token: a passwordless server needs none.
|
||||
try {
|
||||
@@ -429,13 +429,13 @@ class AppState extends ChangeNotifier {
|
||||
}
|
||||
} on ApiError {
|
||||
if (password.isEmpty) {
|
||||
throw ApiError(401, tr('需要密码或已保存的凭据'));
|
||||
throw ApiError(401, tr('Password or saved credentials required'));
|
||||
}
|
||||
}
|
||||
if (token == null && password.isNotEmpty) {
|
||||
final res = await cl.login(password, await storage.installId());
|
||||
token = res['clientToken'] as String? ?? '';
|
||||
if (token.isEmpty) throw ApiError(401, tr('登录成功但没有返回令牌'));
|
||||
if (token.isEmpty) throw ApiError(401, tr('Signed in but no token was returned'));
|
||||
await storage.saveToken(c.id, token);
|
||||
}
|
||||
}
|
||||
@@ -458,25 +458,25 @@ class AppState extends ChangeNotifier {
|
||||
if (e is ApiError) {
|
||||
if (e.status == 401 &&
|
||||
e.message.toLowerCase().contains('invalid credentials')) {
|
||||
return tr('密码错误,请重试');
|
||||
return tr('Wrong password, try again');
|
||||
}
|
||||
return e.message;
|
||||
}
|
||||
if (e is ArgumentError) return e.message?.toString() ?? e.toString();
|
||||
if (e is TimeoutException) return tr('连接超时:检查服务器与代理地址');
|
||||
if (e is TimeoutException) return tr('Connection timed out: check the server and proxy address');
|
||||
final s = e.toString();
|
||||
if (e is SocketException) {
|
||||
if (s.contains('Connection refused')) {
|
||||
return tr('连接被拒绝:服务器或代理未启动,或端口不对');
|
||||
return tr('Connection refused: server or proxy not running, or wrong port');
|
||||
}
|
||||
if (s.contains('Failed host lookup') || s.contains('nodename nor servname')) {
|
||||
return tr('无法解析地址:检查服务器或代理主机名');
|
||||
return tr('Could not resolve address: check the server or proxy hostname');
|
||||
}
|
||||
if (s.contains('Network is unreachable')) return tr('网络不可达');
|
||||
if (s.contains('Network is unreachable')) return tr('Network unreachable');
|
||||
if (s.contains('Connection closed') || s.contains('reset by peer')) {
|
||||
return tr('连接被断开:检查代理是否可用');
|
||||
return tr('Connection closed: check whether the proxy works');
|
||||
}
|
||||
return trArgs('网络错误:{0}', [s]);
|
||||
return trArgs('Network error: {0}', [s]);
|
||||
}
|
||||
return s;
|
||||
}
|
||||
@@ -706,7 +706,7 @@ class AppState extends ChangeNotifier {
|
||||
final local = [
|
||||
SlashItem(
|
||||
name: 'compact',
|
||||
description: tr('使用 AI 压缩会话历史以减少上下文大小'),
|
||||
description: tr('Use AI to compact the session history and reduce context size'),
|
||||
action: 'compact',
|
||||
),
|
||||
];
|
||||
@@ -741,7 +741,7 @@ class AppState extends ChangeNotifier {
|
||||
}
|
||||
|
||||
String projectLabelFor(String directory) {
|
||||
if (directory == chatTarget || isChatDirectory(directory)) return tr('聊天');
|
||||
if (directory == chatTarget || isChatDirectory(directory)) return tr('Chat');
|
||||
if (directory.isEmpty) return '';
|
||||
for (final project in projects) {
|
||||
if (samePath(project.canonical, directory)) return project.label;
|
||||
@@ -784,7 +784,7 @@ class AppState extends ChangeNotifier {
|
||||
await openChat(session);
|
||||
return true;
|
||||
} catch (e) {
|
||||
_lastError = trArgs('无法打开子代理会话:{0}', [e]);
|
||||
_lastError = trArgs('Could not open the subagent session: {0}', [e]);
|
||||
notifyListeners();
|
||||
return false;
|
||||
}
|
||||
@@ -827,11 +827,11 @@ class AppState extends ChangeNotifier {
|
||||
/// project scope.
|
||||
Future<String> createChatDirectory() async {
|
||||
final cl = client;
|
||||
if (cl == null) throw StateError(tr('未连接服务器'));
|
||||
if (cl == null) throw StateError(tr('Not connected to a server'));
|
||||
if (chatsRoot == null || chatsRoot!.isEmpty) await refreshFsHome();
|
||||
final root = chatsRoot;
|
||||
if (root == null || root.isEmpty) {
|
||||
throw StateError(tr('服务器没有提供聊天目录'));
|
||||
throw StateError(tr('Server did not provide a chat directory'));
|
||||
}
|
||||
final now = DateTime.now();
|
||||
final date = '${now.year.toString().padLeft(4, '0')}-'
|
||||
@@ -1009,7 +1009,7 @@ class AppState extends ChangeNotifier {
|
||||
} catch (e) {
|
||||
sendingDraft = false;
|
||||
current.error = trArgs(
|
||||
'无法创建聊天目录:{0}', [e is ApiError ? e.message : e]);
|
||||
'Could not create the chat directory: {0}', [e is ApiError ? e.message : e]);
|
||||
notifyListeners();
|
||||
return;
|
||||
}
|
||||
@@ -1119,7 +1119,7 @@ class AppState extends ChangeNotifier {
|
||||
// Anything arriving means the stream is back (the server greets
|
||||
// every connection with `server.connected`), so the "reconnecting"
|
||||
// banner has done its job.
|
||||
if (error == tr('连接中断,正在重连…')) error = null;
|
||||
if (error == tr('Connection lost, reconnecting…')) error = null;
|
||||
if (catchUp) {
|
||||
catchUp = false;
|
||||
_resyncActivity();
|
||||
@@ -1137,7 +1137,7 @@ class AppState extends ChangeNotifier {
|
||||
await done.future;
|
||||
if (client != cl || gen != _streamGen) return;
|
||||
afterDrop = true;
|
||||
error = tr('连接中断,正在重连…');
|
||||
error = tr('Connection lost, reconnecting…');
|
||||
notifyListeners();
|
||||
await Future.delayed(const Duration(seconds: 2));
|
||||
}
|
||||
@@ -1486,6 +1486,7 @@ class ChatState extends ChangeNotifier {
|
||||
try {
|
||||
final page = await app.client!.listMessages(id, directory: dir);
|
||||
_setMessages(page.data);
|
||||
_recovered.clear();
|
||||
// A desc page's `next` cursor points at the older side. The server also
|
||||
// hands out a cursor for a page that already holds everything, so a
|
||||
// short page means there is nothing older.
|
||||
@@ -1789,7 +1790,7 @@ class ChatState extends ChangeNotifier {
|
||||
type: 'user',
|
||||
text: t,
|
||||
created: DateTime.now().millisecondsSinceEpoch,
|
||||
files: files?.map((f) => FileAttachment(f['name'] ?? tr('附件'), '')).toList() ?? const [],
|
||||
files: files?.map((f) => FileAttachment(f['name'] ?? tr('Attachment'), '')).toList() ?? const [],
|
||||
));
|
||||
_sortMsgs();
|
||||
notifyListeners();
|
||||
@@ -1823,7 +1824,7 @@ class ChatState extends ChangeNotifier {
|
||||
type: 'user',
|
||||
text: t,
|
||||
created: DateTime.now().millisecondsSinceEpoch,
|
||||
files: files?.map((f) => FileAttachment(f['name'] ?? tr('附件'), '')).toList() ?? const [],
|
||||
files: files?.map((f) => FileAttachment(f['name'] ?? tr('Attachment'), '')).toList() ?? const [],
|
||||
));
|
||||
_sortMsgs();
|
||||
notifyListeners();
|
||||
@@ -1858,7 +1859,7 @@ class ChatState extends ChangeNotifier {
|
||||
delivery: delivery,
|
||||
created: DateTime.now().millisecondsSinceEpoch,
|
||||
files: files
|
||||
?.map((f) => FileAttachment(f['name'] ?? tr('附件'), ''))
|
||||
?.map((f) => FileAttachment(f['name'] ?? tr('Attachment'), ''))
|
||||
.toList() ??
|
||||
const [],
|
||||
);
|
||||
@@ -1995,8 +1996,19 @@ class ChatState extends ChangeNotifier {
|
||||
|
||||
// ------------------------------------------------------------ events
|
||||
|
||||
/// Assistant messages whose turn we already fetched once after seeing an
|
||||
/// event for a message the transcript did not have yet.
|
||||
final Set<String> _recovered = {};
|
||||
|
||||
void handleEvent(String type, Map<String, dynamic> data, int created) {
|
||||
final mid = data['assistantMessageID'] as String?;
|
||||
if (mid != null && !byId.containsKey(mid) && _recovered.add(mid)) {
|
||||
// The turn began while the event stream was down: its start event is
|
||||
// gone, so neither the user prompt nor the assistant message is in the
|
||||
// transcript. The delta events alone would stitch an answer without
|
||||
// them; take the tail from the server once instead.
|
||||
reloadTail();
|
||||
}
|
||||
if (mid != null) {
|
||||
_ensureAssistant(mid, created);
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user