Skip to content

Commit 1cb4648

Browse files
authored
Add a first pass at ClientRegistry (#1967)
This seems to work, but someone who understands rust, baml and all this stuff better than me should give it a look, would definitely love any feedback! Also, no rush to merge for tomorrow's release, I don't need it that badly, I mostly need the collector and streaming... <!-- ELLIPSIS_HIDDEN --> ---- > [!IMPORTANT] > Introduces `ClientRegistry` for managing client configurations, updating function signatures and encoding logic across Rust and Go components. > > - **Behavior**: > - Introduces `ClientRegistry` to manage client configurations in `ctypes.rs` and `lib.rs`. > - Updates `call_function_from_c_inner` in `lib.rs` to accept `client_registry`. > - Adds `WithClientRegistry` option in `client.go.j2` for Go client functions. > - **Models**: > - Adds `CFFIClientRegistry` and `CFFIClientProperty` in `cffi_generated.rs`. > - Updates `CFFIFunctionArguments` to include `client_registry` in `cffi.fbs`. > - **Go Code**: > - Adds `ClientRegistry` and related methods in `runtime.go`. > - Updates `encode.go` to handle `ClientRegistry` encoding. > - Modifies Go client functions in `client.go.j2` to accept `CallOptionFunc` for `ClientRegistry`. > - **Tests**: > - Updates `encode_test.go` to test `ClientRegistry` encoding. > - Modifies `test.go` to use `ClientRegistry` in integration tests. > > <sup>This description was created by </sup>[<img alt="Ellipsis" src="https://img.shields.io/badge/Ellipsis-blue?color=175173">](https://www.ellipsis.dev?ref=BoundaryML%2Fbaml&utm_source=github&utm_medium=referral)<sup> for 64a8d5b. You can [customize](https://app.ellipsis.dev/BoundaryML/settings/summaries) this summary. It will automatically update as commits are pushed.</sup> <!-- ELLIPSIS_HIDDEN -->
1 parent 3fdbfd0 commit 1cb4648

17 files changed

Lines changed: 2843 additions & 195 deletions

File tree

engine/language_client_cffi/src/cffi/cffi_generated.rs

Lines changed: 279 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5599,6 +5599,7 @@ impl<'a> flatbuffers::Follow<'a> for CFFIFunctionArguments<'a> {
55995599

56005600
impl<'a> CFFIFunctionArguments<'a> {
56015601
pub const VT_KWARGS: flatbuffers::VOffsetT = 4;
5602+
pub const VT_CLIENT_REGISTRY: flatbuffers::VOffsetT = 6;
56025603

56035604
#[inline]
56045605
pub unsafe fn init_from_table(table: flatbuffers::Table<'a>) -> Self {
@@ -5610,6 +5611,7 @@ impl<'a> CFFIFunctionArguments<'a> {
56105611
args: &'args CFFIFunctionArgumentsArgs<'args>
56115612
) -> flatbuffers::WIPOffset<CFFIFunctionArguments<'bldr>> {
56125613
let mut builder = CFFIFunctionArgumentsBuilder::new(_fbb);
5614+
if let Some(x) = args.client_registry { builder.add_client_registry(x); }
56135615
if let Some(x) = args.kwargs { builder.add_kwargs(x); }
56145616
builder.finish()
56155617
}
@@ -5622,6 +5624,13 @@ impl<'a> CFFIFunctionArguments<'a> {
56225624
// which contains a valid value in this slot
56235625
unsafe { self._tab.get::<flatbuffers::ForwardsUOffset<flatbuffers::Vector<'a, flatbuffers::ForwardsUOffset<CFFIMapEntry>>>>(CFFIFunctionArguments::VT_KWARGS, None)}
56245626
}
5627+
#[inline]
5628+
pub fn client_registry(&self) -> Option<CFFIClientRegistry<'a>> {
5629+
// Safety:
5630+
// Created from valid Table for this object
5631+
// which contains a valid value in this slot
5632+
unsafe { self._tab.get::<flatbuffers::ForwardsUOffset<CFFIClientRegistry>>(CFFIFunctionArguments::VT_CLIENT_REGISTRY, None)}
5633+
}
56255634
}
56265635

56275636
impl flatbuffers::Verifiable for CFFIFunctionArguments<'_> {
@@ -5632,18 +5641,21 @@ impl flatbuffers::Verifiable for CFFIFunctionArguments<'_> {
56325641
use self::flatbuffers::Verifiable;
56335642
v.visit_table(pos)?
56345643
.visit_field::<flatbuffers::ForwardsUOffset<flatbuffers::Vector<'_, flatbuffers::ForwardsUOffset<CFFIMapEntry>>>>("kwargs", Self::VT_KWARGS, false)?
5644+
.visit_field::<flatbuffers::ForwardsUOffset<CFFIClientRegistry>>("client_registry", Self::VT_CLIENT_REGISTRY, false)?
56355645
.finish();
56365646
Ok(())
56375647
}
56385648
}
56395649
pub struct CFFIFunctionArgumentsArgs<'a> {
56405650
pub kwargs: Option<flatbuffers::WIPOffset<flatbuffers::Vector<'a, flatbuffers::ForwardsUOffset<CFFIMapEntry<'a>>>>>,
5651+
pub client_registry: Option<flatbuffers::WIPOffset<CFFIClientRegistry<'a>>>,
56415652
}
56425653
impl<'a> Default for CFFIFunctionArgumentsArgs<'a> {
56435654
#[inline]
56445655
fn default() -> Self {
56455656
CFFIFunctionArgumentsArgs {
56465657
kwargs: None,
5658+
client_registry: None,
56475659
}
56485660
}
56495661
}
@@ -5658,6 +5670,10 @@ impl<'a: 'b, 'b> CFFIFunctionArgumentsBuilder<'a, 'b> {
56585670
self.fbb_.push_slot_always::<flatbuffers::WIPOffset<_>>(CFFIFunctionArguments::VT_KWARGS, kwargs);
56595671
}
56605672
#[inline]
5673+
pub fn add_client_registry(&mut self, client_registry: flatbuffers::WIPOffset<CFFIClientRegistry<'b >>) {
5674+
self.fbb_.push_slot_always::<flatbuffers::WIPOffset<CFFIClientRegistry>>(CFFIFunctionArguments::VT_CLIENT_REGISTRY, client_registry);
5675+
}
5676+
#[inline]
56615677
pub fn new(_fbb: &'b mut flatbuffers::FlatBufferBuilder<'a>) -> CFFIFunctionArgumentsBuilder<'a, 'b> {
56625678
let start = _fbb.start_table();
56635679
CFFIFunctionArgumentsBuilder {
@@ -5676,6 +5692,269 @@ impl core::fmt::Debug for CFFIFunctionArguments<'_> {
56765692
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
56775693
let mut ds = f.debug_struct("CFFIFunctionArguments");
56785694
ds.field("kwargs", &self.kwargs());
5695+
ds.field("client_registry", &self.client_registry());
5696+
ds.finish()
5697+
}
5698+
}
5699+
pub enum CFFIClientRegistryOffset {}
5700+
#[derive(Copy, Clone, PartialEq)]
5701+
5702+
pub struct CFFIClientRegistry<'a> {
5703+
pub _tab: flatbuffers::Table<'a>,
5704+
}
5705+
5706+
impl<'a> flatbuffers::Follow<'a> for CFFIClientRegistry<'a> {
5707+
type Inner = CFFIClientRegistry<'a>;
5708+
#[inline]
5709+
unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
5710+
Self { _tab: flatbuffers::Table::new(buf, loc) }
5711+
}
5712+
}
5713+
5714+
impl<'a> CFFIClientRegistry<'a> {
5715+
pub const VT_PRIMARY: flatbuffers::VOffsetT = 4;
5716+
pub const VT_CLIENTS: flatbuffers::VOffsetT = 6;
5717+
5718+
#[inline]
5719+
pub unsafe fn init_from_table(table: flatbuffers::Table<'a>) -> Self {
5720+
CFFIClientRegistry { _tab: table }
5721+
}
5722+
#[allow(unused_mut)]
5723+
pub fn create<'bldr: 'args, 'args: 'mut_bldr, 'mut_bldr>(
5724+
_fbb: &'mut_bldr mut flatbuffers::FlatBufferBuilder<'bldr>,
5725+
args: &'args CFFIClientRegistryArgs<'args>
5726+
) -> flatbuffers::WIPOffset<CFFIClientRegistry<'bldr>> {
5727+
let mut builder = CFFIClientRegistryBuilder::new(_fbb);
5728+
if let Some(x) = args.clients { builder.add_clients(x); }
5729+
if let Some(x) = args.primary { builder.add_primary(x); }
5730+
builder.finish()
5731+
}
5732+
5733+
5734+
#[inline]
5735+
pub fn primary(&self) -> Option<&'a str> {
5736+
// Safety:
5737+
// Created from valid Table for this object
5738+
// which contains a valid value in this slot
5739+
unsafe { self._tab.get::<flatbuffers::ForwardsUOffset<&str>>(CFFIClientRegistry::VT_PRIMARY, None)}
5740+
}
5741+
#[inline]
5742+
pub fn clients(&self) -> Option<flatbuffers::Vector<'a, flatbuffers::ForwardsUOffset<CFFIClientProperty<'a>>>> {
5743+
// Safety:
5744+
// Created from valid Table for this object
5745+
// which contains a valid value in this slot
5746+
unsafe { self._tab.get::<flatbuffers::ForwardsUOffset<flatbuffers::Vector<'a, flatbuffers::ForwardsUOffset<CFFIClientProperty>>>>(CFFIClientRegistry::VT_CLIENTS, None)}
5747+
}
5748+
}
5749+
5750+
impl flatbuffers::Verifiable for CFFIClientRegistry<'_> {
5751+
#[inline]
5752+
fn run_verifier(
5753+
v: &mut flatbuffers::Verifier, pos: usize
5754+
) -> Result<(), flatbuffers::InvalidFlatbuffer> {
5755+
use self::flatbuffers::Verifiable;
5756+
v.visit_table(pos)?
5757+
.visit_field::<flatbuffers::ForwardsUOffset<&str>>("primary", Self::VT_PRIMARY, false)?
5758+
.visit_field::<flatbuffers::ForwardsUOffset<flatbuffers::Vector<'_, flatbuffers::ForwardsUOffset<CFFIClientProperty>>>>("clients", Self::VT_CLIENTS, false)?
5759+
.finish();
5760+
Ok(())
5761+
}
5762+
}
5763+
pub struct CFFIClientRegistryArgs<'a> {
5764+
pub primary: Option<flatbuffers::WIPOffset<&'a str>>,
5765+
pub clients: Option<flatbuffers::WIPOffset<flatbuffers::Vector<'a, flatbuffers::ForwardsUOffset<CFFIClientProperty<'a>>>>>,
5766+
}
5767+
impl<'a> Default for CFFIClientRegistryArgs<'a> {
5768+
#[inline]
5769+
fn default() -> Self {
5770+
CFFIClientRegistryArgs {
5771+
primary: None,
5772+
clients: None,
5773+
}
5774+
}
5775+
}
5776+
5777+
pub struct CFFIClientRegistryBuilder<'a: 'b, 'b> {
5778+
fbb_: &'b mut flatbuffers::FlatBufferBuilder<'a>,
5779+
start_: flatbuffers::WIPOffset<flatbuffers::TableUnfinishedWIPOffset>,
5780+
}
5781+
impl<'a: 'b, 'b> CFFIClientRegistryBuilder<'a, 'b> {
5782+
#[inline]
5783+
pub fn add_primary(&mut self, primary: flatbuffers::WIPOffset<&'b str>) {
5784+
self.fbb_.push_slot_always::<flatbuffers::WIPOffset<_>>(CFFIClientRegistry::VT_PRIMARY, primary);
5785+
}
5786+
#[inline]
5787+
pub fn add_clients(&mut self, clients: flatbuffers::WIPOffset<flatbuffers::Vector<'b , flatbuffers::ForwardsUOffset<CFFIClientProperty<'b >>>>) {
5788+
self.fbb_.push_slot_always::<flatbuffers::WIPOffset<_>>(CFFIClientRegistry::VT_CLIENTS, clients);
5789+
}
5790+
#[inline]
5791+
pub fn new(_fbb: &'b mut flatbuffers::FlatBufferBuilder<'a>) -> CFFIClientRegistryBuilder<'a, 'b> {
5792+
let start = _fbb.start_table();
5793+
CFFIClientRegistryBuilder {
5794+
fbb_: _fbb,
5795+
start_: start,
5796+
}
5797+
}
5798+
#[inline]
5799+
pub fn finish(self) -> flatbuffers::WIPOffset<CFFIClientRegistry<'a>> {
5800+
let o = self.fbb_.end_table(self.start_);
5801+
flatbuffers::WIPOffset::new(o.value())
5802+
}
5803+
}
5804+
5805+
impl core::fmt::Debug for CFFIClientRegistry<'_> {
5806+
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
5807+
let mut ds = f.debug_struct("CFFIClientRegistry");
5808+
ds.field("primary", &self.primary());
5809+
ds.field("clients", &self.clients());
5810+
ds.finish()
5811+
}
5812+
}
5813+
pub enum CFFIClientPropertyOffset {}
5814+
#[derive(Copy, Clone, PartialEq)]
5815+
5816+
pub struct CFFIClientProperty<'a> {
5817+
pub _tab: flatbuffers::Table<'a>,
5818+
}
5819+
5820+
impl<'a> flatbuffers::Follow<'a> for CFFIClientProperty<'a> {
5821+
type Inner = CFFIClientProperty<'a>;
5822+
#[inline]
5823+
unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
5824+
Self { _tab: flatbuffers::Table::new(buf, loc) }
5825+
}
5826+
}
5827+
5828+
impl<'a> CFFIClientProperty<'a> {
5829+
pub const VT_NAME: flatbuffers::VOffsetT = 4;
5830+
pub const VT_PROVIDER: flatbuffers::VOffsetT = 6;
5831+
pub const VT_RETRY_POLICY: flatbuffers::VOffsetT = 8;
5832+
pub const VT_OPTIONS: flatbuffers::VOffsetT = 10;
5833+
5834+
#[inline]
5835+
pub unsafe fn init_from_table(table: flatbuffers::Table<'a>) -> Self {
5836+
CFFIClientProperty { _tab: table }
5837+
}
5838+
#[allow(unused_mut)]
5839+
pub fn create<'bldr: 'args, 'args: 'mut_bldr, 'mut_bldr>(
5840+
_fbb: &'mut_bldr mut flatbuffers::FlatBufferBuilder<'bldr>,
5841+
args: &'args CFFIClientPropertyArgs<'args>
5842+
) -> flatbuffers::WIPOffset<CFFIClientProperty<'bldr>> {
5843+
let mut builder = CFFIClientPropertyBuilder::new(_fbb);
5844+
if let Some(x) = args.options { builder.add_options(x); }
5845+
if let Some(x) = args.retry_policy { builder.add_retry_policy(x); }
5846+
if let Some(x) = args.provider { builder.add_provider(x); }
5847+
if let Some(x) = args.name { builder.add_name(x); }
5848+
builder.finish()
5849+
}
5850+
5851+
5852+
#[inline]
5853+
pub fn name(&self) -> Option<&'a str> {
5854+
// Safety:
5855+
// Created from valid Table for this object
5856+
// which contains a valid value in this slot
5857+
unsafe { self._tab.get::<flatbuffers::ForwardsUOffset<&str>>(CFFIClientProperty::VT_NAME, None)}
5858+
}
5859+
#[inline]
5860+
pub fn provider(&self) -> Option<&'a str> {
5861+
// Safety:
5862+
// Created from valid Table for this object
5863+
// which contains a valid value in this slot
5864+
unsafe { self._tab.get::<flatbuffers::ForwardsUOffset<&str>>(CFFIClientProperty::VT_PROVIDER, None)}
5865+
}
5866+
#[inline]
5867+
pub fn retry_policy(&self) -> Option<&'a str> {
5868+
// Safety:
5869+
// Created from valid Table for this object
5870+
// which contains a valid value in this slot
5871+
unsafe { self._tab.get::<flatbuffers::ForwardsUOffset<&str>>(CFFIClientProperty::VT_RETRY_POLICY, None)}
5872+
}
5873+
#[inline]
5874+
pub fn options(&self) -> Option<flatbuffers::Vector<'a, flatbuffers::ForwardsUOffset<CFFIMapEntry<'a>>>> {
5875+
// Safety:
5876+
// Created from valid Table for this object
5877+
// which contains a valid value in this slot
5878+
unsafe { self._tab.get::<flatbuffers::ForwardsUOffset<flatbuffers::Vector<'a, flatbuffers::ForwardsUOffset<CFFIMapEntry>>>>(CFFIClientProperty::VT_OPTIONS, None)}
5879+
}
5880+
}
5881+
5882+
impl flatbuffers::Verifiable for CFFIClientProperty<'_> {
5883+
#[inline]
5884+
fn run_verifier(
5885+
v: &mut flatbuffers::Verifier, pos: usize
5886+
) -> Result<(), flatbuffers::InvalidFlatbuffer> {
5887+
use self::flatbuffers::Verifiable;
5888+
v.visit_table(pos)?
5889+
.visit_field::<flatbuffers::ForwardsUOffset<&str>>("name", Self::VT_NAME, false)?
5890+
.visit_field::<flatbuffers::ForwardsUOffset<&str>>("provider", Self::VT_PROVIDER, false)?
5891+
.visit_field::<flatbuffers::ForwardsUOffset<&str>>("retry_policy", Self::VT_RETRY_POLICY, false)?
5892+
.visit_field::<flatbuffers::ForwardsUOffset<flatbuffers::Vector<'_, flatbuffers::ForwardsUOffset<CFFIMapEntry>>>>("options", Self::VT_OPTIONS, false)?
5893+
.finish();
5894+
Ok(())
5895+
}
5896+
}
5897+
pub struct CFFIClientPropertyArgs<'a> {
5898+
pub name: Option<flatbuffers::WIPOffset<&'a str>>,
5899+
pub provider: Option<flatbuffers::WIPOffset<&'a str>>,
5900+
pub retry_policy: Option<flatbuffers::WIPOffset<&'a str>>,
5901+
pub options: Option<flatbuffers::WIPOffset<flatbuffers::Vector<'a, flatbuffers::ForwardsUOffset<CFFIMapEntry<'a>>>>>,
5902+
}
5903+
impl<'a> Default for CFFIClientPropertyArgs<'a> {
5904+
#[inline]
5905+
fn default() -> Self {
5906+
CFFIClientPropertyArgs {
5907+
name: None,
5908+
provider: None,
5909+
retry_policy: None,
5910+
options: None,
5911+
}
5912+
}
5913+
}
5914+
5915+
pub struct CFFIClientPropertyBuilder<'a: 'b, 'b> {
5916+
fbb_: &'b mut flatbuffers::FlatBufferBuilder<'a>,
5917+
start_: flatbuffers::WIPOffset<flatbuffers::TableUnfinishedWIPOffset>,
5918+
}
5919+
impl<'a: 'b, 'b> CFFIClientPropertyBuilder<'a, 'b> {
5920+
#[inline]
5921+
pub fn add_name(&mut self, name: flatbuffers::WIPOffset<&'b str>) {
5922+
self.fbb_.push_slot_always::<flatbuffers::WIPOffset<_>>(CFFIClientProperty::VT_NAME, name);
5923+
}
5924+
#[inline]
5925+
pub fn add_provider(&mut self, provider: flatbuffers::WIPOffset<&'b str>) {
5926+
self.fbb_.push_slot_always::<flatbuffers::WIPOffset<_>>(CFFIClientProperty::VT_PROVIDER, provider);
5927+
}
5928+
#[inline]
5929+
pub fn add_retry_policy(&mut self, retry_policy: flatbuffers::WIPOffset<&'b str>) {
5930+
self.fbb_.push_slot_always::<flatbuffers::WIPOffset<_>>(CFFIClientProperty::VT_RETRY_POLICY, retry_policy);
5931+
}
5932+
#[inline]
5933+
pub fn add_options(&mut self, options: flatbuffers::WIPOffset<flatbuffers::Vector<'b , flatbuffers::ForwardsUOffset<CFFIMapEntry<'b >>>>) {
5934+
self.fbb_.push_slot_always::<flatbuffers::WIPOffset<_>>(CFFIClientProperty::VT_OPTIONS, options);
5935+
}
5936+
#[inline]
5937+
pub fn new(_fbb: &'b mut flatbuffers::FlatBufferBuilder<'a>) -> CFFIClientPropertyBuilder<'a, 'b> {
5938+
let start = _fbb.start_table();
5939+
CFFIClientPropertyBuilder {
5940+
fbb_: _fbb,
5941+
start_: start,
5942+
}
5943+
}
5944+
#[inline]
5945+
pub fn finish(self) -> flatbuffers::WIPOffset<CFFIClientProperty<'a>> {
5946+
let o = self.fbb_.end_table(self.start_);
5947+
flatbuffers::WIPOffset::new(o.value())
5948+
}
5949+
}
5950+
5951+
impl core::fmt::Debug for CFFIClientProperty<'_> {
5952+
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
5953+
let mut ds = f.debug_struct("CFFIClientProperty");
5954+
ds.field("name", &self.name());
5955+
ds.field("provider", &self.provider());
5956+
ds.field("retry_policy", &self.retry_policy());
5957+
ds.field("options", &self.options());
56795958
ds.finish()
56805959
}
56815960
}

0 commit comments

Comments
 (0)