{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "type": "object",
  "properties": {
    "version": { "type": "number", "const": 1 },
    "usage": {
      "type": "object",
      "properties": {
        "hostId": {
          "type": "string",
          "pattern": "^[a-zA-Z0-9][a-zA-Z0-9._-]{0,79}$"
        },
        "labels": {
          "type": "object",
          "propertyNames": {
            "type": "string",
            "pattern": "^[a-zA-Z][a-zA-Z0-9._-]{0,63}$"
          },
          "additionalProperties": { "type": "string", "maxLength": 128 }
        },
        "retentionDays": { "type": "integer", "minimum": 1, "maximum": 3650 }
      },
      "required": ["hostId"],
      "additionalProperties": false
    },
    "listen": {
      "default": { "host": "127.0.0.1", "port": 7433 },
      "type": "object",
      "properties": {
        "host": { "default": "127.0.0.1", "type": "string", "minLength": 1 },
        "port": {
          "default": 7433,
          "type": "integer",
          "minimum": 0,
          "maximum": 65535
        }
      },
      "additionalProperties": false
    },
    "clientUrl": { "type": "string", "format": "uri" },
    "tls": {
      "type": "object",
      "properties": {
        "certFile": { "type": "string", "minLength": 1 },
        "keyRef": {
          "anyOf": [
            {
              "type": "object",
              "properties": {
                "env": {
                  "type": "string",
                  "pattern": "^[A-Za-z_][A-Za-z0-9_]{0,127}$"
                }
              },
              "required": ["env"],
              "additionalProperties": false
            },
            {
              "type": "object",
              "properties": {
                "file": { "type": "string", "minLength": 1, "maxLength": 4096 }
              },
              "required": ["file"],
              "additionalProperties": false
            },
            {
              "type": "object",
              "properties": {
                "keychain": {
                  "type": "object",
                  "properties": {
                    "service": {
                      "type": "string",
                      "minLength": 1,
                      "maxLength": 128
                    },
                    "account": {
                      "type": "string",
                      "minLength": 1,
                      "maxLength": 128
                    }
                  },
                  "required": ["service", "account"],
                  "additionalProperties": false
                }
              },
              "required": ["keychain"],
              "additionalProperties": false
            }
          ]
        }
      },
      "required": ["certFile", "keyRef"],
      "additionalProperties": false
    },
    "providers": {
      "maxItems": 32,
      "type": "array",
      "items": {
        "anyOf": [
          {
            "type": "object",
            "properties": {
              "id": {
                "type": "string",
                "pattern": "^[a-zA-Z0-9][a-zA-Z0-9._-]{0,79}$"
              },
              "enabled": { "type": "boolean" },
              "accountId": {
                "type": "string",
                "pattern": "^[a-zA-Z0-9][a-zA-Z0-9._-]{0,79}$"
              },
              "name": { "type": "string", "minLength": 1, "maxLength": 100 },
              "models": {
                "maxItems": 1000,
                "type": "array",
                "items": {
                  "type": "string",
                  "pattern": "^[a-zA-Z0-9][a-zA-Z0-9._:/\\[\\]-]{0,199}$"
                }
              },
              "kind": {
                "type": "string",
                "enum": [
                  "openai",
                  "anthropic",
                  "gemini",
                  "xai",
                  "xai-responses",
                  "openai-compatible"
                ]
              },
              "apiKeyRef": {
                "anyOf": [
                  {
                    "type": "object",
                    "properties": {
                      "env": {
                        "type": "string",
                        "pattern": "^[A-Za-z_][A-Za-z0-9_]{0,127}$"
                      }
                    },
                    "required": ["env"],
                    "additionalProperties": false
                  },
                  {
                    "type": "object",
                    "properties": {
                      "file": {
                        "type": "string",
                        "minLength": 1,
                        "maxLength": 4096
                      }
                    },
                    "required": ["file"],
                    "additionalProperties": false
                  },
                  {
                    "type": "object",
                    "properties": {
                      "keychain": {
                        "type": "object",
                        "properties": {
                          "service": {
                            "type": "string",
                            "minLength": 1,
                            "maxLength": 128
                          },
                          "account": {
                            "type": "string",
                            "minLength": 1,
                            "maxLength": 128
                          }
                        },
                        "required": ["service", "account"],
                        "additionalProperties": false
                      }
                    },
                    "required": ["keychain"],
                    "additionalProperties": false
                  }
                ]
              },
              "inputMediaTypes": {
                "type": "object",
                "propertyNames": {
                  "type": "string",
                  "pattern": "^[a-zA-Z0-9][a-zA-Z0-9._:/\\[\\]-]{0,199}$"
                },
                "additionalProperties": {
                  "maxItems": 6,
                  "type": "array",
                  "items": {
                    "type": "string",
                    "enum": [
                      "text/plain",
                      "text/markdown",
                      "image/png",
                      "image/jpeg",
                      "image/webp",
                      "application/pdf"
                    ]
                  }
                }
              },
              "baseUrl": { "type": "string", "format": "uri" }
            },
            "required": ["id", "kind", "apiKeyRef"],
            "additionalProperties": false
          },
          {
            "type": "object",
            "properties": {
              "id": {
                "type": "string",
                "pattern": "^[a-zA-Z0-9][a-zA-Z0-9._-]{0,79}$"
              },
              "enabled": { "type": "boolean" },
              "accountId": {
                "type": "string",
                "pattern": "^[a-zA-Z0-9][a-zA-Z0-9._-]{0,79}$"
              },
              "name": { "type": "string", "minLength": 1, "maxLength": 100 },
              "models": {
                "maxItems": 1000,
                "type": "array",
                "items": {
                  "type": "string",
                  "pattern": "^[a-zA-Z0-9][a-zA-Z0-9._:/\\[\\]-]{0,199}$"
                }
              },
              "kind": {
                "type": "string",
                "enum": ["claude-code", "gemini-cli"]
              },
              "accountDirectory": { "type": "string", "minLength": 1 },
              "binary": { "type": "string", "minLength": 1 }
            },
            "required": ["id", "kind"],
            "additionalProperties": false
          },
          {
            "type": "object",
            "properties": {
              "id": {
                "type": "string",
                "pattern": "^[a-zA-Z0-9][a-zA-Z0-9._-]{0,79}$"
              },
              "enabled": { "type": "boolean" },
              "accountId": {
                "type": "string",
                "pattern": "^[a-zA-Z0-9][a-zA-Z0-9._-]{0,79}$"
              },
              "name": { "type": "string", "minLength": 1, "maxLength": 100 },
              "models": {
                "maxItems": 1000,
                "type": "array",
                "items": {
                  "type": "string",
                  "pattern": "^[a-zA-Z0-9][a-zA-Z0-9._:/\\[\\]-]{0,199}$"
                }
              },
              "kind": { "type": "string", "const": "codex" },
              "accountDirectory": { "type": "string", "minLength": 1 },
              "binary": { "type": "string", "minLength": 1 },
              "reasoningEffort": {
                "type": "string",
                "pattern": "^[a-z][a-z0-9_-]{0,63}$"
              },
              "applicationTools": { "type": "string", "const": "mcp" }
            },
            "required": ["id", "kind"],
            "additionalProperties": false
          },
          {
            "type": "object",
            "properties": {
              "id": {
                "type": "string",
                "pattern": "^[a-zA-Z0-9][a-zA-Z0-9._-]{0,79}$"
              },
              "enabled": { "type": "boolean" },
              "accountId": {
                "type": "string",
                "pattern": "^[a-zA-Z0-9][a-zA-Z0-9._-]{0,79}$"
              },
              "name": { "type": "string", "minLength": 1, "maxLength": 100 },
              "models": {
                "minItems": 1,
                "maxItems": 1000,
                "type": "array",
                "items": {
                  "type": "string",
                  "pattern": "^[a-zA-Z0-9][a-zA-Z0-9._:/\\[\\]-]{0,199}$"
                }
              },
              "kind": { "type": "string", "const": "extension" },
              "extensionId": {
                "type": "string",
                "pattern": "^[a-zA-Z0-9][a-zA-Z0-9._-]{0,79}$"
              },
              "extensionVersion": {
                "type": "string",
                "minLength": 1,
                "maxLength": 100
              },
              "settings": {
                "default": {},
                "type": "object",
                "propertyNames": { "type": "string" },
                "additionalProperties": { "$ref": "#/$defs/__schema0" }
              },
              "secretRefs": {
                "default": {},
                "type": "object",
                "propertyNames": {
                  "type": "string",
                  "pattern": "^[a-zA-Z0-9][a-zA-Z0-9._-]{0,79}$"
                },
                "additionalProperties": {
                  "anyOf": [
                    {
                      "type": "object",
                      "properties": {
                        "env": {
                          "type": "string",
                          "pattern": "^[A-Za-z_][A-Za-z0-9_]{0,127}$"
                        }
                      },
                      "required": ["env"],
                      "additionalProperties": false
                    },
                    {
                      "type": "object",
                      "properties": {
                        "file": {
                          "type": "string",
                          "minLength": 1,
                          "maxLength": 4096
                        }
                      },
                      "required": ["file"],
                      "additionalProperties": false
                    },
                    {
                      "type": "object",
                      "properties": {
                        "keychain": {
                          "type": "object",
                          "properties": {
                            "service": {
                              "type": "string",
                              "minLength": 1,
                              "maxLength": 128
                            },
                            "account": {
                              "type": "string",
                              "minLength": 1,
                              "maxLength": 128
                            }
                          },
                          "required": ["service", "account"],
                          "additionalProperties": false
                        }
                      },
                      "required": ["keychain"],
                      "additionalProperties": false
                    }
                  ]
                }
              }
            },
            "required": [
              "id",
              "models",
              "kind",
              "extensionId",
              "extensionVersion"
            ],
            "additionalProperties": false
          }
        ]
      }
    },
    "tokens": {
      "default": [],
      "maxItems": 100,
      "type": "array",
      "items": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "pattern": "^[a-zA-Z0-9][a-zA-Z0-9._-]{0,79}$"
          },
          "subject": { "type": "string", "minLength": 1, "maxLength": 128 },
          "manageProviders": { "type": "boolean" },
          "tokenRef": {
            "anyOf": [
              {
                "type": "object",
                "properties": {
                  "env": {
                    "type": "string",
                    "pattern": "^[A-Za-z_][A-Za-z0-9_]{0,127}$"
                  }
                },
                "required": ["env"],
                "additionalProperties": false
              },
              {
                "type": "object",
                "properties": {
                  "file": {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 4096
                  }
                },
                "required": ["file"],
                "additionalProperties": false
              },
              {
                "type": "object",
                "properties": {
                  "keychain": {
                    "type": "object",
                    "properties": {
                      "service": {
                        "type": "string",
                        "minLength": 1,
                        "maxLength": 128
                      },
                      "account": {
                        "type": "string",
                        "minLength": 1,
                        "maxLength": 128
                      }
                    },
                    "required": ["service", "account"],
                    "additionalProperties": false
                  }
                },
                "required": ["keychain"],
                "additionalProperties": false
              }
            ]
          },
          "retrieval": {
            "type": "object",
            "properties": {
              "search": {
                "maxItems": 1000,
                "type": "array",
                "items": {
                  "type": "string",
                  "pattern": "^[a-zA-Z0-9][a-zA-Z0-9._:-]{0,127}$"
                }
              },
              "index": {
                "maxItems": 1000,
                "type": "array",
                "items": {
                  "type": "string",
                  "pattern": "^[a-zA-Z0-9][a-zA-Z0-9._:-]{0,127}$"
                }
              },
              "delete": {
                "maxItems": 1000,
                "type": "array",
                "items": {
                  "type": "string",
                  "pattern": "^[a-zA-Z0-9][a-zA-Z0-9._:-]{0,127}$"
                }
              }
            },
            "additionalProperties": false
          },
          "providers": {
            "maxItems": 32,
            "type": "array",
            "items": {
              "type": "string",
              "pattern": "^[a-zA-Z0-9][a-zA-Z0-9._-]{0,79}$"
            }
          },
          "sessions": {
            "maxItems": 4,
            "type": "array",
            "items": {
              "type": "string",
              "enum": ["create", "read", "continue", "delete"]
            }
          },
          "jobs": {
            "maxItems": 3,
            "type": "array",
            "items": { "type": "string", "enum": ["submit", "read", "cancel"] }
          },
          "applicationTools": {
            "maxItems": 32,
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "name": {
                  "type": "string",
                  "pattern": "^[a-zA-Z_][a-zA-Z0-9_]{0,63}$"
                },
                "requiresApproval": { "type": "boolean" }
              },
              "required": ["name"],
              "additionalProperties": false
            }
          },
          "approveTools": {
            "maxItems": 32,
            "type": "array",
            "items": {
              "type": "string",
              "pattern": "^[a-zA-Z_][a-zA-Z0-9_]{0,63}$"
            }
          },
          "tools": {
            "default": [],
            "maxItems": 32,
            "type": "array",
            "items": {
              "type": "string",
              "pattern": "^[a-zA-Z_][a-zA-Z0-9_]{0,63}$"
            }
          }
        },
        "required": ["id", "subject", "tokenRef", "providers"],
        "additionalProperties": false
      }
    },
    "applicationTools": {
      "type": "object",
      "properties": {
        "enabled": { "type": "boolean", "const": true },
        "requireApproval": { "type": "boolean" },
        "maxPending": {
          "type": "integer",
          "exclusiveMinimum": 0,
          "maximum": 9007199254740991
        }
      },
      "required": ["enabled"],
      "additionalProperties": false
    },
    "sessions": {
      "type": "object",
      "properties": {
        "retentionMs": {
          "type": "integer",
          "minimum": 1,
          "maximum": 2147483647
        },
        "maxEntries": { "type": "integer", "minimum": 1, "maximum": 100000 },
        "maxMessages": { "type": "integer", "minimum": 2, "maximum": 100 },
        "maxRecordBytes": {
          "type": "integer",
          "minimum": 1,
          "maximum": 1000000
        }
      },
      "required": ["retentionMs"],
      "additionalProperties": false
    },
    "jobs": {
      "type": "object",
      "properties": {
        "retentionMs": {
          "type": "integer",
          "minimum": 1,
          "maximum": 31536000000
        },
        "maxJobs": {
          "default": 1000,
          "type": "integer",
          "minimum": 1,
          "maximum": 100000
        },
        "maxJobsPerSubject": {
          "default": 100,
          "type": "integer",
          "minimum": 1,
          "maximum": 100000
        },
        "maxBytes": {
          "default": 64000000,
          "type": "integer",
          "minimum": 65536,
          "maximum": 9007199254740991
        },
        "maxJobBytes": {
          "default": 8000000,
          "type": "integer",
          "minimum": 16384,
          "maximum": 64000000
        },
        "path": { "type": "string", "minLength": 1 },
        "worker": {
          "type": "object",
          "properties": {
            "leaseMs": {
              "default": 30000,
              "type": "integer",
              "minimum": 300,
              "maximum": 3600000
            },
            "pollIntervalMs": {
              "default": 250,
              "type": "integer",
              "minimum": 10,
              "maximum": 60000
            },
            "maxWorkers": {
              "default": 32,
              "type": "integer",
              "minimum": 1,
              "maximum": 1000
            }
          },
          "additionalProperties": false
        }
      },
      "required": ["retentionMs", "path"],
      "additionalProperties": false
    },
    "approvals": {
      "type": "object",
      "properties": {
        "interactive": { "type": "boolean", "const": true },
        "allowIdlePause": { "type": "boolean" },
        "maxPending": {
          "type": "integer",
          "exclusiveMinimum": 0,
          "maximum": 9007199254740991
        }
      },
      "required": ["interactive"],
      "additionalProperties": false
    },
    "allowedOrigins": {
      "maxItems": 100,
      "type": "array",
      "items": { "type": "string", "format": "uri" }
    },
    "operations": {
      "type": "object",
      "properties": {
        "directory": { "type": "string", "minLength": 1 },
        "maxRecordBytes": {
          "type": "integer",
          "exclusiveMinimum": 0,
          "maximum": 9007199254740991
        }
      },
      "required": ["directory"],
      "additionalProperties": false
    },
    "context": {
      "type": "object",
      "properties": {
        "maxBytes": { "type": "integer", "minimum": 1, "maximum": 33554432 },
        "maxTextBytes": { "type": "integer", "minimum": 1, "maximum": 1000000 }
      },
      "additionalProperties": false
    },
    "usageLog": { "type": "string", "minLength": 1 },
    "usagestat": {
      "type": "object",
      "properties": {
        "url": { "type": "string", "format": "uri" },
        "tokenRef": {
          "anyOf": [
            {
              "type": "object",
              "properties": {
                "env": {
                  "type": "string",
                  "pattern": "^[A-Za-z_][A-Za-z0-9_]{0,127}$"
                }
              },
              "required": ["env"],
              "additionalProperties": false
            },
            {
              "type": "object",
              "properties": {
                "file": { "type": "string", "minLength": 1, "maxLength": 4096 }
              },
              "required": ["file"],
              "additionalProperties": false
            },
            {
              "type": "object",
              "properties": {
                "keychain": {
                  "type": "object",
                  "properties": {
                    "service": {
                      "type": "string",
                      "minLength": 1,
                      "maxLength": 128
                    },
                    "account": {
                      "type": "string",
                      "minLength": 1,
                      "maxLength": 128
                    }
                  },
                  "required": ["service", "account"],
                  "additionalProperties": false
                }
              },
              "required": ["keychain"],
              "additionalProperties": false
            }
          ]
        },
        "ingestionTimeoutMs": {
          "type": "integer",
          "minimum": 100,
          "maximum": 1500
        }
      },
      "required": ["url", "tokenRef"],
      "additionalProperties": false
    },
    "limits": {
      "type": "object",
      "properties": {
        "maxSteps": { "type": "integer", "minimum": 1, "maximum": 64 },
        "maxOutputTokens": {
          "type": "integer",
          "minimum": 1,
          "maximum": 65536
        },
        "idleTimeoutMs": {
          "type": "integer",
          "minimum": 0,
          "maximum": 2147483647
        },
        "maxAttempts": { "type": "integer", "minimum": 1, "maximum": 5 }
      },
      "additionalProperties": false
    },
    "concurrency": {
      "type": "object",
      "properties": {
        "total": { "type": "integer", "minimum": 1, "maximum": 100000 },
        "perSubject": { "type": "integer", "minimum": 1, "maximum": 100000 },
        "perAccount": { "type": "integer", "minimum": 1, "maximum": 100000 },
        "subjects": {
          "type": "object",
          "propertyNames": {
            "type": "string",
            "minLength": 1,
            "maxLength": 128
          },
          "additionalProperties": {
            "type": "integer",
            "minimum": 1,
            "maximum": 100000
          }
        },
        "accounts": {
          "type": "object",
          "propertyNames": {
            "type": "string",
            "pattern": "^[a-zA-Z0-9][a-zA-Z0-9._-]{0,79}$"
          },
          "additionalProperties": {
            "type": "integer",
            "minimum": 1,
            "maximum": 100000
          }
        },
        "queue": {
          "type": "object",
          "properties": {
            "total": { "type": "integer", "minimum": 1, "maximum": 100000 },
            "perSubject": { "type": "integer", "minimum": 1, "maximum": 100000 }
          },
          "required": ["total", "perSubject"],
          "additionalProperties": false
        }
      },
      "additionalProperties": false
    },
    "resources": {
      "type": "object",
      "properties": {
        "default": {
          "type": "object",
          "properties": {
            "maxTokens": {
              "type": "integer",
              "minimum": 1,
              "maximum": 9007199254740991
            },
            "maxCostUsd": { "type": "number", "exclusiveMinimum": 0 },
            "unknownUsage": { "type": "string", "enum": ["reject", "allow"] }
          },
          "required": ["unknownUsage"],
          "additionalProperties": false
        },
        "subjects": {
          "type": "object",
          "propertyNames": {
            "type": "string",
            "minLength": 1,
            "maxLength": 128
          },
          "additionalProperties": {
            "type": "object",
            "properties": {
              "maxTokens": {
                "type": "integer",
                "minimum": 1,
                "maximum": 9007199254740991
              },
              "maxCostUsd": { "type": "number", "exclusiveMinimum": 0 },
              "unknownUsage": { "type": "string", "enum": ["reject", "allow"] }
            },
            "required": ["unknownUsage"],
            "additionalProperties": false
          }
        },
        "accounts": {
          "type": "object",
          "propertyNames": {
            "type": "string",
            "pattern": "^[a-zA-Z0-9][a-zA-Z0-9._-]{0,79}$"
          },
          "additionalProperties": {
            "type": "object",
            "properties": {
              "maxTokens": {
                "type": "integer",
                "minimum": 1,
                "maximum": 9007199254740991
              },
              "maxCostUsd": { "type": "number", "exclusiveMinimum": 0 },
              "unknownUsage": { "type": "string", "enum": ["reject", "allow"] }
            },
            "required": ["unknownUsage"],
            "additionalProperties": false
          }
        }
      },
      "additionalProperties": false
    }
  },
  "required": ["version", "providers"],
  "additionalProperties": false,
  "$defs": {
    "__schema0": {
      "anyOf": [
        { "type": "string" },
        { "type": "number" },
        { "type": "boolean" },
        { "type": "null" },
        { "type": "array", "items": { "$ref": "#/$defs/__schema0" } },
        {
          "type": "object",
          "propertyNames": { "type": "string" },
          "additionalProperties": { "$ref": "#/$defs/__schema0" }
        }
      ]
    }
  }
}
