feat: port the client to Flutter (0.3.0)
Replace the MyGo/Go app with a Flutter client that keeps the feature set: - servers: saved servers, passwordless and password login, HTTP/SOCKS5 proxy via dart:io, self-signed certificates and pinning, tokens in flutter_secure_storage (Keystore) - sessions: list with live events, search, new/rename/archive/delete, instance sheet - chat: streaming Markdown (flutter_markdown), reasoning and tool rows, image previews, context usage ring and sheet, model/agent switching, fork/revert, attachments (file_picker), permissions - Android 7.0 (API 24)+, plain http:// works in release (Dart dials sockets directly) - build: China mirrors for Gradle/NDK, Aliyun Maven repositories, and the Gradle distribution pre-seeded; release signed with the test keystore Read-aloud is dropped as requested. Version 0.3.0.
This commit is contained in:
1 parent
24a311f234
commit
aee560172c
2616 files changed
+5810
-672083
No files matched your search
@@ -0,0 +1,287 @@
|
||||
// OpenChamber API models, ported from the Go client's protocol knowledge.
|
||||
library;
|
||||
|
||||
class ModelRef {
|
||||
final String id;
|
||||
final String providerId;
|
||||
final String? variant;
|
||||
ModelRef(this.id, this.providerId, [this.variant]);
|
||||
factory ModelRef.fromJson(Map<String, dynamic> j) =>
|
||||
ModelRef(j['id'] as String, j['providerID'] as String, j['variant'] as String?);
|
||||
Map<String, dynamic> toJson() =>
|
||||
{'id': id, 'providerID': providerId, if (variant != null) 'variant': variant};
|
||||
}
|
||||
|
||||
class TokenUsage {
|
||||
final int? total;
|
||||
final int input;
|
||||
final int output;
|
||||
final int reasoning;
|
||||
final int cacheRead;
|
||||
final int cacheWrite;
|
||||
TokenUsage({
|
||||
this.total,
|
||||
this.input = 0,
|
||||
this.output = 0,
|
||||
this.reasoning = 0,
|
||||
this.cacheRead = 0,
|
||||
this.cacheWrite = 0,
|
||||
});
|
||||
factory TokenUsage.fromJson(Map<String, dynamic> j) {
|
||||
final cache = j['cache'] as Map<String, dynamic>? ?? {};
|
||||
return TokenUsage(
|
||||
total: j['total'] as int?,
|
||||
input: (j['input'] as num?)?.toInt() ?? 0,
|
||||
output: (j['output'] as num?)?.toInt() ?? 0,
|
||||
reasoning: (j['reasoning'] as num?)?.toInt() ?? 0,
|
||||
cacheRead: (cache['read'] as num?)?.toInt() ?? 0,
|
||||
cacheWrite: (cache['write'] as num?)?.toInt() ?? 0,
|
||||
);
|
||||
}
|
||||
int get used =>
|
||||
(total ?? 0) > 0 ? total! : input + output + reasoning + cacheRead + cacheWrite;
|
||||
}
|
||||
|
||||
class Location {
|
||||
final String directory;
|
||||
final String? projectId;
|
||||
Location(this.directory, [this.projectId]);
|
||||
factory Location.fromJson(Map<String, dynamic> j) =>
|
||||
Location(j['directory'] as String? ?? '', j['projectId'] as String?);
|
||||
}
|
||||
|
||||
class Session {
|
||||
final String id;
|
||||
final String title;
|
||||
final String agent;
|
||||
final ModelRef? model;
|
||||
final Location? location;
|
||||
final int created;
|
||||
final int updated;
|
||||
Session({
|
||||
required this.id,
|
||||
required this.title,
|
||||
this.agent = '',
|
||||
this.model,
|
||||
this.location,
|
||||
this.created = 0,
|
||||
this.updated = 0,
|
||||
});
|
||||
factory Session.fromJson(Map<String, dynamic> j) {
|
||||
final t = j['time'] as Map<String, dynamic>? ?? {};
|
||||
return Session(
|
||||
id: j['id'] as String,
|
||||
title: j['title'] as String? ?? '',
|
||||
agent: j['agent'] as String? ?? '',
|
||||
model: j['model'] == null ? null : ModelRef.fromJson(j['model'] as Map<String, dynamic>),
|
||||
location: j['location'] == null ? null : Location.fromJson(j['location'] as Map<String, dynamic>),
|
||||
created: (t['created'] as num?)?.toInt() ?? 0,
|
||||
updated: (t['updated'] as num?)?.toInt() ?? 0,
|
||||
);
|
||||
}
|
||||
String get directory => location?.directory ?? '';
|
||||
}
|
||||
|
||||
class ContentPart {
|
||||
final String type;
|
||||
final String text;
|
||||
final String? id;
|
||||
final String? name;
|
||||
final ToolState? state;
|
||||
final String? mime;
|
||||
final String? url;
|
||||
final String? uri;
|
||||
final String? filename;
|
||||
ContentPart({
|
||||
this.type = '',
|
||||
this.text = '',
|
||||
this.id,
|
||||
this.name,
|
||||
this.state,
|
||||
this.mime,
|
||||
this.url,
|
||||
this.uri,
|
||||
this.filename,
|
||||
});
|
||||
factory ContentPart.fromJson(Map<String, dynamic> j) => ContentPart(
|
||||
type: j['type'] as String? ?? '',
|
||||
text: j['text'] as String? ?? '',
|
||||
id: j['id'] as String?,
|
||||
name: j['name'] as String?,
|
||||
state: j['state'] == null ? null : ToolState.fromJson(j['state'] as Map<String, dynamic>),
|
||||
mime: j['mime'] as String?,
|
||||
url: j['url'] as String?,
|
||||
uri: j['uri'] as String?,
|
||||
filename: j['filename'] as String?,
|
||||
);
|
||||
Map<String, dynamic> toJson() => {
|
||||
if (type.isNotEmpty) 'type': type,
|
||||
if (text.isNotEmpty) 'text': text,
|
||||
if (state != null) 'state': state!.toJson(),
|
||||
};
|
||||
}
|
||||
|
||||
class ToolState {
|
||||
String status;
|
||||
Map<String, dynamic> input;
|
||||
List<ContentPart> content;
|
||||
List<ContentPart> attachments;
|
||||
Map<String, dynamic>? metadata;
|
||||
String? error;
|
||||
ToolState({
|
||||
this.status = '',
|
||||
Map<String, dynamic>? input,
|
||||
List<ContentPart>? content,
|
||||
List<ContentPart>? attachments,
|
||||
this.metadata,
|
||||
this.error,
|
||||
}) : input = input ?? {},
|
||||
content = content ?? [],
|
||||
attachments = attachments ?? [];
|
||||
factory ToolState.fromJson(Map<String, dynamic> j) => ToolState(
|
||||
status: j['status'] as String? ?? '',
|
||||
input: j['input'] as Map<String, dynamic>? ?? {},
|
||||
content: (j['content'] as List?)
|
||||
?.map((e) => ContentPart.fromJson(e as Map<String, dynamic>))
|
||||
.toList(),
|
||||
attachments: (j['attachments'] as List?)
|
||||
?.map((e) => ContentPart.fromJson(e as Map<String, dynamic>))
|
||||
.toList(),
|
||||
metadata: j['metadata'] as Map<String, dynamic>?,
|
||||
error: j['error'] == null ? null : _jsonString(j['error']),
|
||||
);
|
||||
Map<String, dynamic> toJson() => {
|
||||
'status': status,
|
||||
if (input.isNotEmpty) 'input': input,
|
||||
if (content.isNotEmpty) 'content': content.map((e) => e.toJson()).toList(),
|
||||
if (metadata != null) 'metadata': metadata,
|
||||
};
|
||||
}
|
||||
|
||||
class Message {
|
||||
final String id;
|
||||
final String type;
|
||||
final int created;
|
||||
final int completed;
|
||||
final String agent;
|
||||
final ModelRef? model;
|
||||
final List<ContentPart> content;
|
||||
final String text;
|
||||
final List<FileAttachment> files;
|
||||
final String finish;
|
||||
final double cost;
|
||||
final TokenUsage? tokens;
|
||||
Message({
|
||||
required this.id,
|
||||
required this.type,
|
||||
this.created = 0,
|
||||
this.completed = 0,
|
||||
this.agent = '',
|
||||
this.model,
|
||||
this.content = const [],
|
||||
this.text = '',
|
||||
this.files = const [],
|
||||
this.finish = '',
|
||||
this.cost = 0,
|
||||
this.tokens,
|
||||
});
|
||||
factory Message.fromJson(Map<String, dynamic> j) {
|
||||
final t = j['time'] as Map<String, dynamic>? ?? {};
|
||||
return Message(
|
||||
id: j['id'] as String,
|
||||
type: j['type'] as String? ?? '',
|
||||
created: (t['created'] as num?)?.toInt() ?? 0,
|
||||
completed: (t['completed'] as num?)?.toInt() ?? 0,
|
||||
agent: j['agent'] as String? ?? '',
|
||||
model: j['model'] == null ? null : ModelRef.fromJson(j['model'] as Map<String, dynamic>),
|
||||
content: (j['content'] as List?)
|
||||
?.map((e) => ContentPart.fromJson(e as Map<String, dynamic>))
|
||||
.toList() ??
|
||||
const [],
|
||||
text: j['text'] as String? ?? '',
|
||||
files: (j['files'] as List?)
|
||||
?.map((e) => FileAttachment.fromJson(e as Map<String, dynamic>))
|
||||
.toList() ??
|
||||
const [],
|
||||
finish: j['finish'] as String? ?? '',
|
||||
cost: (j['cost'] as num?)?.toDouble() ?? 0,
|
||||
tokens: j['tokens'] == null ? null : TokenUsage.fromJson(j['tokens'] as Map<String, dynamic>),
|
||||
);
|
||||
}
|
||||
String get partText {
|
||||
final buf = StringBuffer();
|
||||
for (final p in content) {
|
||||
if (p.type == 'text' && p.text.isNotEmpty) buf.write(p.text);
|
||||
}
|
||||
return buf.toString();
|
||||
}
|
||||
}
|
||||
|
||||
class FileAttachment {
|
||||
final String name;
|
||||
final String mime;
|
||||
FileAttachment(this.name, this.mime);
|
||||
factory FileAttachment.fromJson(Map<String, dynamic> j) =>
|
||||
FileAttachment(j['name'] as String? ?? '', j['mime'] as String? ?? '');
|
||||
}
|
||||
|
||||
class Page<T> {
|
||||
final List<T> data;
|
||||
final String? next;
|
||||
final String? previous;
|
||||
Page(this.data, {this.next, this.previous});
|
||||
}
|
||||
|
||||
class AuthStatus {
|
||||
final bool authenticated;
|
||||
final bool disabled;
|
||||
final bool locked;
|
||||
AuthStatus(this.authenticated, this.disabled, this.locked);
|
||||
}
|
||||
|
||||
class ModelInfo {
|
||||
final String id;
|
||||
final String providerId;
|
||||
final String name;
|
||||
final int context;
|
||||
final int output;
|
||||
ModelInfo(this.id, this.providerId, this.name, this.context, this.output);
|
||||
factory ModelInfo.fromJson(Map<String, dynamic> j) {
|
||||
final lim = j['limit'] as Map<String, dynamic>? ?? {};
|
||||
return ModelInfo(
|
||||
j['id'] as String,
|
||||
j['providerID'] as String? ?? '',
|
||||
j['name'] as String? ?? (j['id'] as String? ?? ''),
|
||||
(lim['context'] as num?)?.toInt() ?? 0,
|
||||
(lim['output'] as num?)?.toInt() ?? 0,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class AgentInfo {
|
||||
final String id;
|
||||
final String name;
|
||||
final String mode;
|
||||
AgentInfo(this.id, this.name, this.mode);
|
||||
factory AgentInfo.fromJson(Map<String, dynamic> j) =>
|
||||
AgentInfo(j['id'] as String, j['name'] as String? ?? '', j['mode'] as String? ?? '');
|
||||
}
|
||||
|
||||
class PermissionRequest {
|
||||
final String id;
|
||||
final String sessionId;
|
||||
final String action;
|
||||
final List<String> resources;
|
||||
PermissionRequest(this.id, this.sessionId, this.action, this.resources);
|
||||
factory PermissionRequest.fromJson(Map<String, dynamic> j) => PermissionRequest(
|
||||
j['id'] as String,
|
||||
j['sessionID'] as String? ?? '',
|
||||
j['action'] as String? ?? '',
|
||||
(j['resources'] as List?)?.map((e) => e.toString()).toList() ?? const [],
|
||||
);
|
||||
}
|
||||
|
||||
String _jsonString(Object? o) {
|
||||
if (o is String) return o;
|
||||
return o.toString();
|
||||
}
|
||||
Reference in new issue
Block a user