12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364(** Type-safe heterogeneous key-value store using extensible GADTs.
Uses {!Obj.Extension_constructor.id} to identify keys at runtime and
{!Obj.magic} for type recovery. This is type-safe by construction:
two extensible variant constructors share the same [Extension_constructor.id]
if and only if they are the same constructor, which guarantees they carry
the same type parameter. This is the standard OCaml pattern for extensible
GADTs, used by {!Printexc} and other stdlib modules.
Future: OCaml 5.1+ [Type.eq] would provide a first-class type equality
witness, eliminating the need for [Obj.magic]. *)type_key=..typeentry=Entry:'akey*'a->entrytypet=entrylistletempty=[]letset(typea)(k:akey)(v:a)(opts:t):t=letkid=Obj.Extension_constructor.id(Obj.Extension_constructor.of_valk)inletreplaced=reffalseinletopts'=List.filter_map(fun(Entry(k',_)ase)->letkid'=Obj.Extension_constructor.id(Obj.Extension_constructor.of_valk')inifInt.equalkidkid'thenbeginreplaced:=true;Some(Entry(k,v))endelseSomee)optsinif!replacedthenopts'elseEntry(k,v)::opts(* NOTE on Obj.magic: This is the standard pattern for extensible GADT
existentials in OCaml. When two extensible variant constructors have the
same Extension_constructor.id, they are the same constructor and thus
carry the same type parameter. The Obj.magic is therefore type-safe.
This is the same approach used by Printexc and other stdlib modules. *)letfind(typea)(k:akey)(opts:t):aoption=letkid=Obj.Extension_constructor.id(Obj.Extension_constructor.of_valk)inletrecgo=function|[]->None|Entry(k',v)::rest->letkid'=Obj.Extension_constructor.id(Obj.Extension_constructor.of_valk')inifInt.equalkid'kidthenSome(Obj.magicv:a)elsegorestingooptsletfind_exnkopts=matchfindkoptswith|Somev->v|None->raiseNot_found(** Raw provider metadata from upstream re-submissions.
Stores [Record<string, Record<string, JsonValue>>] — each provider
reads its own namespace (e.g. ["anthropic"]). *)type_key+=Provider_metadata:Yojson.Basic.tkeyletof_provider_metadatajson=setProvider_metadatajsonemptyletprovider_metadataopts=findProvider_metadataopts