{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://git-a2a.com/schema/a2amodule.v2.json",
  "title": "a2amodule schema 2 manifest",
  "type": "object",
  "required": ["schema", "component"],
  "properties": {
    "schema": { "const": 2 },
    "component": { "$ref": "#/$defs/component" },
    "agent": { "$ref": "#/$defs/agent" },
    "dependencies": { "type": "array", "items": { "$ref": "#/$defs/dependency" } }
  },
  "additionalProperties": false,
  "$defs": {
    "id": { "type": "string", "pattern": "^[a-z0-9](?:[a-z0-9._-]*[a-z0-9])?$" },
    "relativePath": {
      "type": "string",
      "minLength": 1,
      "pattern": "^(?!/)(?![A-Za-z]:[\\\\/])(?!.*(?:^|/)\\.\\.(?:/|$))(?!.*\\\\)(?!\\.$).+$"
    },
    "surfacePath": { "oneOf": [{ "const": "." }, { "$ref": "#/$defs/relativePath" }] },
    "component": {
      "type": "object",
      "required": ["id"],
      "properties": {
        "id": { "$ref": "#/$defs/id" },
        "description": { "type": "string" },
        "repository": { "type": "string", "minLength": 1 },
        "exports": { "type": "array", "items": { "$ref": "#/$defs/export" } },
        "surface": { "$ref": "#/$defs/surfacePath" }
      },
      "additionalProperties": false
    },
    "export": {
      "type": "object",
      "required": ["adapter", "name"],
      "properties": {
        "adapter": { "type": "string", "minLength": 1 },
        "name": { "type": "string", "minLength": 1 },
        "path": { "$ref": "#/$defs/relativePath" },
        "checksum": { "type": "string", "minLength": 1 }
      },
      "additionalProperties": false
    },
    "agent": {
      "type": "object",
      "required": ["card"],
      "properties": {
        "name": { "type": "string" },
        "card": {
          "anyOf": [
            { "type": "string", "pattern": "^https://[^/\\s]+(?:/[^\\s]*)?$" },
            { "$ref": "#/$defs/relativePath" }
          ]
        }
      },
      "additionalProperties": false
    },
    "dependency": {
      "type": "object",
      "required": ["name", "git"],
      "properties": {
        "name": { "$ref": "#/$defs/id" },
        "git": { "type": "string", "minLength": 1 },
        "ref": { "type": "string", "minLength": 1 },
        "path": { "$ref": "#/$defs/relativePath" },
        "bindings": { "type": "array", "items": { "$ref": "#/$defs/binding" } }
      },
      "additionalProperties": false
    },
    "binding": {
      "type": "object",
      "required": ["adapter", "variant"],
      "properties": {
        "adapter": { "type": "string", "minLength": 1 },
        "variant": { "type": "string", "minLength": 1 },
        "export": { "type": "string", "minLength": 1 },
        "path": { "$ref": "#/$defs/relativePath" }
      },
      "additionalProperties": false
    }
  }
}
