feat: a transport seam, image previews, native forms, a phone drawer
- lib/api/transport.dart: TransportRequest/TransportResponse/Transport, with DirectTransport holding the old behaviour (HTTP CONNECT, SOCKS5/socks5h, self-signed and pinned certificates). Client goes through it, so a relay tunnel only adds an implementation. - User rows decode the server's inline attachment data and open the shared image preview on tap; the local path stays the fallback. - The agent's native forms: models from @opencode/client, the form list, replies and cancels, form.* events, and a dock above the composer with when-rules and required-field validation (a switch must be on). - HomeScreen: the session list is the phone's left drawer and a persistent column from 840 px, the chat beside it; the newest session opens on start. - 0.3.10 (310).
This commit is contained in:
1 parent
9b53338908
commit
60d02083d3
11 files changed
+1272
-320
No files matched your search
+147
-3
@@ -291,9 +291,153 @@ class Message {
|
||||
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? ?? '');
|
||||
|
||||
/// Base64 of the file the user attached, as the server stores it.
|
||||
final String data;
|
||||
|
||||
/// 'inline' | 'path' — where the bytes came from, when the server says.
|
||||
final String source;
|
||||
|
||||
FileAttachment(this.name, this.mime, {this.data = '', this.source = ''});
|
||||
|
||||
bool get isImage => mime.startsWith('image/') && data.isNotEmpty;
|
||||
|
||||
factory FileAttachment.fromJson(Map<String, dynamic> j) => FileAttachment(
|
||||
j['name'] as String? ?? '',
|
||||
j['mime'] as String? ?? '',
|
||||
data: j['data'] as String? ?? '',
|
||||
// Stored messages carry `{type: 'inline'}` here; keep only text.
|
||||
source: j['source'] is String ? j['source'] as String : '',
|
||||
);
|
||||
}
|
||||
|
||||
/// One row of a native form's choice control.
|
||||
class FormOption {
|
||||
final String value;
|
||||
final String label;
|
||||
final String? description;
|
||||
const FormOption(this.value, this.label, [this.description]);
|
||||
factory FormOption.fromJson(Map<String, dynamic> j) => FormOption(
|
||||
j['value'] as String? ?? '',
|
||||
j['label'] as String? ?? j['value'] as String? ?? '',
|
||||
j['description'] as String?,
|
||||
);
|
||||
}
|
||||
|
||||
/// `when` makes a field visible only while another field holds a value.
|
||||
class FormWhen {
|
||||
final String key;
|
||||
final String op; // eq | neq
|
||||
final Object? value;
|
||||
const FormWhen(this.key, this.op, this.value);
|
||||
factory FormWhen.fromJson(Map<String, dynamic> j) => FormWhen(
|
||||
j['key'] as String? ?? '',
|
||||
j['op'] as String? ?? 'eq',
|
||||
j['value'],
|
||||
);
|
||||
}
|
||||
|
||||
/// A field of a form request: string, number, integer, boolean, multiselect
|
||||
/// or external (a link the user acknowledges).
|
||||
class AgentFormField {
|
||||
final String key;
|
||||
final String type;
|
||||
final String? title;
|
||||
final String? description;
|
||||
final String? placeholder;
|
||||
final String? format;
|
||||
final String? url;
|
||||
final bool required;
|
||||
final bool hidden;
|
||||
final bool custom;
|
||||
final Object? defaultValue;
|
||||
final num? minimum;
|
||||
final num? maximum;
|
||||
final int? minLength;
|
||||
final int? maxLength;
|
||||
final int? minItems;
|
||||
final int? maxItems;
|
||||
final List<FormOption> options;
|
||||
final List<FormWhen> when;
|
||||
|
||||
const AgentFormField({
|
||||
required this.key,
|
||||
required this.type,
|
||||
this.title,
|
||||
this.description,
|
||||
this.placeholder,
|
||||
this.format,
|
||||
this.url,
|
||||
this.required = false,
|
||||
this.hidden = false,
|
||||
this.custom = false,
|
||||
this.defaultValue,
|
||||
this.minimum,
|
||||
this.maximum,
|
||||
this.minLength,
|
||||
this.maxLength,
|
||||
this.minItems,
|
||||
this.maxItems,
|
||||
this.options = const [],
|
||||
this.when = const [],
|
||||
});
|
||||
|
||||
factory AgentFormField.fromJson(Map<String, dynamic> j) {
|
||||
num? numOf(Object? v) => v is num ? v : null;
|
||||
return AgentFormField(
|
||||
key: j['key'] as String? ?? '',
|
||||
type: j['type'] as String? ?? 'string',
|
||||
title: j['title'] as String?,
|
||||
description: j['description'] as String?,
|
||||
placeholder: j['placeholder'] as String?,
|
||||
format: j['format'] as String?,
|
||||
url: j['url'] as String?,
|
||||
required: j['required'] as bool? ?? false,
|
||||
hidden: j['hidden'] as bool? ?? false,
|
||||
custom: j['custom'] as bool? ?? false,
|
||||
defaultValue: j['default'],
|
||||
minimum: numOf(j['minimum']),
|
||||
maximum: numOf(j['maximum']),
|
||||
minLength: (j['minLength'] as num?)?.toInt(),
|
||||
maxLength: (j['maxLength'] as num?)?.toInt(),
|
||||
minItems: (j['minItems'] as num?)?.toInt(),
|
||||
maxItems: (j['maxItems'] as num?)?.toInt(),
|
||||
options: [
|
||||
for (final o in (j['options'] as List? ?? []))
|
||||
if (o is Map<String, dynamic>) FormOption.fromJson(o),
|
||||
],
|
||||
when: [
|
||||
for (final w in (j['when'] as List? ?? []))
|
||||
if (w is Map<String, dynamic>) FormWhen.fromJson(w),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
String get label => (title == null || title!.isEmpty) ? key : title!;
|
||||
}
|
||||
|
||||
/// A blocking question from the agent. The client answers every visible field
|
||||
/// at once; the answer map is keyed by field key.
|
||||
class FormInfo {
|
||||
final String id;
|
||||
final String sessionID;
|
||||
final String title;
|
||||
final List<AgentFormField> fields;
|
||||
const FormInfo({
|
||||
required this.id,
|
||||
required this.sessionID,
|
||||
required this.title,
|
||||
required this.fields,
|
||||
});
|
||||
factory FormInfo.fromJson(Map<String, dynamic> j) => FormInfo(
|
||||
id: j['id'] as String? ?? '',
|
||||
sessionID: j['sessionID'] as String? ?? '',
|
||||
title: j['title'] as String? ?? '',
|
||||
fields: [
|
||||
for (final f in (j['fields'] as List? ?? []))
|
||||
if (f is Map<String, dynamic>) AgentFormField.fromJson(f),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
class Page<T> {
|
||||
|
||||
Reference in new issue
Block a user