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:
1 parent
d7cec9d155
commit
6c00e5e026
7 files changed
+725
-14
No files matched your search
+50
-1
@@ -250,15 +250,64 @@ class Client {
|
||||
}
|
||||
|
||||
Future<void> prompt(String sessionId,
|
||||
{String text = '', String? messageId, String? directory, List<Map<String, String>>? files}) async {
|
||||
{String text = '',
|
||||
String? messageId,
|
||||
String? directory,
|
||||
List<Map<String, String>>? files,
|
||||
List<String>? skillIds}) async {
|
||||
await _json('POST', '/api/session/${Uri.encodeComponent(sessionId)}/prompt', directory: directory,
|
||||
body: {
|
||||
if (text.isNotEmpty) 'text': text,
|
||||
if (messageId != null) 'id': messageId,
|
||||
if (files != null && files.isNotEmpty) 'files': files,
|
||||
if (skillIds != null && skillIds.isNotEmpty)
|
||||
'skills': [
|
||||
for (final id in skillIds) {'id': id},
|
||||
],
|
||||
});
|
||||
}
|
||||
|
||||
/// Runs a registered slash command (`/initialize`, `/review`, …). The
|
||||
/// server expands the command template and starts the turn.
|
||||
Future<void> command(String sessionId,
|
||||
{required String name, String text = '', String? directory,
|
||||
List<Map<String, String>>? files}) async {
|
||||
await _json('POST', '/api/session/${Uri.encodeComponent(sessionId)}/command',
|
||||
directory: directory,
|
||||
body: {
|
||||
'name': name,
|
||||
'text': text,
|
||||
if (files != null && files.isNotEmpty) 'files': files,
|
||||
});
|
||||
}
|
||||
|
||||
/// The commands this directory registers (`/api/command`).
|
||||
Future<List<Map<String, String>>> commands({String? directory}) async {
|
||||
final r = await _json('GET', '/api/command', directory: directory);
|
||||
return [
|
||||
for (final e in (r['data'] as List? ?? []))
|
||||
if (e is Map)
|
||||
{
|
||||
'name': e['name'] as String? ?? '',
|
||||
'description': e['description'] as String? ?? '',
|
||||
},
|
||||
];
|
||||
}
|
||||
|
||||
/// The skills opencode knows in this directory (`/api/skill`).
|
||||
Future<List<Map<String, String>>> skills({String? directory}) async {
|
||||
final r = await _json('GET', '/api/skill', directory: directory);
|
||||
return [
|
||||
for (final e in (r['data'] as List? ?? []))
|
||||
if (e is Map)
|
||||
{
|
||||
'id': e['id'] as String? ?? '',
|
||||
'name': e['name'] as String? ?? '',
|
||||
'description': e['description'] as String? ?? '',
|
||||
},
|
||||
];
|
||||
}
|
||||
|
||||
Future<bool> interrupt(String sessionId, {String? directory}) async {
|
||||
final r = await _json('POST', '/api/session/${Uri.encodeComponent(sessionId)}/interrupt',
|
||||
directory: directory, body: const {});
|
||||
|
||||
@@ -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 {
|
||||
|
||||
Reference in new issue
Block a user