feat: show short paths and generated images in the chat
A file tool's row keeps only the part of the path under the session's directory (lib/screens/chat_screen.dart instead of the whole absolute path), as the first-party client does, so a phone still shows the file name; the diff card's file headings drop the same prefix. A finished openchamber_image call is lifted out of the folded run and drawn as the picture it saved, in place, as ShownToolCard does through GeneratedImages: tap opens the full-screen preview, and the card and preview share an in-memory cache of the bytes. 0.4.13 (413).
This commit is contained in:
1 parent
5c0ea6f6f4
commit
809e0a747a
7 files changed
+353
-25
No files matched your search
@@ -1,6 +1,8 @@
|
||||
// OpenChamber API models, ported from the Go client's protocol knowledge.
|
||||
library;
|
||||
|
||||
import 'dart:convert';
|
||||
|
||||
class ModelRef {
|
||||
final String id;
|
||||
final String providerId;
|
||||
@@ -255,6 +257,19 @@ String pathLeaf(String path) {
|
||||
String slashPath(String path) =>
|
||||
path.replaceAll('\\', '/').replaceAll(RegExp(r'/+$'), '');
|
||||
|
||||
/// A file inside [directory] shown without it: the tool row says
|
||||
/// `lib/screens/chat_screen.dart`, as the first-party client does, so a phone
|
||||
/// still sees the part of the path that matters. Paths elsewhere stay whole.
|
||||
String relativePath(String path, String directory) {
|
||||
final file = path.trim();
|
||||
final dir = slashPath(directory.trim());
|
||||
if (file.isEmpty || dir.isEmpty) return file;
|
||||
final normalized = slashPath(file);
|
||||
if (normalized == dir) return '.';
|
||||
if (normalized.startsWith('$dir/')) return normalized.substring(dir.length + 1);
|
||||
return file;
|
||||
}
|
||||
|
||||
/// Whether [directory] is [root] or inside it. Separators are unified and a
|
||||
/// Windows drive path compares case-insensitively, as [samePath] does.
|
||||
bool isUnderDirectory(String directory, String root) {
|
||||
@@ -1034,3 +1049,41 @@ String _jsonString(Object? o) {
|
||||
if (o is String) return o;
|
||||
return o.toString();
|
||||
}
|
||||
|
||||
/// The images an `openchamber_image` call saved. The first-party client lifts
|
||||
/// such a call out of the folded run and shows the pictures in the chat; this
|
||||
/// reads the call's result envelope (`{ok, action: image.generate, data:
|
||||
/// {images: [{path}]}}`) to know which files those are.
|
||||
List<String> generatedImagePaths(ContentPart part) {
|
||||
const empty = <String>[];
|
||||
if (part.type != 'tool' || part.name != 'openchamber_image') return empty;
|
||||
final state = part.state;
|
||||
if (state == null || state.status != 'completed') return empty;
|
||||
final text = state.content
|
||||
.where((c) => c.type == 'text')
|
||||
.map((c) => c.text)
|
||||
.join()
|
||||
.trim();
|
||||
if (text.isEmpty) return empty;
|
||||
Object? decoded;
|
||||
try {
|
||||
decoded = jsonDecode(text);
|
||||
} catch (_) {
|
||||
return empty;
|
||||
}
|
||||
if (decoded is! Map) return empty;
|
||||
if (decoded['ok'] != true || decoded['action'] != 'image.generate') {
|
||||
return empty;
|
||||
}
|
||||
final data = decoded['data'];
|
||||
if (data is! Map) return empty;
|
||||
final images = data['images'];
|
||||
if (images is! List) return empty;
|
||||
final out = <String>[];
|
||||
for (final image in images) {
|
||||
if (image is! Map) continue;
|
||||
final path = image['path'];
|
||||
if (path is String && path.trim().isNotEmpty) out.add(path.trim());
|
||||
}
|
||||
return out;
|
||||
}
|
||||
Reference in new issue
Block a user