feat: slash commands and skills in the composer, readable turn errors

- Typing `/` opens a palette above the composer, dsh-Go's shape: icon, the
  first-party Chinese label, /name, a one-line description, the first match
  highlighted and a return hint. It lists the directory's commands
  (/api/command) and skills (/api/skill), filters by name, label or
  description, and keeps the field focused while it opens.
- Picking completes `/name ` when the command takes arguments (its
  description shows a `[...]` form) and runs argument-free commands at once;
  skills complete and ride the next prompt as a `skills` attachment. Enter
  picks the highlighted row, arrows move, Esc closes.
- Sends route by name: commands go through POST /api/session/:id/command so
  the server expands the template (and writes the user message), skills go
  through the normal prompt with their id attached, anything else stays a
  plain message. A failed command keeps the draft for a retry.
- A failed turn now says so in the transcript: the last step's error is
  rendered under it as a quiet red block with the 中文 reading (auth, retry,
  stopped, send failure) and the provider's raw response behind 显示详情.
  Failed compactions and idle errors not already carried by the step are
  shown too; an error that a later step recovered from is not the turn's
  outcome and stays hidden.
- The tail is refetched when a turn starts, so a command's server-written
  user message (or another client's) appears without reopening the session;
  a successful send clears the stale error banner.
Version 0.3.6 (code 306).
This commit is contained in:
blumia committed 2026-11-20 02:20:35 +08:00
1 parent d7cec9d155
commit 6c00e5e026
7 files changed
+725 -14

No files matched your search

+37
View File
@@ -158,6 +158,29 @@ class ToolState {
};
}
/// The error OpenCode recorded on a message (a failed step, a failed
/// compaction). `body` is the provider's raw response, when there was one.
class MessageError {
final String type;
final String message;
final int? status;
final String? body;
const MessageError({this.type = '', this.message = '', this.status, this.body});
factory MessageError.fromJson(Map<String, dynamic> j) {
final data = j['data'];
final response = j['response'];
return MessageError(
type: (j['type'] ?? j['name'] ?? '') as String? ?? '',
message: (j['message'] as String?) ??
(data is Map ? data['message'] as String? : null) ??
'',
status: (j['status'] as num?)?.toInt(),
body: response is Map ? response['body'] as String? : null,
);
}
bool get isEmpty => type.isEmpty && message.isEmpty;
}
class Message {
final String id;
final String type;
@@ -171,6 +194,12 @@ class Message {
final String finish;
final double cost;
final TokenUsage? tokens;
/// Set when the step (or compaction) failed.
final MessageError? error;
/// Compaction messages: 'failed' etc.
final String status;
/// Compaction messages: why it ran ('manual').
final String reason;
Message({
required this.id,
required this.type,
@@ -184,6 +213,9 @@ class Message {
this.finish = '',
this.cost = 0,
this.tokens,
this.error,
this.status = '',
this.reason = '',
});
factory Message.fromJson(Map<String, dynamic> j) {
final t = j['time'] as Map<String, dynamic>? ?? {};
@@ -206,6 +238,11 @@ class Message {
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>),
error: j['error'] == null
? null
: MessageError.fromJson(j['error'] as Map<String, dynamic>),
status: j['status'] as String? ?? '',
reason: j['reason'] as String? ?? '',
);
}
String get partText {