V18 / MESSAGING

message_claim_operation

Application-bound scenario operation. Named XML inputs control execution; this is not a main-agent tool.

See source registrationIntroduced in V14V18

What it does

Read the exact source snapshot below for its parameters, behavior, and registration.

Read the implementation

This page describes the selected release. The source link points to the same exact commit; it cannot silently open a newer implementation.

Lilith/Core/Messaging/MessageOperations.cs ↗

Implementation code

Read the implementation from this version's exact source snapshot. Helper links below stay on the same release.

Lilith/Core/Messaging/MessageOperations.cs

C#
using System.Text.Json;
using Lilith.Core.Workspace;

namespace Lilith.Core.Messaging;

internal static class MessageOperations
{
    internal static readonly HashSet<string> Names = ["message_channels_operation", "message_check_operation", "message_status_operation", "message_claim_operation", "message_send_operation"];
    internal static bool NeedsApproval(string? receipt)
    {
        if (receipt is null) return false;
        using var doc = JsonDocument.Parse(receipt);
        return doc.RootElement.TryGetProperty("status", out var value) && value.GetString() == "needs_approval";
    }
    internal static async Task<string> ExecuteAsync(ProviderClient provider, string operation, IReadOnlyDictionary<string, string> inputs, CancellationToken ct)
    {
        string Get(string key) => inputs.GetValueOrDefault(key) ?? "";
        string nickname = Get("nickname");
        switch (operation)
        {
            case "message_channels_operation": return await MessageBridgeClient.RequestAsync("channels", new { key = Get("after") }, ct);
            case "message_check_operation": return await MessageBridgeClient.RequestAsync("inbox", new { nickname }, ct);
            case "message_status_operation": return await MessageBridgeClient.RequestAsync("status", new { nickname }, ct);
            case "message_claim_operation": return await MessageBridgeClient.RequestAsync("claim", new { nickname, messageId = Get("message_id") }, ct);
            case "message_send_operation":
                var workspace = provider.Workspace ?? throw new InvalidOperationException("Configure the boot-fixed access mode first.");
                string prepared = await MessageBridgeClient.RequestAsync("prepare", new { nickname, room = Get("room"), text = Get("text"), replyTo = Get("reply_to"), key = Guid.NewGuid().ToString("N") }, ct);
                using (var doc = JsonDocument.Parse(prepared))
                {
                    var proposal = doc.RootElement;
                    string id = proposal.GetProperty("id").GetString()!;
                    if (workspace.Options.Mode == WorkspaceAccessMode.Yolo)
                        return await MessageBridgeClient.RequestAsync("send", new { nickname, proposalId = id, signature = proposal.GetProperty("signature").GetString() }, ct);
                    provider.PendingMessageApproval = true;
                    return JsonSerializer.Serialize(new { status = "needs_approval", source = "dummy", nickname, proposal = proposal.Clone(), instruction = "Review the exact destination and text. Nothing sent. Enter /message-approve " + nickname + " " + id + " to send, or /message-reject " + nickname + " " + id + "." });
                }
            default: throw new ArgumentException("Unknown messaging operation.");
        }
    }
}

Scenarios using this tool