{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "title": "SumWise Compute v1 body schemas",
  "description": "Authoritative private-alpha Draft schemas for the POST /v1/evaluate request, success bodies, and deliverable problem bodies. HTTP framing and headers are defined by the companion OpenAPI document and REST Integration Guide.",
  "$comment": "No $id is assigned because these source-controlled artifacts do not yet have an authoritative public publication URI.",
  "$defs": {
    "EvaluateRequest": {
      "title": "Evaluate request",
      "description": "A closed request containing one expression string. The complete serialized UTF-8 HTTP body, not the logical string length, is limited to 4096 bytes inclusive. The admitted grammar and nine supported functions are defined in docs/compute/REST_INTEGRATION_GUIDE.md.",
      "type": "object",
      "properties": {
        "expression": {
          "type": "string",
          "description": "One decoded ASCII SumWise Compute v1 expression. The aggregation functions sum, mean, min, and max accept 1 through 30 arguments. The scalar utilities abs, sign, floor, ceil, and trunc accept exactly one argument. See the REST Integration Guide for the normative expression grammar and wire-level JSON rules.",
          "pattern": "^[\\u0000-\\u007E]*$"
        }
      },
      "required": ["expression"],
      "additionalProperties": false
    },
    "EngineVersion": {
      "title": "Engine version",
      "description": "Immutable process-level strict-SemVer engine behavior identity. A particular observed development label is not frozen by the API contract.",
      "type": "string",
      "minLength": 5,
      "maxLength": 64,
      "pattern": "^(?:0|[1-9][0-9]*)\\.(?:0|[1-9][0-9]*)\\.(?:0|[1-9][0-9]*)(?:-(?:(?:0|[1-9][0-9]*)|[0-9A-Za-z-]*[A-Za-z-][0-9A-Za-z-]*)(?:\\.(?:(?:0|[1-9][0-9]*)|[0-9A-Za-z-]*[A-Za-z-][0-9A-Za-z-]*))*)?(?:\\+[0-9A-Za-z-]+(?:\\.[0-9A-Za-z-]+)*)?$"
    },
    "CanonicalIntegerString": {
      "title": "Canonical integer string",
      "type": "string",
      "pattern": "^(?:0|-?[1-9][0-9]*)$"
    },
    "CanonicalNonzeroIntegerString": {
      "title": "Canonical nonzero integer string",
      "type": "string",
      "pattern": "^-?[1-9][0-9]*$"
    },
    "CanonicalDenominatorString": {
      "title": "Canonical denominator string",
      "type": "string",
      "pattern": "^(?:[2-9]|[1-9][0-9]+)$"
    },
    "CanonicalRationalString": {
      "title": "Canonical rational string",
      "description": "A reduced nonzero numerator and positive denominator greater than one. It equals value.numerator + '/' + value.denominator.",
      "type": "string",
      "pattern": "^-?[1-9][0-9]*/(?:[2-9]|[1-9][0-9]+)$"
    },
    "CanonicalRealString": {
      "title": "Canonical finite binary64 string",
      "description": "Locale-independent finite binary64 text using a dot decimal separator and optional lowercase-e exponent. The authoritative invariant additionally requires the shortest same-build exact binary64 round-trip representation; positive zero is '0' and negative zero is '-0'.",
      "type": "string",
      "pattern": "^-?(?:0|[1-9][0-9]*)(?:\\.[0-9]*[1-9])?(?:e-?[1-9][0-9]*)?$"
    },
    "IntegerResult": {
      "title": "Exact integer result",
      "description": "text and value are byte-for-byte equal canonical integer strings.",
      "type": "object",
      "properties": {
        "type": {"const": "integer"},
        "text": {"$ref": "#/$defs/CanonicalIntegerString"},
        "exactness": {"const": "exact"},
        "value": {"$ref": "#/$defs/CanonicalIntegerString"}
      },
      "required": ["type", "text", "exactness", "value"],
      "additionalProperties": false
    },
    "RationalComponents": {
      "title": "Exact rational components",
      "type": "object",
      "properties": {
        "numerator": {"$ref": "#/$defs/CanonicalNonzeroIntegerString"},
        "denominator": {"$ref": "#/$defs/CanonicalDenominatorString"}
      },
      "required": ["numerator", "denominator"],
      "additionalProperties": false
    },
    "RationalResult": {
      "title": "Exact rational result",
      "description": "text equals value.numerator + '/' + value.denominator. Components are reduced, the denominator is positive and greater than one, and zero or denominator-one outcomes use the integer family instead.",
      "type": "object",
      "properties": {
        "type": {"const": "rational"},
        "text": {"$ref": "#/$defs/CanonicalRationalString"},
        "exactness": {"const": "exact"},
        "value": {"$ref": "#/$defs/RationalComponents"}
      },
      "required": ["type", "text", "exactness", "value"],
      "additionalProperties": false
    },
    "RealResult": {
      "title": "Approximate real result",
      "description": "text and value are byte-for-byte equal canonical finite binary64 strings.",
      "type": "object",
      "properties": {
        "type": {"const": "real"},
        "text": {"$ref": "#/$defs/CanonicalRealString"},
        "exactness": {"const": "approximate"},
        "value": {"$ref": "#/$defs/CanonicalRealString"}
      },
      "required": ["type", "text", "exactness", "value"],
      "additionalProperties": false
    },
    "IntegerSuccessResponse": {
      "title": "Integer success response",
      "type": "object",
      "properties": {
        "ok": {"const": true},
        "api_version": {"const": "v1"},
        "operation": {"const": "evaluate"},
        "engine_version": {"$ref": "#/$defs/EngineVersion"},
        "result": {"$ref": "#/$defs/IntegerResult"}
      },
      "required": ["ok", "api_version", "operation", "engine_version", "result"],
      "additionalProperties": false
    },
    "RationalSuccessResponse": {
      "title": "Rational success response",
      "type": "object",
      "properties": {
        "ok": {"const": true},
        "api_version": {"const": "v1"},
        "operation": {"const": "evaluate"},
        "engine_version": {"$ref": "#/$defs/EngineVersion"},
        "result": {"$ref": "#/$defs/RationalResult"}
      },
      "required": ["ok", "api_version", "operation", "engine_version", "result"],
      "additionalProperties": false
    },
    "RealSuccessResponse": {
      "title": "Real success response",
      "type": "object",
      "properties": {
        "ok": {"const": true},
        "api_version": {"const": "v1"},
        "operation": {"const": "evaluate"},
        "engine_version": {"$ref": "#/$defs/EngineVersion"},
        "result": {"$ref": "#/$defs/RealResult"}
      },
      "required": ["ok", "api_version", "operation", "engine_version", "result"],
      "additionalProperties": false
    },
    "SuccessResponse": {
      "title": "Evaluate success response",
      "description": "Closed, unambiguous union discriminated by result.type and result.exactness.",
      "oneOf": [
        {"$ref": "#/$defs/IntegerSuccessResponse"},
        {"$ref": "#/$defs/RationalSuccessResponse"},
        {"$ref": "#/$defs/RealSuccessResponse"}
      ]
    },
    "ServiceProblem": {
      "title": "Service problem response",
      "type": "object",
      "properties": {
        "type": {"type": "string"},
        "title": {"type": "string"},
        "status": {"type": "integer"},
        "detail": {"type": "string"},
        "code": {"type": "string"}
      },
      "required": ["type", "title", "status", "detail", "code"],
      "additionalProperties": false,
      "oneOf": [
        {"properties": {"type": {"const": "https://sumwisecalc.com/compute/problems/v1/service/invalid-http-request"}, "title": {"const": "Invalid HTTP request"}, "status": {"const": 400}, "detail": {"const": "The HTTP request framing is invalid for this service."}, "code": {"const": "invalid_http_request"}}},
        {"properties": {"type": {"const": "https://sumwisecalc.com/compute/problems/v1/service/route-not-found"}, "title": {"const": "Route not found"}, "status": {"const": 404}, "detail": {"const": "The requested service route was not found."}, "code": {"const": "route_not_found"}}},
        {"properties": {"type": {"const": "https://sumwisecalc.com/compute/problems/v1/service/method-not-allowed"}, "title": {"const": "Method not allowed"}, "status": {"const": 405}, "detail": {"const": "The requested service route accepts POST only."}, "code": {"const": "method_not_allowed"}}},
        {"properties": {"type": {"const": "https://sumwisecalc.com/compute/problems/v1/service/content-length-required"}, "title": {"const": "Content length required"}, "status": {"const": 411}, "detail": {"const": "A single valid Content-Length header is required."}, "code": {"const": "content_length_required"}}},
        {"properties": {"type": {"const": "https://sumwisecalc.com/compute/problems/v1/service/request-body-too-large"}, "title": {"const": "Request body too large"}, "status": {"const": 413}, "detail": {"const": "The request body exceeds the private service limit."}, "code": {"const": "request_body_too_large"}}},
        {"properties": {"type": {"const": "https://sumwisecalc.com/compute/problems/v1/service/unsupported-media-type"}, "title": {"const": "Unsupported media type"}, "status": {"const": 415}, "detail": {"const": "The service accepts application/json with UTF-8 only."}, "code": {"const": "unsupported_media_type"}}},
        {"properties": {"type": {"const": "https://sumwisecalc.com/compute/service/problems/v1/authentication-required"}, "title": {"const": "Authentication required"}, "status": {"const": 401}, "detail": {"const": "A valid private-alpha API key is required."}, "code": {"const": "authentication_required"}}},
        {"properties": {"type": {"const": "https://sumwisecalc.com/compute/service/problems/v1/concurrent-request-limit-exceeded"}, "title": {"const": "Concurrent request limit exceeded"}, "status": {"const": 429}, "detail": {"const": "This API key already has a request in progress."}, "code": {"const": "concurrent_request_limit_exceeded"}}},
        {"properties": {"type": {"const": "https://sumwisecalc.com/compute/service/problems/v1/rate-limit-exceeded"}, "title": {"const": "Rate limit exceeded"}, "status": {"const": 429}, "detail": {"const": "The fixed accepted-request rate limit is exhausted."}, "code": {"const": "rate_limit_exceeded"}}},
        {"properties": {"type": {"const": "https://sumwisecalc.com/compute/service/problems/v1/quota-exhausted"}, "title": {"const": "Compute quota exhausted"}, "status": {"const": 429}, "detail": {"const": "The current Compute quota is exhausted."}, "code": {"const": "quota_exhausted"}}},
        {"properties": {"type": {"const": "https://sumwisecalc.com/compute/problems/v1/service/service-busy"}, "title": {"const": "Service busy"}, "status": {"const": 503}, "detail": {"const": "The private service is already processing its single allowed request."}, "code": {"const": "service_busy"}}},
        {"properties": {"type": {"const": "https://sumwisecalc.com/compute/service/problems/v1/service-unavailable"}, "title": {"const": "Service unavailable"}, "status": {"const": 503}, "detail": {"const": "The service is temporarily unavailable."}, "code": {"const": "service_unavailable"}}}
      ]
    },
    "ComputeProblem": {
      "title": "Compute evaluation problem response",
      "type": "object",
      "properties": {
        "type": {"type": "string"},
        "title": {"type": "string"},
        "status": {"type": "integer"},
        "detail": {"type": "string"},
        "code": {"type": "string"},
        "api_version": {"const": "v1"},
        "operation": {"const": "evaluate"}
      },
      "required": ["type", "title", "status", "detail", "code", "api_version", "operation"],
      "additionalProperties": false,
      "oneOf": [
        {"properties": {"type": {"const": "https://sumwisecalc.com/compute/problems/v1/evaluate/invalid-request"}, "title": {"const": "Invalid request"}, "status": {"const": 422}, "detail": {"const": "The request body does not match the Evaluate request contract."}, "code": {"const": "invalid_request"}}},
        {"properties": {"type": {"const": "https://sumwisecalc.com/compute/problems/v1/evaluate/expression-parse-error"}, "title": {"const": "Expression parse error"}, "status": {"const": 422}, "detail": {"const": "The expression could not be parsed by the supported Evaluate grammar."}, "code": {"const": "expression_parse_error"}}},
        {"properties": {"type": {"const": "https://sumwisecalc.com/compute/problems/v1/evaluate/unbound-symbol"}, "title": {"const": "Unbound symbol"}, "status": {"const": 422}, "detail": {"const": "The expression contains an identifier that is not available as a public constant."}, "code": {"const": "unbound_symbol"}}},
        {"properties": {"type": {"const": "https://sumwisecalc.com/compute/problems/v1/evaluate/unknown-function"}, "title": {"const": "Unknown function"}, "status": {"const": 422}, "detail": {"const": "The expression names a function that is not recognized by this API version."}, "code": {"const": "unknown_function"}}},
        {"properties": {"type": {"const": "https://sumwisecalc.com/compute/problems/v1/evaluate/operation-not-allowed"}, "title": {"const": "Operation not allowed"}, "status": {"const": 422}, "detail": {"const": "The expression uses an operation that is not allowed by this Evaluate API version."}, "code": {"const": "operation_not_allowed"}}},
        {"properties": {"type": {"const": "https://sumwisecalc.com/compute/problems/v1/evaluate/unsupported-expression"}, "title": {"const": "Unsupported expression"}, "status": {"const": 422}, "detail": {"const": "The expression is valid but is not supported by this Evaluate API version."}, "code": {"const": "unsupported_expression"}}},
        {"properties": {"type": {"const": "https://sumwisecalc.com/compute/problems/v1/evaluate/domain-error"}, "title": {"const": "Domain error"}, "status": {"const": 422}, "detail": {"const": "The expression is outside the supported mathematical domain."}, "code": {"const": "domain_error"}}},
        {"properties": {"type": {"const": "https://sumwisecalc.com/compute/problems/v1/evaluate/numeric-overflow"}, "title": {"const": "Numeric overflow"}, "status": {"const": 422}, "detail": {"const": "Evaluation exceeded the supported finite numeric range."}, "code": {"const": "numeric_overflow"}}},
        {"properties": {"type": {"const": "https://sumwisecalc.com/compute/problems/v1/evaluate/computation-limit-exceeded"}, "title": {"const": "Computation limit exceeded"}, "status": {"const": 422}, "detail": {"const": "The request exceeded the computation limits for this API version."}, "code": {"const": "computation_limit_exceeded"}}},
        {"properties": {"type": {"const": "https://sumwisecalc.com/compute/problems/v1/evaluate/result-limit-exceeded"}, "title": {"const": "Result limit exceeded"}, "status": {"const": 422}, "detail": {"const": "The result exceeded the output limits for this API version."}, "code": {"const": "result_limit_exceeded"}}},
        {"properties": {"type": {"const": "https://sumwisecalc.com/compute/problems/v1/evaluate/computation-timeout"}, "title": {"const": "Computation timeout"}, "status": {"const": 504}, "detail": {"const": "The computation did not complete within the service time limit."}, "code": {"const": "computation_timeout"}}},
        {"properties": {"type": {"const": "https://sumwisecalc.com/compute/problems/v1/evaluate/internal-error"}, "title": {"const": "Internal error"}, "status": {"const": 500}, "detail": {"const": "The service could not safely produce a result."}, "code": {"const": "internal_error"}}}
      ]
    },
    "ProblemResponse": {
      "title": "Deliverable problem response",
      "oneOf": [
        {"$ref": "#/$defs/ServiceProblem"},
        {"$ref": "#/$defs/ComputeProblem"}
      ]
    },
    "BadRequestProblem": {"allOf": [{"$ref": "#/$defs/ServiceProblem"}, {"properties": {"code": {"const": "invalid_http_request"}}}]},
    "AuthenticationProblem": {"allOf": [{"$ref": "#/$defs/ServiceProblem"}, {"properties": {"code": {"const": "authentication_required"}}}]},
    "NotFoundProblem": {"allOf": [{"$ref": "#/$defs/ServiceProblem"}, {"properties": {"code": {"const": "route_not_found"}}}]},
    "MethodNotAllowedProblem": {"allOf": [{"$ref": "#/$defs/ServiceProblem"}, {"properties": {"code": {"const": "method_not_allowed"}}}]},
    "LengthRequiredProblem": {"allOf": [{"$ref": "#/$defs/ServiceProblem"}, {"properties": {"code": {"const": "content_length_required"}}}]},
    "PayloadTooLargeProblem": {"allOf": [{"$ref": "#/$defs/ServiceProblem"}, {"properties": {"code": {"const": "request_body_too_large"}}}]},
    "UnsupportedMediaTypeProblem": {"allOf": [{"$ref": "#/$defs/ServiceProblem"}, {"properties": {"code": {"const": "unsupported_media_type"}}}]},
    "UnprocessableEntityProblem": {
      "allOf": [
        {"$ref": "#/$defs/ComputeProblem"},
        {"properties": {"code": {"enum": ["invalid_request", "expression_parse_error", "unbound_symbol", "unknown_function", "operation_not_allowed", "unsupported_expression", "domain_error", "numeric_overflow", "computation_limit_exceeded", "result_limit_exceeded"]}}}
      ]
    },
    "TooManyRequestsProblem": {
      "allOf": [
        {"$ref": "#/$defs/ServiceProblem"},
        {"properties": {"code": {"enum": ["concurrent_request_limit_exceeded", "rate_limit_exceeded", "quota_exhausted"]}}}
      ]
    },
    "InternalErrorProblem": {"allOf": [{"$ref": "#/$defs/ComputeProblem"}, {"properties": {"code": {"const": "internal_error"}}}]},
    "ServiceUnavailableProblem": {
      "allOf": [
        {"$ref": "#/$defs/ServiceProblem"},
        {"properties": {"code": {"enum": ["service_busy", "service_unavailable"]}}}
      ]
    },
    "GatewayTimeoutProblem": {"allOf": [{"$ref": "#/$defs/ComputeProblem"}, {"properties": {"code": {"const": "computation_timeout"}}}]}
  },
  "oneOf": [
    {"$ref": "#/$defs/EvaluateRequest"},
    {"$ref": "#/$defs/SuccessResponse"},
    {"$ref": "#/$defs/ProblemResponse"}
  ]
}
