fix: keep loaded tool output when the tail page only has its shell
List responses ask the server to elide large tool output (`x-openchamber-part-shells: v1`): the part comes back as an empty text plus an `openchamberContentShell` marker, and the full text is fetched when a step is expanded. Every tail refresh (a turn starting, the app returning) then replaced the loaded message with that shell again, so an expanded step fell back to "无输出" — the more the session was used, the more it looked like shell steps never had output. reloadTail now keeps an already-loaded tool part when the server's copy of that part is a shell (matched by position and call id), and the pending state reads "输出较大,正在载入…" instead of claiming there was no output. Version 0.3.7 (code 307).
This commit is contained in:
1 parent
6c00e5e026
commit
fbadf6f858
5 files changed
+68
-4
No files matched your search
@@ -770,6 +770,10 @@ class _ChatScreenState extends State<ChatScreen> {
|
||||
final shell = _isShell(p);
|
||||
final command = shell ? '${input['command'] ?? ''}'.trim() : '';
|
||||
final output = toolOutput(p);
|
||||
// A big output arrives as an empty shell until the message is fetched;
|
||||
// that is not the same as a command that printed nothing.
|
||||
final shelled = shell &&
|
||||
(p.state?.metadata?.containsKey('openchamberContentShell') ?? false);
|
||||
const mono = TextStyle(fontSize: 12, height: 1.45, fontFamily: 'monospace');
|
||||
return Padding(
|
||||
padding: const EdgeInsets.fromLTRB(10, 2, 10, 8),
|
||||
@@ -796,7 +800,11 @@ class _ChatScreenState extends State<ChatScreen> {
|
||||
),
|
||||
if (extras.isNotEmpty) const SizedBox(height: 4),
|
||||
SelectableText(
|
||||
output.isEmpty ? (shell ? '无输出' : '无内容') : output,
|
||||
output.isNotEmpty
|
||||
? output
|
||||
: shelled
|
||||
? '输出较大,正在载入…'
|
||||
: (shell ? '无输出' : '无内容'),
|
||||
style: mono.copyWith(
|
||||
color: p.state?.error != null
|
||||
? theme.colorScheme.error
|
||||
|
||||
+45
-1
@@ -602,6 +602,46 @@ class ChatState extends ChangeNotifier {
|
||||
return null;
|
||||
}
|
||||
|
||||
/// A page keeps large tool outputs out (`x-openchamber-part-shells`); the
|
||||
/// message itself still carries them. Such a part reads as an empty text.
|
||||
static bool _shelledPart(ContentPart p) =>
|
||||
p.type == 'tool' &&
|
||||
(p.state?.metadata?.containsKey('openchamberContentShell') ?? false);
|
||||
|
||||
/// The server's copy of a message, except that a tool output already loaded
|
||||
/// in full is kept: taking the shell back would turn the step's output into
|
||||
/// "无输出" again on the next tail refresh.
|
||||
static Message _keepLoadedOutput(Message local, Message server) {
|
||||
if (!server.content.any(_shelledPart)) return server;
|
||||
final parts = <ContentPart>[];
|
||||
for (var i = 0; i < server.content.length; i++) {
|
||||
final s = server.content[i];
|
||||
final l = i < local.content.length ? local.content[i] : null;
|
||||
final loaded = l != null &&
|
||||
l.type == 'tool' &&
|
||||
l.id == s.id &&
|
||||
(l.state?.content.any((c) => c.text.isNotEmpty) ?? false);
|
||||
parts.add(_shelledPart(s) && loaded ? l : s);
|
||||
}
|
||||
return Message(
|
||||
id: server.id,
|
||||
type: server.type,
|
||||
created: server.created,
|
||||
completed: server.completed,
|
||||
agent: server.agent,
|
||||
model: server.model,
|
||||
content: parts,
|
||||
text: server.text,
|
||||
files: server.files,
|
||||
finish: server.finish,
|
||||
cost: server.cost,
|
||||
tokens: server.tokens,
|
||||
error: server.error,
|
||||
status: server.status,
|
||||
reason: server.reason,
|
||||
);
|
||||
}
|
||||
|
||||
/// Refreshes the newest page without dropping the older pages that were
|
||||
/// already loaded; the server's copy wins for messages it returns.
|
||||
Future<void> reloadTail() async {
|
||||
@@ -612,7 +652,11 @@ class ChatState extends ChangeNotifier {
|
||||
} else {
|
||||
final fresh = {for (final m in page.data) m.id: m};
|
||||
final merged = <Message>[
|
||||
for (final m in msgs) fresh.remove(m.id) ?? m,
|
||||
for (final m in msgs)
|
||||
switch (fresh.remove(m.id)) {
|
||||
final Message s => _keepLoadedOutput(m, s),
|
||||
null => m,
|
||||
},
|
||||
for (final m in page.data)
|
||||
if (fresh.containsKey(m.id)) m,
|
||||
];
|
||||
|
||||
Reference in new issue
Block a user