hyf

Context-aware query service for Radroots
git clone https://radroots.dev/git/hyf.git
Log | Files | Refs | README | LICENSE

buyer_request_match.request.schema.json (16070B)


      1 {
      2   "$schema": "https://json-schema.org/draft/2020-12/schema",
      3   "$id": "hyf_ops_v2/buyer_request_match.request.schema.json",
      4   "title": "hyf_ops_v2 buyer_request.match strict request (ADR-0025 D45 CB01-CB04)",
      5   "$comment": "Corrected versioned operation contract (ADR-0026 D46 CR02, ADR-0027 D47 BP01). Consumes the typed reviewed need, authorized snapshots and coverage; no flattened product_phrase/unreserved_value/scale shortcut. Evidence is the closed span|record_field union. snapshot.price binds the existing scaled money representation (state/amount/scale/currency/basis) distinct from the reported-quantity decimal projection; the optional fees family is the separate money-schema family.",
      6   "type": "object",
      7   "properties": {
      8     "version": {
      9       "type": "integer",
     10       "const": 1
     11     },
     12     "request_id": {
     13       "type": "string",
     14       "minLength": 1
     15     },
     16     "trace_id": {
     17       "type": "string",
     18       "minLength": 1
     19     },
     20     "capability": {
     21       "type": "string",
     22       "const": "buyer_request.match"
     23     },
     24     "context": {
     25       "$ref": "#/$defs/buyer_context"
     26     },
     27     "input": {
     28       "$ref": "#/$defs/match_input"
     29     }
     30   },
     31   "required": ["version", "request_id", "capability", "context", "input"],
     32   "additionalProperties": false,
     33   "$defs": {
     34     "versions": {
     35       "type": "object",
     36       "properties": {
     37         "schema": {"type": "string", "const": "hyf_ops_v2"},
     38         "taxonomy": {"type": "string", "minLength": 1},
     39         "normalization": {"type": "string", "minLength": 1},
     40         "review_policy": {"type": "string", "minLength": 1},
     41         "ranking_policy": {"type": "string", "minLength": 1},
     42         "question_bundle": {"type": "string", "minLength": 1},
     43         "model": {"type": "string", "minLength": 1}
     44       },
     45       "required": [
     46         "schema",
     47         "taxonomy",
     48         "normalization",
     49         "review_policy",
     50         "ranking_policy",
     51         "question_bundle",
     52         "model"
     53       ],
     54       "additionalProperties": false
     55     },
     56     "buyer_context": {
     57       "type": "object",
     58       "properties": {
     59         "consumer": {"type": "string", "minLength": 1},
     60         "execution_mode_preference": {
     61           "type": "string",
     62           "enum": ["deterministic", "assisted"]
     63         },
     64         "deadline_ms": {"type": "integer", "minimum": 1},
     65         "evaluation_time": {"type": "string", "minLength": 1},
     66         "timezone": {"type": "string", "minLength": 1},
     67         "locale": {"type": "string", "minLength": 1},
     68         "versions": {"$ref": "#/$defs/versions"},
     69         "return_provenance": {"type": "boolean"},
     70         "actor_id": {"type": "string", "minLength": 1}
     71       },
     72       "required": ["evaluation_time", "versions", "actor_id"],
     73       "additionalProperties": false
     74     },
     75     "evidence_span": {
     76       "type": "object",
     77       "properties": {
     78         "kind": {"type": "string", "const": "span"},
     79         "source_id": {"type": "string", "minLength": 1},
     80         "revision": {"type": "string", "minLength": 1},
     81         "start": {"type": "integer", "minimum": 0},
     82         "end": {"type": "integer", "minimum": 0},
     83         "method": {"type": "string", "minLength": 1}
     84       },
     85       "required": ["kind", "source_id", "revision", "start", "end", "method"],
     86       "additionalProperties": false
     87     },
     88     "record_field_evidence": {
     89       "type": "object",
     90       "properties": {
     91         "kind": {"type": "string", "const": "record_field"},
     92         "source_id": {"type": "string", "minLength": 1},
     93         "revision": {"type": "string", "minLength": 1},
     94         "record_id": {"type": "string", "minLength": 1},
     95         "field": {"type": "string", "minLength": 1},
     96         "method": {"type": "string", "const": "trusted_record"}
     97       },
     98       "required": ["kind", "source_id", "revision", "record_id", "field", "method"],
     99       "additionalProperties": false
    100     },
    101     "evidence_ref": {
    102       "oneOf": [
    103         {"$ref": "#/$defs/evidence_span"},
    104         {"$ref": "#/$defs/record_field_evidence"}
    105       ]
    106     },
    107     "reported_quantity": {
    108       "type": "object",
    109       "properties": {
    110         "state": {"type": "string", "enum": ["known", "unknown"]},
    111         "value": {
    112           "type": ["string", "null"],
    113           "pattern": "^-?(0|[1-9][0-9]*)(\\.[0-9]{1,9})?$"
    114         },
    115         "unit": {"type": ["string", "null"], "minLength": 1},
    116         "qualifier": {"type": "string", "enum": ["exact", "approximate"]}
    117       },
    118       "required": ["state", "qualifier"],
    119       "additionalProperties": false,
    120       "allOf": [
    121         {
    122           "if": {
    123             "properties": {"state": {"const": "unknown"}},
    124             "required": ["state"]
    125           },
    126           "then": {
    127             "properties": {"value": {"type": "null"}, "unit": {"type": "null"}}
    128           }
    129         },
    130         {
    131           "if": {
    132             "properties": {"state": {"const": "known"}},
    133             "required": ["state"]
    134           },
    135           "then": {
    136             "properties": {
    137               "value": {
    138                 "type": "string",
    139                 "pattern": "^-?(0|[1-9][0-9]*)(\\.[0-9]{1,9})?$"
    140               },
    141               "unit": {"type": "string", "minLength": 1}
    142             },
    143             "required": ["value", "unit"]
    144           }
    145         }
    146       ]
    147     },
    148     "product_ref": {
    149       "type": "object",
    150       "properties": {
    151         "phrase": {"type": "string", "minLength": 1},
    152         "catalogue_id": {"type": ["string", "null"], "minLength": 1},
    153         "resolution": {"type": "string", "enum": ["resolved", "unresolved"]}
    154       },
    155       "required": ["phrase", "catalogue_id", "resolution"],
    156       "additionalProperties": false
    157     },
    158     "taxonomy_bundle": {
    159       "type": "object",
    160       "properties": {
    161         "version": {"type": "string", "minLength": 1},
    162         "provenance": {"type": "string", "enum": ["synthetic", "host_supplied"]},
    163         "products": {
    164           "type": "array",
    165           "items": {
    166             "type": "object",
    167             "properties": {
    168               "catalogue_id": {"type": "string", "minLength": 1},
    169               "terms": {
    170                 "type": "array",
    171                 "minItems": 1,
    172                 "items": {"type": "string", "minLength": 1}
    173               }
    174             },
    175             "required": ["catalogue_id", "terms"],
    176             "additionalProperties": false
    177           }
    178         }
    179       },
    180       "required": ["version", "provenance", "products"],
    181       "additionalProperties": false
    182     },
    183     "normalization_bundle": {
    184       "type": "object",
    185       "properties": {
    186         "version": {"type": "string", "minLength": 1},
    187         "provenance": {"type": "string", "enum": ["synthetic", "host_supplied"]},
    188         "units": {
    189           "type": "array",
    190           "items": {
    191             "type": "object",
    192             "properties": {
    193               "unit": {"type": "string", "minLength": 1},
    194               "dimension": {
    195                 "type": "string",
    196                 "enum": ["mass", "volume", "count", "unknown"]
    197               }
    198             },
    199             "required": ["unit", "dimension"],
    200             "additionalProperties": false
    201           }
    202         },
    203         "conversions": {
    204           "type": "array",
    205           "items": {
    206             "type": "object",
    207             "properties": {
    208               "from_unit": {"type": "string", "minLength": 1},
    209               "to_unit": {"type": "string", "minLength": 1},
    210               "numerator": {"type": "string", "pattern": "^[1-9][0-9]*$"},
    211               "denominator": {"type": "string", "pattern": "^10*$"}
    212             },
    213             "required": ["from_unit", "to_unit", "numerator", "denominator"],
    214             "additionalProperties": false
    215           }
    216         },
    217         "packs": {
    218           "type": "array",
    219           "items": {
    220             "type": "object",
    221             "properties": {
    222               "product_id": {"type": "string", "minLength": 1},
    223               "pack_unit": {"type": "string", "minLength": 1},
    224               "inner_unit": {"type": "string", "minLength": 1},
    225               "value": {
    226                 "type": "string",
    227                 "pattern": "^(0|[1-9][0-9]*)(\\.[0-9]{1,9})?$",
    228                 "allOf": [
    229                   {"not": {"const": "0"}},
    230                   {"not": {"pattern": "^0(\\.0+)?$"}}
    231                 ]
    232               }
    233             },
    234             "required": ["product_id", "pack_unit", "inner_unit", "value"],
    235             "additionalProperties": false
    236           }
    237         }
    238       },
    239       "required": ["version", "provenance", "units", "conversions", "packs"],
    240       "additionalProperties": false
    241     },
    242     "references": {
    243       "type": "object",
    244       "properties": {
    245         "taxonomy": {"$ref": "#/$defs/taxonomy_bundle"},
    246         "normalization": {"$ref": "#/$defs/normalization_bundle"}
    247       },
    248       "required": ["taxonomy", "normalization"],
    249       "additionalProperties": false
    250     },
    251     "demand_line": {
    252       "type": "object",
    253       "properties": {
    254         "line_id": {"type": "string", "minLength": 1},
    255         "product": {"$ref": "#/$defs/product_ref"},
    256         "quantity": {"$ref": "#/$defs/reported_quantity"},
    257         "conditions": {
    258           "type": "array",
    259           "items": {
    260             "type": "object",
    261             "properties": {
    262               "kind": {
    263                 "type": "string",
    264                 "enum": [
    265                   "fulfillment",
    266                   "window",
    267                   "grade",
    268                   "price",
    269                   "attribute",
    270                   "substitution"
    271                 ]
    272               },
    273               "strength": {
    274                 "type": "string",
    275                 "enum": ["mandatory", "preferred", "excluded", "permitted"]
    276               },
    277               "value": {"type": ["string", "null"]},
    278               "evidence": {
    279                 "type": "array",
    280                 "items": {"$ref": "#/$defs/evidence_ref"}
    281               }
    282             },
    283             "required": ["kind", "strength", "evidence"],
    284             "additionalProperties": false
    285           }
    286         },
    287         "evidence": {
    288           "type": "array",
    289           "items": {"$ref": "#/$defs/evidence_ref"}
    290         },
    291         "review_required": {"type": "boolean"}
    292       },
    293       "required": [
    294         "line_id",
    295         "product",
    296         "quantity",
    297         "conditions",
    298         "evidence",
    299         "review_required"
    300       ],
    301       "additionalProperties": false
    302     },
    303     "need": {
    304       "type": "object",
    305       "properties": {
    306         "need_id": {"type": "string", "minLength": 1},
    307         "revision": {"type": "string", "minLength": 1},
    308         "actor_id": {"type": "string", "minLength": 1},
    309         "demand_lines": {
    310           "type": "array",
    311           "items": {"$ref": "#/$defs/demand_line"}
    312         },
    313         "partial_fulfillment": {
    314           "type": "string",
    315           "enum": ["allowed", "disallowed", "unstated"]
    316         }
    317       },
    318       "required": [
    319         "need_id",
    320         "revision",
    321         "actor_id",
    322         "demand_lines",
    323         "partial_fulfillment"
    324       ],
    325       "additionalProperties": false
    326     },
    327     "snapshot": {
    328       "type": "object",
    329       "properties": {
    330         "lot_id": {"type": "string", "minLength": 1},
    331         "revision": {"type": "string", "minLength": 1},
    332         "supplier_id": {"type": "string", "minLength": 1},
    333         "product": {"$ref": "#/$defs/product_ref"},
    334         "unreserved_quantity": {"$ref": "#/$defs/reported_quantity"},
    335         "attributes": {
    336           "type": "array",
    337           "items": {
    338             "type": "object",
    339             "properties": {
    340               "name": {"type": "string", "minLength": 1},
    341               "verified": {"type": "boolean"}
    342             },
    343             "required": ["name", "verified"],
    344             "additionalProperties": false
    345           }
    346         },
    347         "fulfillment": {
    348           "type": "object",
    349           "properties": {
    350             "method": {
    351               "type": "string",
    352               "enum": ["pickup", "delivery", "unspecified"]
    353             },
    354             "area": {"type": ["string", "null"]},
    355             "window": {"type": ["string", "null"]}
    356           },
    357           "required": ["method", "area", "window"],
    358           "additionalProperties": false
    359         },
    360         "price": {"$ref": "#/$defs/snapshot_price"}
    361       },
    362       "required": [
    363         "lot_id",
    364         "revision",
    365         "supplier_id",
    366         "product",
    367         "unreserved_quantity"
    368       ],
    369       "additionalProperties": false
    370     },
    371     "money_fee": {
    372       "type": "object",
    373       "properties": {
    374         "kind": {"type": "string", "minLength": 1},
    375         "amount": {
    376           "type": "string",
    377           "pattern": "^(0|[1-9][0-9]*)$",
    378           "maxLength": 19
    379         },
    380         "scale": {"type": "integer", "minimum": 0, "maximum": 9},
    381         "currency": {"type": "string", "minLength": 1}
    382       },
    383       "required": ["kind", "amount", "scale", "currency"],
    384       "additionalProperties": false
    385     },
    386     "money_fees": {
    387       "type": ["array", "null"],
    388       "items": {"$ref": "#/$defs/money_fee"}
    389     },
    390     "snapshot_price": {
    391       "type": "object",
    392       "properties": {
    393         "state": {"type": "string", "enum": ["known", "unknown"]},
    394         "amount": {
    395           "type": ["string", "null"],
    396           "pattern": "^(0|[1-9][0-9]*)$",
    397           "maxLength": 19
    398         },
    399         "scale": {
    400           "type": ["integer", "null"],
    401           "minimum": 0,
    402           "maximum": 9
    403         },
    404         "currency": {"type": ["string", "null"]},
    405         "basis": {
    406           "type": "string",
    407           "enum": ["per_unit", "per_pack", "per_order", "unknown"]
    408         },
    409         "fees": {"$ref": "#/$defs/money_fees"}
    410       },
    411       "required": ["state", "amount", "scale", "currency", "basis"],
    412       "additionalProperties": false,
    413       "$comment": "ADR-0027 D47 BP01 scaled money. known: amount is a canonical nonnegative integer string (checked coefficient 0..9223372036854775807, enforced by C009), scale 0..9, currency nonblank, basis per_unit|per_pack|per_order; zero is a known price. unknown: amount/scale/currency null and basis unknown; never interpreted as free. No conversion, FX, minimum-order or fee inference.",
    414       "allOf": [
    415         {
    416           "if": {
    417             "properties": {"state": {"const": "known"}},
    418             "required": ["state"]
    419           },
    420           "then": {
    421             "required": ["amount", "scale", "currency", "basis"],
    422             "properties": {
    423               "amount": {
    424                 "type": "string",
    425                 "pattern": "^(0|[1-9][0-9]*)$",
    426                 "maxLength": 19
    427               },
    428               "scale": {
    429                 "type": "integer",
    430                 "minimum": 0,
    431                 "maximum": 9
    432               },
    433               "currency": {"type": "string", "minLength": 1},
    434               "basis": {"enum": ["per_unit", "per_pack", "per_order"]}
    435             }
    436           }
    437         },
    438         {
    439           "if": {
    440             "properties": {"state": {"const": "unknown"}},
    441             "required": ["state"]
    442           },
    443           "then": {
    444             "required": ["amount", "scale", "currency", "basis"],
    445             "properties": {
    446               "amount": {"type": "null"},
    447               "scale": {"type": "null"},
    448               "currency": {"type": "null"},
    449               "basis": {"const": "unknown"}
    450             }
    451           }
    452         }
    453       ]
    454     },
    455     "coverage": {
    456       "type": "object",
    457       "properties": {
    458         "scope": {"type": "string", "enum": ["supplied_only"]},
    459         "truncated": {"type": "boolean"},
    460         "evaluated": {"type": "integer", "minimum": 0},
    461         "excluded": {"type": "integer", "minimum": 0}
    462       },
    463       "required": ["scope", "truncated"],
    464       "additionalProperties": false
    465     },
    466     "match_input": {
    467       "type": "object",
    468       "properties": {
    469         "need": {"$ref": "#/$defs/need"},
    470         "snapshots": {
    471           "type": "array",
    472           "items": {"$ref": "#/$defs/snapshot"}
    473         },
    474         "coverage": {"$ref": "#/$defs/coverage"},
    475         "references": {"$ref": "#/$defs/references"}
    476       },
    477       "required": ["need", "snapshots", "coverage", "references"],
    478       "additionalProperties": false
    479     }
    480   }
    481 }