merge: return confirmation payload from delete_task and cancel_task
This commit is contained in:
@@ -10,6 +10,8 @@ using TaskStatus = ClaudeDo.Data.Models.TaskStatus;
|
|||||||
namespace ClaudeDo.Worker.External;
|
namespace ClaudeDo.Worker.External;
|
||||||
|
|
||||||
public sealed record TaskListDto(string Id, string Name, string? WorkingDir);
|
public sealed record TaskListDto(string Id, string Name, string? WorkingDir);
|
||||||
|
public sealed record DeleteTaskResult(bool Deleted, string Id);
|
||||||
|
public sealed record CancelTaskResult(bool Cancelled, string Id);
|
||||||
|
|
||||||
public sealed record TaskDto(
|
public sealed record TaskDto(
|
||||||
string Id,
|
string Id,
|
||||||
@@ -204,16 +206,16 @@ public sealed class ExternalMcpService
|
|||||||
await _broadcaster.TaskUpdated(taskId);
|
await _broadcaster.TaskUpdated(taskId);
|
||||||
}
|
}
|
||||||
|
|
||||||
[McpServerTool, Description("Cancel a running task. Returns true if the task was running and cancellation was requested.")]
|
[McpServerTool, Description("Cancel a running task. Returns { cancelled: true, id } if the task was running and cancellation was requested; cancelled is false if the task was not running.")]
|
||||||
public async Task<bool> CancelTask(string taskId, CancellationToken cancellationToken)
|
public async Task<CancelTaskResult> CancelTask(string taskId, CancellationToken cancellationToken)
|
||||||
{
|
{
|
||||||
var cancelled = _queue.CancelTask(taskId);
|
var cancelled = _queue.CancelTask(taskId);
|
||||||
if (cancelled) await _broadcaster.TaskUpdated(taskId);
|
if (cancelled) await _broadcaster.TaskUpdated(taskId);
|
||||||
return cancelled;
|
return new CancelTaskResult(cancelled, taskId);
|
||||||
}
|
}
|
||||||
|
|
||||||
[McpServerTool, Description("Delete a task. Refuses if the task is currently Running — cancel it first.")]
|
[McpServerTool, Description("Delete a task. Returns { deleted: true, id } on success. Throws if the task is not found or is currently Running — cancel it first.")]
|
||||||
public async Task DeleteTask(string taskId, CancellationToken cancellationToken)
|
public async Task<DeleteTaskResult> DeleteTask(string taskId, CancellationToken cancellationToken)
|
||||||
{
|
{
|
||||||
var task = await _tasks.GetByIdAsync(taskId, cancellationToken)
|
var task = await _tasks.GetByIdAsync(taskId, cancellationToken)
|
||||||
?? throw new InvalidOperationException($"Task {taskId} not found.");
|
?? throw new InvalidOperationException($"Task {taskId} not found.");
|
||||||
@@ -222,6 +224,7 @@ public sealed class ExternalMcpService
|
|||||||
|
|
||||||
await _tasks.DeleteAsync(taskId, cancellationToken);
|
await _tasks.DeleteAsync(taskId, cancellationToken);
|
||||||
await _broadcaster.TaskUpdated(taskId);
|
await _broadcaster.TaskUpdated(taskId);
|
||||||
|
return new DeleteTaskResult(true, taskId);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static TaskDto ToDto(TaskEntity t) => new(
|
private static TaskDto ToDto(TaskEntity t) => new(
|
||||||
|
|||||||
Reference in New Issue
Block a user