/**
 * Mailbox channel provider — delivers to an agent's file-based mailbox.
 *
 * The mailbox is one channel among many. This provider is a thin wrapper over
 * the same `enqueue` seam that `agents message` uses (commands/message.ts), so
 * both callers share one spool at ~/.agents/.history/mailbox/<id>/.
 */
import { mailboxDir, enqueue, isValidMailboxId } from '../../mailbox.js';
export const mailboxProvider = {
    name: 'mailbox',
    async send(text, opts) {
        if (!isValidMailboxId(opts.target)) {
            return { ok: false, channel: 'mailbox', id: opts.target, error: `invalid mailbox id '${opts.target}'` };
        }
        if (opts.dryRun) {
            return { ok: true, channel: 'mailbox', id: opts.target };
        }
        try {
            const msgId = enqueue(mailboxDir(opts.target), { to: opts.target, text, from: opts.from });
            return { ok: true, channel: 'mailbox', id: opts.target, msgId };
        }
        catch (err) {
            return { ok: false, channel: 'mailbox', id: opts.target, error: err.message };
        }
    },
};
