/**
 * AgentCard — A2A v1.2 (Linux Foundation, 150+ orgs).
 *
 * Sprint-563: B8 — AgentCard + A2A v1.2 + Signed Agent Cards (CH8 activation).
 *
 * Converts a Vauban AgentDescriptor into an A2A v1.2-compliant AgentCard.
 * Signed AgentCards activate CH8: Trace.agentSignature is computed from
 * the agent's identity key.
 */
// ─── Builder ─────────────────────────────────────────────────────────────────
/**
 * Convert a Vauban AgentDescriptor into an A2A v1.2 AgentCard.
 *
 * Usage:
 *   import { toAgentCard } from "@vauban-org/agent-sdk";
 *   const card = await toAgentCard(descriptor, skills, { baseUrl: "https://agents.vauban.tech" });
 */
export async function toAgentCard(descriptor, skills, opts) {
    const card = {
        protocolVersion: "1.2",
        name: descriptor.name,
        description: descriptor.description,
        url: `${opts.baseUrl}/agents/${descriptor.agentId}`,
        provider: opts.provider ?? "vauban",
        version: descriptor.version,
        defaultInputModes: ["application/json"],
        defaultOutputModes: ["application/json"],
        capabilities: {
            streaming: true,
            pushNotifications: false,
            stateTransitionHistory: true,
            ...opts.capabilities,
        },
        skills: skills.map((s) => ({
            id: `skill:${s.name}`,
            name: s.name,
            description: s.description,
            tags: s.tags,
            inputSchema: s.inputSchema,
            outputSchema: s.outputSchema,
        })),
    };
    // CH8: Sign the card if a signing key is provided
    if (opts.signingKey) {
        const payload = JSON.stringify({
            name: card.name,
            url: card.url,
            version: card.version,
            skills: card.skills.map((s) => s.id).sort(),
        });
        card.signature = await opts.signingKey.sign(payload);
    }
    return card;
}
/**
 * Validate that an AgentCard has all required fields per A2A v1.2 spec.
 */
export function validateAgentCard(card) {
    const errors = [];
    if (card.protocolVersion !== "1.2") {
        errors.push("protocolVersion must be '1.2'");
    }
    if (!card.name || card.name.trim().length === 0) {
        errors.push("name is required");
    }
    if (!card.description || card.description.trim().length === 0) {
        errors.push("description is required");
    }
    if (!card.url || !card.url.startsWith("https://")) {
        errors.push("url must be a valid HTTPS URL");
    }
    if (!card.version) {
        errors.push("version is required");
    }
    if (!card.skills || card.skills.length === 0) {
        errors.push("at least one skill is required");
    }
    return { valid: errors.length === 0, errors };
}
//# sourceMappingURL=agent-card.js.map