{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://schemas.shimpz.com/assistant/v1/manifest.schema.json",
  "title": "Shimpz Assistant manifest v1",
  "type": "object",
  "additionalProperties": false,
  "required": [
    "shimpz",
    "network"
  ],
  "properties": {
    "shimpz": {
      "$ref": "#/$defs/shimpz"
    },
    "network": {
      "$ref": "#/$defs/network"
    },
    "integrations": {
      "type": "object",
      "maxProperties": 16,
      "propertyNames": {
        "$ref": "#/$defs/identifier"
      },
      "additionalProperties": {
        "$ref": "#/$defs/integration"
      }
    },
    "stored_inputs": {
      "type": "object",
      "maxProperties": 8,
      "propertyNames": {
        "$ref": "#/$defs/identifier"
      },
      "additionalProperties": {
        "$ref": "#/$defs/storedInput"
      }
    }
  },
  "$defs": {
    "shimpz": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "spec",
        "id",
        "version",
        "name",
        "summary",
        "description",
        "creators",
        "github",
        "genesis"
      ],
      "properties": {
        "spec": {
          "const": 1
        },
        "id": {
          "$ref": "#/$defs/assistantIdentifier"
        },
        "version": {
          "type": "string",
          "pattern": "^(0|[1-9][0-9]*)\\.(0|[1-9][0-9]*)\\.(0|[1-9][0-9]*)$"
        },
        "name": {
          "type": "string",
          "minLength": 1,
          "maxLength": 80,
          "pattern": "^(?!\\s)(?!.*\\s$)[^\\u0000-\\u001f\\u007f-\\u009f\\u200b-\\u200f\\u202a-\\u202e\\u2060-\\u206f\\ufeff]+$"
        },
        "summary": {
          "type": "string",
          "minLength": 1,
          "maxLength": 80,
          "pattern": "^(?!\\s)(?!.*\\s$)[^\\u0000-\\u001f\\u007f-\\u009f\\u200b-\\u200f\\u202a-\\u202e\\u2060-\\u206f\\ufeff]+$"
        },
        "description": {
          "type": "string",
          "minLength": 1,
          "maxLength": 400,
          "pattern": "^(?!\\s)(?!.*\\s$)[^\\u0000-\\u001f\\u007f-\\u009f\\u200b-\\u200f\\u202a-\\u202e\\u2060-\\u206f\\ufeff]+$"
        },
        "creators": {
          "type": "array",
          "minItems": 1,
          "maxItems": 16,
          "uniqueItems": true,
          "items": {
            "type": "string",
            "pattern": "^@[a-z0-9][a-z0-9-]{1,30}[a-z0-9]$"
          }
        },
        "github": {
          "type": "string",
          "pattern": "^https://github\\.com/[A-Za-z0-9](?:[A-Za-z0-9-]{0,37}[A-Za-z0-9])?/[A-Za-z0-9](?:[A-Za-z0-9_.-]{0,98}[A-Za-z0-9])?$"
        },
        "links": {
          "$ref": "#/$defs/links"
        },
        "genesis": {
          "type": "string",
          "minLength": 1,
          "maxLength": 65536
        }
      }
    },
    "network": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "allowed_hosts"
      ],
      "properties": {
        "allowed_hosts": {
          "type": "array",
          "maxItems": 32,
          "uniqueItems": true,
          "items": {
            "type": "string",
            "minLength": 1,
            "maxLength": 253
          }
        }
      }
    },
    "assistantIdentifier": {
      "type": "string",
      "minLength": 1,
      "maxLength": 40,
      "pattern": "^[a-z][a-z0-9]*(?:-[a-z0-9]+)*$",
      "not": {
        "enum": [
          "postgres",
          "assistant-egress",
          "shimpz-assistant-egress"
        ]
      }
    },
    "identifier": {
      "type": "string",
      "minLength": 1,
      "maxLength": 64,
      "pattern": "^[a-z][a-z0-9]*(?:-[a-z0-9]+)*$"
    },
    "integration": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "scopes"
      ],
      "properties": {
        "scopes": {
          "type": "array",
          "minItems": 1,
          "maxItems": 32,
          "uniqueItems": true,
          "items": {
            "type": "string",
            "minLength": 1,
            "maxLength": 128,
            "pattern": "^[a-z0-9][a-z0-9.:/_-]*$"
          }
        }
      }
    },
    "storedInput": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "kind",
        "label",
        "description",
        "help_url",
        "host",
        "routes"
      ],
      "oneOf": [
        {
          "required": [
            "header"
          ]
        },
        {
          "required": [
            "query"
          ],
          "not": {
            "required": [
              "scheme"
            ]
          }
        }
      ],
      "properties": {
        "kind": {
          "const": "password"
        },
        "host": {
          "type": "string",
          "minLength": 1,
          "maxLength": 253
        },
        "header": {
          "type": "string",
          "pattern": "^[!#$%&'*+.^_`|~0-9A-Za-z-]{1,64}$"
        },
        "query": {
          "type": "string",
          "pattern": "^[A-Za-z0-9._~-]{1,64}$"
        },
        "scheme": {
          "type": "string",
          "pattern": "^[A-Za-z][A-Za-z0-9-]{0,31}$"
        },
        "hmac": {
          "$ref": "#/$defs/identifier"
        },
        "routes": {
          "type": "array",
          "minItems": 1,
          "maxItems": 32,
          "items": {
            "$ref": "#/$defs/route"
          }
        },
        "label": {
          "type": "string",
          "minLength": 1,
          "maxLength": 80,
          "pattern": "^(?!\\s)(?!.*\\s$)[^\\u0000-\\u001f\\u007f-\\u009f\\u200b-\\u200f\\u202a-\\u202e\\u2060-\\u206f\\ufeff]+$"
        },
        "description": {
          "type": "string",
          "minLength": 1,
          "maxLength": 400,
          "pattern": "^(?!\\s)(?!.*\\s$)[^\\u0000-\\u001f\\u007f-\\u009f\\u200b-\\u200f\\u202a-\\u202e\\u2060-\\u206f\\ufeff]+$"
        },
        "help_url": {
          "$ref": "#/$defs/helpUrl"
        }
      }
    },
    "route": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "method",
        "path"
      ],
      "properties": {
        "method": {
          "enum": [
            "GET",
            "HEAD",
            "POST",
            "PUT",
            "PATCH",
            "DELETE"
          ]
        },
        "path": {
          "type": "string",
          "minLength": 2,
          "maxLength": 512,
          "pattern": "^(?:/(?:\\*|(?!\\.\\.?(?:/|(?![\\s\\S])))[A-Za-z0-9._~-]{1,64}))+(?![\\s\\S])"
        },
        "query": {
          "type": "array",
          "minItems": 1,
          "maxItems": 8,
          "items": {
            "$ref": "#/$defs/routeSelector"
          }
        }
      }
    },
    "routeSelector": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "name",
        "values"
      ],
      "properties": {
        "name": {
          "type": "string",
          "pattern": "^[A-Za-z0-9._~-]{1,64}(?![\\s\\S])"
        },
        "values": {
          "type": "array",
          "minItems": 1,
          "maxItems": 16,
          "uniqueItems": true,
          "items": {
            "type": "string",
            "minLength": 1,
            "maxLength": 256,
            "pattern": "^(?:[A-Za-z0-9._~-]|%[0-9A-F]{2})+(?![\\s\\S])"
          }
        }
      }
    },
    "helpUrl": {
      "type": "string",
      "minLength": 1,
      "maxLength": 2048,
      "pattern": "^https://(?=[^/]{1,253}/)(?![^/]*\\.(?:arpa|example|home|internal|invalid|lan|local|localdomain|localhost|onion|test)/)(?:(?!xn--)[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?\\.)+(?!xn--)[a-z](?:[a-z0-9-]{0,61}[a-z0-9])?(?:/(?!\\.\\.?(?:/|\\?|(?![\\s\\S])))(?:[A-Za-z0-9._~!$&()*+,;=:@-]|%(?!2E)[0-9A-F]{2})*)+(?:\\?(?:[A-Za-z0-9._~!$&()*+,;=:@/?-]|%[0-9A-F]{2})+)?(?![\\s\\S])"
    },
    "links": {
      "type": "object",
      "additionalProperties": false,
      "minProperties": 1,
      "properties": {
        "site": {
          "type": "string",
          "maxLength": 256,
          "allOf": [
            {
              "$ref": "#/$defs/helpUrl"
            }
          ]
        },
        "github": {
          "type": "string",
          "maxLength": 256,
          "allOf": [
            {
              "$ref": "#/$defs/helpUrl"
            },
            {
              "pattern": "^https://github\\.com/"
            }
          ]
        },
        "x": {
          "type": "string",
          "maxLength": 256,
          "allOf": [
            {
              "$ref": "#/$defs/helpUrl"
            },
            {
              "pattern": "^https://x\\.com/"
            }
          ]
        },
        "youtube": {
          "type": "string",
          "maxLength": 256,
          "allOf": [
            {
              "$ref": "#/$defs/helpUrl"
            },
            {
              "pattern": "^https://(?:www\\.)?youtube\\.com/"
            }
          ]
        },
        "linkedin": {
          "type": "string",
          "maxLength": 256,
          "allOf": [
            {
              "$ref": "#/$defs/helpUrl"
            },
            {
              "pattern": "^https://(?:www\\.)?linkedin\\.com/"
            }
          ]
        },
        "instagram": {
          "type": "string",
          "maxLength": 256,
          "allOf": [
            {
              "$ref": "#/$defs/helpUrl"
            },
            {
              "pattern": "^https://(?:www\\.)?instagram\\.com/"
            }
          ]
        }
      }
    }
  }
}
