react-native-nobodywho 2.0.0 → 2.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -82,7 +82,7 @@ task resolveNativeLibraries {
82
82
  abiDir.mkdirs()
83
83
 
84
84
  def fileName = "libnobodywho-uniffi-${triple}-release.so"
85
- def downloadUrl = "https://github.com/nobodywho-ooo/nobodywho/releases/download/nobodywho-react-native-${nobodywhoVersion}/${fileName}"
85
+ def downloadUrl = "https://github.com/nobodywho-ooo/nobodywho/releases/download/nobodywho-react-native-v${nobodywhoVersion}/${fileName}"
86
86
 
87
87
  logger.lifecycle("[NobodyWho] ${abi}: Downloading from ${downloadUrl}")
88
88
 
@@ -110,7 +110,7 @@ task resolveNativeLibraries {
110
110
  throw new GradleException(
111
111
  "Failed to download NobodyWho library for ${abi}: HTTP ${code}\n" +
112
112
  "URL: ${downloadUrl}\n" +
113
- "Check that the release exists: https://github.com/nobodywho-ooo/nobodywho/releases/tag/nobodywho-react-native-${nobodywhoVersion}"
113
+ "Check that the release exists: https://github.com/nobodywho-ooo/nobodywho/releases/tag/nobodywho-react-native-v${nobodywhoVersion}"
114
114
  )
115
115
  }
116
116
  }
@@ -271,6 +271,15 @@ float uniffi_nobodywho_uniffi_fn_func_cosine_similarity(
271
271
  /*handle*/ uint64_t uniffi_nobodywho_uniffi_fn_func_load_model(
272
272
  RustBuffer model_path, int8_t use_gpu, RustBuffer projection_model_path,
273
273
  RustBuffer on_download_progress);
274
+ /*handle*/ uint64_t
275
+ uniffi_nobodywho_uniffi_fn_func_sampler_preset_constrain_with_grammar(
276
+ RustBuffer grammar, RustCallStatus *uniffi_out_err);
277
+ /*handle*/ uint64_t
278
+ uniffi_nobodywho_uniffi_fn_func_sampler_preset_constrain_with_json_schema(
279
+ RustBuffer schema, RustCallStatus *uniffi_out_err);
280
+ /*handle*/ uint64_t
281
+ uniffi_nobodywho_uniffi_fn_func_sampler_preset_constrain_with_regex(
282
+ RustBuffer pattern, RustCallStatus *uniffi_out_err);
274
283
  /*handle*/ uint64_t uniffi_nobodywho_uniffi_fn_func_sampler_preset_default(
275
284
  RustCallStatus *uniffi_out_err);
276
285
  /*handle*/ uint64_t uniffi_nobodywho_uniffi_fn_func_sampler_preset_dry(
@@ -408,6 +417,12 @@ void ffi_nobodywho_uniffi_rust_future_complete_void(
408
417
  /*handle*/ uint64_t handle, RustCallStatus *uniffi_out_err);
409
418
  uint16_t uniffi_nobodywho_uniffi_checksum_func_cosine_similarity();
410
419
  uint16_t uniffi_nobodywho_uniffi_checksum_func_load_model();
420
+ uint16_t
421
+ uniffi_nobodywho_uniffi_checksum_func_sampler_preset_constrain_with_grammar();
422
+ uint16_t
423
+ uniffi_nobodywho_uniffi_checksum_func_sampler_preset_constrain_with_json_schema();
424
+ uint16_t
425
+ uniffi_nobodywho_uniffi_checksum_func_sampler_preset_constrain_with_regex();
411
426
  uint16_t uniffi_nobodywho_uniffi_checksum_func_sampler_preset_default();
412
427
  uint16_t uniffi_nobodywho_uniffi_checksum_func_sampler_preset_dry();
413
428
  uint16_t uniffi_nobodywho_uniffi_checksum_func_sampler_preset_grammar();
@@ -3368,6 +3383,43 @@ NativeNobodywho::NativeNobodywho(
3368
3383
  return this->cpp_uniffi_nobodywho_uniffi_fn_func_load_model(
3369
3384
  rt, thisVal, args, count);
3370
3385
  });
3386
+ props["ubrn_uniffi_nobodywho_uniffi_fn_func_sampler_preset_constrain_with_"
3387
+ "grammar"] = jsi::Function::createFromHostFunction(
3388
+ rt,
3389
+ jsi::PropNameID::forAscii(rt, "ubrn_uniffi_nobodywho_uniffi_fn_func_"
3390
+ "sampler_preset_constrain_with_grammar"),
3391
+ 1,
3392
+ [this](jsi::Runtime &rt, const jsi::Value &thisVal,
3393
+ const jsi::Value *args, size_t count) -> jsi::Value {
3394
+ return this
3395
+ ->cpp_uniffi_nobodywho_uniffi_fn_func_sampler_preset_constrain_with_grammar(
3396
+ rt, thisVal, args, count);
3397
+ });
3398
+ props["ubrn_uniffi_nobodywho_uniffi_fn_func_sampler_preset_constrain_with_"
3399
+ "json_schema"] = jsi::Function::createFromHostFunction(
3400
+ rt,
3401
+ jsi::PropNameID::forAscii(rt,
3402
+ "ubrn_uniffi_nobodywho_uniffi_fn_func_sampler_"
3403
+ "preset_constrain_with_json_schema"),
3404
+ 1,
3405
+ [this](jsi::Runtime &rt, const jsi::Value &thisVal,
3406
+ const jsi::Value *args, size_t count) -> jsi::Value {
3407
+ return this
3408
+ ->cpp_uniffi_nobodywho_uniffi_fn_func_sampler_preset_constrain_with_json_schema(
3409
+ rt, thisVal, args, count);
3410
+ });
3411
+ props["ubrn_uniffi_nobodywho_uniffi_fn_func_sampler_preset_constrain_with_"
3412
+ "regex"] = jsi::Function::createFromHostFunction(
3413
+ rt,
3414
+ jsi::PropNameID::forAscii(rt, "ubrn_uniffi_nobodywho_uniffi_fn_func_"
3415
+ "sampler_preset_constrain_with_regex"),
3416
+ 1,
3417
+ [this](jsi::Runtime &rt, const jsi::Value &thisVal,
3418
+ const jsi::Value *args, size_t count) -> jsi::Value {
3419
+ return this
3420
+ ->cpp_uniffi_nobodywho_uniffi_fn_func_sampler_preset_constrain_with_regex(
3421
+ rt, thisVal, args, count);
3422
+ });
3371
3423
  props["ubrn_uniffi_nobodywho_uniffi_fn_func_sampler_preset_default"] =
3372
3424
  jsi::Function::createFromHostFunction(
3373
3425
  rt,
@@ -4019,6 +4071,44 @@ NativeNobodywho::NativeNobodywho(
4019
4071
  return this->cpp_uniffi_nobodywho_uniffi_checksum_func_load_model(
4020
4072
  rt, thisVal, args, count);
4021
4073
  });
4074
+ props["ubrn_uniffi_nobodywho_uniffi_checksum_func_sampler_preset_constrain_"
4075
+ "with_grammar"] = jsi::Function::createFromHostFunction(
4076
+ rt,
4077
+ jsi::PropNameID::forAscii(rt,
4078
+ "ubrn_uniffi_nobodywho_uniffi_checksum_func_"
4079
+ "sampler_preset_constrain_with_grammar"),
4080
+ 0,
4081
+ [this](jsi::Runtime &rt, const jsi::Value &thisVal,
4082
+ const jsi::Value *args, size_t count) -> jsi::Value {
4083
+ return this
4084
+ ->cpp_uniffi_nobodywho_uniffi_checksum_func_sampler_preset_constrain_with_grammar(
4085
+ rt, thisVal, args, count);
4086
+ });
4087
+ props["ubrn_uniffi_nobodywho_uniffi_checksum_func_sampler_preset_constrain_"
4088
+ "with_json_schema"] = jsi::Function::createFromHostFunction(
4089
+ rt,
4090
+ jsi::PropNameID::forAscii(rt,
4091
+ "ubrn_uniffi_nobodywho_uniffi_checksum_func_"
4092
+ "sampler_preset_constrain_with_json_schema"),
4093
+ 0,
4094
+ [this](jsi::Runtime &rt, const jsi::Value &thisVal,
4095
+ const jsi::Value *args, size_t count) -> jsi::Value {
4096
+ return this
4097
+ ->cpp_uniffi_nobodywho_uniffi_checksum_func_sampler_preset_constrain_with_json_schema(
4098
+ rt, thisVal, args, count);
4099
+ });
4100
+ props["ubrn_uniffi_nobodywho_uniffi_checksum_func_sampler_preset_constrain_"
4101
+ "with_regex"] = jsi::Function::createFromHostFunction(
4102
+ rt,
4103
+ jsi::PropNameID::forAscii(rt, "ubrn_uniffi_nobodywho_uniffi_checksum_"
4104
+ "func_sampler_preset_constrain_with_regex"),
4105
+ 0,
4106
+ [this](jsi::Runtime &rt, const jsi::Value &thisVal,
4107
+ const jsi::Value *args, size_t count) -> jsi::Value {
4108
+ return this
4109
+ ->cpp_uniffi_nobodywho_uniffi_checksum_func_sampler_preset_constrain_with_regex(
4110
+ rt, thisVal, args, count);
4111
+ });
4022
4112
  props["ubrn_uniffi_nobodywho_uniffi_checksum_func_sampler_preset_default"] =
4023
4113
  jsi::Function::createFromHostFunction(
4024
4114
  rt,
@@ -5920,6 +6010,57 @@ jsi::Value NativeNobodywho::cpp_uniffi_nobodywho_uniffi_fn_func_load_model(
5920
6010
  return uniffi_jsi::Bridging</*handle*/ uint64_t>::toJs(rt, callInvoker,
5921
6011
  value);
5922
6012
  }
6013
+ jsi::Value NativeNobodywho::
6014
+ cpp_uniffi_nobodywho_uniffi_fn_func_sampler_preset_constrain_with_grammar(
6015
+ jsi::Runtime &rt, const jsi::Value &thisVal, const jsi::Value *args,
6016
+ size_t count) {
6017
+ RustCallStatus status =
6018
+ uniffi::nobodywho::Bridging<RustCallStatus>::rustSuccess(rt);
6019
+ auto value =
6020
+ uniffi_nobodywho_uniffi_fn_func_sampler_preset_constrain_with_grammar(
6021
+ uniffi::nobodywho::Bridging<RustBuffer>::fromJs(rt, callInvoker,
6022
+ args[0]),
6023
+ &status);
6024
+ uniffi::nobodywho::Bridging<RustCallStatus>::copyIntoJs(
6025
+ rt, callInvoker, status, args[count - 1]);
6026
+
6027
+ return uniffi_jsi::Bridging</*handle*/ uint64_t>::toJs(rt, callInvoker,
6028
+ value);
6029
+ }
6030
+ jsi::Value NativeNobodywho::
6031
+ cpp_uniffi_nobodywho_uniffi_fn_func_sampler_preset_constrain_with_json_schema(
6032
+ jsi::Runtime &rt, const jsi::Value &thisVal, const jsi::Value *args,
6033
+ size_t count) {
6034
+ RustCallStatus status =
6035
+ uniffi::nobodywho::Bridging<RustCallStatus>::rustSuccess(rt);
6036
+ auto value =
6037
+ uniffi_nobodywho_uniffi_fn_func_sampler_preset_constrain_with_json_schema(
6038
+ uniffi::nobodywho::Bridging<RustBuffer>::fromJs(rt, callInvoker,
6039
+ args[0]),
6040
+ &status);
6041
+ uniffi::nobodywho::Bridging<RustCallStatus>::copyIntoJs(
6042
+ rt, callInvoker, status, args[count - 1]);
6043
+
6044
+ return uniffi_jsi::Bridging</*handle*/ uint64_t>::toJs(rt, callInvoker,
6045
+ value);
6046
+ }
6047
+ jsi::Value NativeNobodywho::
6048
+ cpp_uniffi_nobodywho_uniffi_fn_func_sampler_preset_constrain_with_regex(
6049
+ jsi::Runtime &rt, const jsi::Value &thisVal, const jsi::Value *args,
6050
+ size_t count) {
6051
+ RustCallStatus status =
6052
+ uniffi::nobodywho::Bridging<RustCallStatus>::rustSuccess(rt);
6053
+ auto value =
6054
+ uniffi_nobodywho_uniffi_fn_func_sampler_preset_constrain_with_regex(
6055
+ uniffi::nobodywho::Bridging<RustBuffer>::fromJs(rt, callInvoker,
6056
+ args[0]),
6057
+ &status);
6058
+ uniffi::nobodywho::Bridging<RustCallStatus>::copyIntoJs(
6059
+ rt, callInvoker, status, args[count - 1]);
6060
+
6061
+ return uniffi_jsi::Bridging</*handle*/ uint64_t>::toJs(rt, callInvoker,
6062
+ value);
6063
+ }
5923
6064
  jsi::Value
5924
6065
  NativeNobodywho::cpp_uniffi_nobodywho_uniffi_fn_func_sampler_preset_default(
5925
6066
  jsi::Runtime &rt, const jsi::Value &thisVal, const jsi::Value *args,
@@ -6589,6 +6730,33 @@ NativeNobodywho::cpp_uniffi_nobodywho_uniffi_checksum_func_load_model(
6589
6730
 
6590
6731
  return uniffi_jsi::Bridging<uint16_t>::toJs(rt, callInvoker, value);
6591
6732
  }
6733
+ jsi::Value NativeNobodywho::
6734
+ cpp_uniffi_nobodywho_uniffi_checksum_func_sampler_preset_constrain_with_grammar(
6735
+ jsi::Runtime &rt, const jsi::Value &thisVal, const jsi::Value *args,
6736
+ size_t count) {
6737
+ auto value =
6738
+ uniffi_nobodywho_uniffi_checksum_func_sampler_preset_constrain_with_grammar();
6739
+
6740
+ return uniffi_jsi::Bridging<uint16_t>::toJs(rt, callInvoker, value);
6741
+ }
6742
+ jsi::Value NativeNobodywho::
6743
+ cpp_uniffi_nobodywho_uniffi_checksum_func_sampler_preset_constrain_with_json_schema(
6744
+ jsi::Runtime &rt, const jsi::Value &thisVal, const jsi::Value *args,
6745
+ size_t count) {
6746
+ auto value =
6747
+ uniffi_nobodywho_uniffi_checksum_func_sampler_preset_constrain_with_json_schema();
6748
+
6749
+ return uniffi_jsi::Bridging<uint16_t>::toJs(rt, callInvoker, value);
6750
+ }
6751
+ jsi::Value NativeNobodywho::
6752
+ cpp_uniffi_nobodywho_uniffi_checksum_func_sampler_preset_constrain_with_regex(
6753
+ jsi::Runtime &rt, const jsi::Value &thisVal, const jsi::Value *args,
6754
+ size_t count) {
6755
+ auto value =
6756
+ uniffi_nobodywho_uniffi_checksum_func_sampler_preset_constrain_with_regex();
6757
+
6758
+ return uniffi_jsi::Bridging<uint16_t>::toJs(rt, callInvoker, value);
6759
+ }
6592
6760
  jsi::Value NativeNobodywho::
6593
6761
  cpp_uniffi_nobodywho_uniffi_checksum_func_sampler_preset_default(
6594
6762
  jsi::Runtime &rt, const jsi::Value &thisVal, const jsi::Value *args,
@@ -224,6 +224,18 @@ protected:
224
224
  jsi::Value cpp_uniffi_nobodywho_uniffi_fn_func_load_model(
225
225
  jsi::Runtime &rt, const jsi::Value &thisVal, const jsi::Value *args,
226
226
  size_t count);
227
+ jsi::Value
228
+ cpp_uniffi_nobodywho_uniffi_fn_func_sampler_preset_constrain_with_grammar(
229
+ jsi::Runtime &rt, const jsi::Value &thisVal, const jsi::Value *args,
230
+ size_t count);
231
+ jsi::Value
232
+ cpp_uniffi_nobodywho_uniffi_fn_func_sampler_preset_constrain_with_json_schema(
233
+ jsi::Runtime &rt, const jsi::Value &thisVal, const jsi::Value *args,
234
+ size_t count);
235
+ jsi::Value
236
+ cpp_uniffi_nobodywho_uniffi_fn_func_sampler_preset_constrain_with_regex(
237
+ jsi::Runtime &rt, const jsi::Value &thisVal, const jsi::Value *args,
238
+ size_t count);
227
239
  jsi::Value cpp_uniffi_nobodywho_uniffi_fn_func_sampler_preset_default(
228
240
  jsi::Runtime &rt, const jsi::Value &thisVal, const jsi::Value *args,
229
241
  size_t count);
@@ -398,6 +410,18 @@ protected:
398
410
  jsi::Value cpp_uniffi_nobodywho_uniffi_checksum_func_load_model(
399
411
  jsi::Runtime &rt, const jsi::Value &thisVal, const jsi::Value *args,
400
412
  size_t count);
413
+ jsi::Value
414
+ cpp_uniffi_nobodywho_uniffi_checksum_func_sampler_preset_constrain_with_grammar(
415
+ jsi::Runtime &rt, const jsi::Value &thisVal, const jsi::Value *args,
416
+ size_t count);
417
+ jsi::Value
418
+ cpp_uniffi_nobodywho_uniffi_checksum_func_sampler_preset_constrain_with_json_schema(
419
+ jsi::Runtime &rt, const jsi::Value &thisVal, const jsi::Value *args,
420
+ size_t count);
421
+ jsi::Value
422
+ cpp_uniffi_nobodywho_uniffi_checksum_func_sampler_preset_constrain_with_regex(
423
+ jsi::Runtime &rt, const jsi::Value &thisVal, const jsi::Value *args,
424
+ size_t count);
401
425
  jsi::Value cpp_uniffi_nobodywho_uniffi_checksum_func_sampler_preset_default(
402
426
  jsi::Runtime &rt, const jsi::Value &thisVal, const jsi::Value *args,
403
427
  size_t count);
@@ -81,6 +81,9 @@ interface NativeModuleInterface {
81
81
  ubrn_uniffi_nobodywho_uniffi_fn_init_callback_vtable_rusttoolcallback(vtable: UniffiVTableCallbackInterfaceRustToolCallback): void;
82
82
  ubrn_uniffi_nobodywho_uniffi_fn_func_cosine_similarity(a: Uint8Array, b: Uint8Array, uniffi_out_err: UniffiRustCallStatus): number;
83
83
  ubrn_uniffi_nobodywho_uniffi_fn_func_load_model(modelPath: Uint8Array, useGpu: number, projectionModelPath: Uint8Array, onDownloadProgress: Uint8Array): bigint;
84
+ ubrn_uniffi_nobodywho_uniffi_fn_func_sampler_preset_constrain_with_grammar(grammar: Uint8Array, uniffi_out_err: UniffiRustCallStatus): bigint;
85
+ ubrn_uniffi_nobodywho_uniffi_fn_func_sampler_preset_constrain_with_json_schema(schema: Uint8Array, uniffi_out_err: UniffiRustCallStatus): bigint;
86
+ ubrn_uniffi_nobodywho_uniffi_fn_func_sampler_preset_constrain_with_regex(pattern: Uint8Array, uniffi_out_err: UniffiRustCallStatus): bigint;
84
87
  ubrn_uniffi_nobodywho_uniffi_fn_func_sampler_preset_default(uniffi_out_err: UniffiRustCallStatus): bigint;
85
88
  ubrn_uniffi_nobodywho_uniffi_fn_func_sampler_preset_dry(uniffi_out_err: UniffiRustCallStatus): bigint;
86
89
  ubrn_uniffi_nobodywho_uniffi_fn_func_sampler_preset_grammar(grammar: Uint8Array, uniffi_out_err: UniffiRustCallStatus): bigint;
@@ -139,6 +142,9 @@ interface NativeModuleInterface {
139
142
  ubrn_ffi_nobodywho_uniffi_rust_future_complete_void(handle: bigint, uniffi_out_err: UniffiRustCallStatus): void;
140
143
  ubrn_uniffi_nobodywho_uniffi_checksum_func_cosine_similarity(): number;
141
144
  ubrn_uniffi_nobodywho_uniffi_checksum_func_load_model(): number;
145
+ ubrn_uniffi_nobodywho_uniffi_checksum_func_sampler_preset_constrain_with_grammar(): number;
146
+ ubrn_uniffi_nobodywho_uniffi_checksum_func_sampler_preset_constrain_with_json_schema(): number;
147
+ ubrn_uniffi_nobodywho_uniffi_checksum_func_sampler_preset_constrain_with_regex(): number;
142
148
  ubrn_uniffi_nobodywho_uniffi_checksum_func_sampler_preset_default(): number;
143
149
  ubrn_uniffi_nobodywho_uniffi_checksum_func_sampler_preset_dry(): number;
144
150
  ubrn_uniffi_nobodywho_uniffi_checksum_func_sampler_preset_grammar(): number;
@@ -130,6 +130,45 @@ export async function loadModel(modelPath: string, useGpu: boolean, projectionMo
130
130
  throw __error;
131
131
  }
132
132
  }
133
+ /**
134
+ * Create a sampler that constrains output using a Lark grammar via llguidance.
135
+ */
136
+ export function samplerPresetConstrainWithGrammar(grammar: string): SamplerConfigInterface {
137
+ return FfiConverterTypeSamplerConfig.lift(uniffiCaller.rustCall(
138
+ /*caller:*/ (callStatus) => {
139
+ return nativeModule().ubrn_uniffi_nobodywho_uniffi_fn_func_sampler_preset_constrain_with_grammar(
140
+ FfiConverterString.lower(grammar),
141
+ callStatus);
142
+ },
143
+ /*liftString:*/ FfiConverterString.lift,
144
+ ));
145
+ }
146
+ /**
147
+ * Create a sampler that constrains output to a JSON schema via llguidance.
148
+ */
149
+ export function samplerPresetConstrainWithJsonSchema(schema: string): SamplerConfigInterface {
150
+ return FfiConverterTypeSamplerConfig.lift(uniffiCaller.rustCall(
151
+ /*caller:*/ (callStatus) => {
152
+ return nativeModule().ubrn_uniffi_nobodywho_uniffi_fn_func_sampler_preset_constrain_with_json_schema(
153
+ FfiConverterString.lower(schema),
154
+ callStatus);
155
+ },
156
+ /*liftString:*/ FfiConverterString.lift,
157
+ ));
158
+ }
159
+ /**
160
+ * Create a sampler that constrains output to a regular expression via llguidance.
161
+ */
162
+ export function samplerPresetConstrainWithRegex(pattern: string): SamplerConfigInterface {
163
+ return FfiConverterTypeSamplerConfig.lift(uniffiCaller.rustCall(
164
+ /*caller:*/ (callStatus) => {
165
+ return nativeModule().ubrn_uniffi_nobodywho_uniffi_fn_func_sampler_preset_constrain_with_regex(
166
+ FfiConverterString.lower(pattern),
167
+ callStatus);
168
+ },
169
+ /*liftString:*/ FfiConverterString.lift,
170
+ ));
171
+ }
133
172
  /**
134
173
  * Get the default sampler configuration.
135
174
  */
@@ -179,9 +218,6 @@ export function samplerPresetGreedy(): SamplerConfigInterface {
179
218
  /*liftString:*/ FfiConverterString.lift,
180
219
  ));
181
220
  }
182
- /**
183
- * Create a sampler configured for JSON output generation.
184
- */
185
221
  export function samplerPresetJson(): SamplerConfigInterface {
186
222
  return FfiConverterTypeSamplerConfig.lift(uniffiCaller.rustCall(
187
223
  /*caller:*/ (callStatus) => {
@@ -2485,7 +2521,7 @@ export interface SamplerBuilderInterface {
2485
2521
  */
2486
2522
  dry(multiplier: /*f32*/number, base: /*f32*/number, allowedLength: /*i32*/number, penaltyLastN: /*i32*/number, seqBreakers: Array<string>) : SamplerBuilderInterface;
2487
2523
  /**
2488
- * Apply a grammar constraint to enforce structured output.
2524
+ * Deprecated: Use `sampler_preset_constrain_with_grammar()` instead. It accepts both Lark and GBNF strings.
2489
2525
  */
2490
2526
  grammar(grammar: string, triggerOn: string | undefined, root: string) : SamplerBuilderInterface;
2491
2527
  /**
@@ -2588,7 +2624,7 @@ export class SamplerBuilder extends UniffiAbstractObject implements SamplerBuild
2588
2624
  }
2589
2625
 
2590
2626
  /**
2591
- * Apply a grammar constraint to enforce structured output.
2627
+ * Deprecated: Use `sampler_preset_constrain_with_grammar()` instead. It accepts both Lark and GBNF strings.
2592
2628
  */
2593
2629
  grammar(grammar: string, triggerOn: string | undefined, root: string): SamplerBuilderInterface {
2594
2630
  return FfiConverterTypeSamplerBuilder.lift(uniffiCaller.rustCall(
@@ -3045,6 +3081,15 @@ function uniffiEnsureInitialized() {
3045
3081
  if (nativeModule().ubrn_uniffi_nobodywho_uniffi_checksum_func_load_model() !== 33587) {
3046
3082
  throw new UniffiInternalError.ApiChecksumMismatch("uniffi_nobodywho_uniffi_checksum_func_load_model");
3047
3083
  }
3084
+ if (nativeModule().ubrn_uniffi_nobodywho_uniffi_checksum_func_sampler_preset_constrain_with_grammar() !== 13698) {
3085
+ throw new UniffiInternalError.ApiChecksumMismatch("uniffi_nobodywho_uniffi_checksum_func_sampler_preset_constrain_with_grammar");
3086
+ }
3087
+ if (nativeModule().ubrn_uniffi_nobodywho_uniffi_checksum_func_sampler_preset_constrain_with_json_schema() !== 4691) {
3088
+ throw new UniffiInternalError.ApiChecksumMismatch("uniffi_nobodywho_uniffi_checksum_func_sampler_preset_constrain_with_json_schema");
3089
+ }
3090
+ if (nativeModule().ubrn_uniffi_nobodywho_uniffi_checksum_func_sampler_preset_constrain_with_regex() !== 25543) {
3091
+ throw new UniffiInternalError.ApiChecksumMismatch("uniffi_nobodywho_uniffi_checksum_func_sampler_preset_constrain_with_regex");
3092
+ }
3048
3093
  if (nativeModule().ubrn_uniffi_nobodywho_uniffi_checksum_func_sampler_preset_default() !== 10834) {
3049
3094
  throw new UniffiInternalError.ApiChecksumMismatch("uniffi_nobodywho_uniffi_checksum_func_sampler_preset_default");
3050
3095
  }
@@ -3057,7 +3102,7 @@ function uniffiEnsureInitialized() {
3057
3102
  if (nativeModule().ubrn_uniffi_nobodywho_uniffi_checksum_func_sampler_preset_greedy() !== 13219) {
3058
3103
  throw new UniffiInternalError.ApiChecksumMismatch("uniffi_nobodywho_uniffi_checksum_func_sampler_preset_greedy");
3059
3104
  }
3060
- if (nativeModule().ubrn_uniffi_nobodywho_uniffi_checksum_func_sampler_preset_json() !== 40006) {
3105
+ if (nativeModule().ubrn_uniffi_nobodywho_uniffi_checksum_func_sampler_preset_json() !== 8103) {
3061
3106
  throw new UniffiInternalError.ApiChecksumMismatch("uniffi_nobodywho_uniffi_checksum_func_sampler_preset_json");
3062
3107
  }
3063
3108
  if (nativeModule().ubrn_uniffi_nobodywho_uniffi_checksum_func_sampler_preset_temperature() !== 64803) {
@@ -3141,7 +3186,7 @@ function uniffiEnsureInitialized() {
3141
3186
  if (nativeModule().ubrn_uniffi_nobodywho_uniffi_checksum_method_samplerbuilder_dry() !== 35315) {
3142
3187
  throw new UniffiInternalError.ApiChecksumMismatch("uniffi_nobodywho_uniffi_checksum_method_samplerbuilder_dry");
3143
3188
  }
3144
- if (nativeModule().ubrn_uniffi_nobodywho_uniffi_checksum_method_samplerbuilder_grammar() !== 24369) {
3189
+ if (nativeModule().ubrn_uniffi_nobodywho_uniffi_checksum_method_samplerbuilder_grammar() !== 3547) {
3145
3190
  throw new UniffiInternalError.ApiChecksumMismatch("uniffi_nobodywho_uniffi_checksum_method_samplerbuilder_grammar");
3146
3191
  }
3147
3192
  if (nativeModule().ubrn_uniffi_nobodywho_uniffi_checksum_method_samplerbuilder_greedy() !== 32898) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-nobodywho",
3
- "version": "2.0.0",
3
+ "version": "2.1.0",
4
4
  "description": "Run LLMs locally with offline inference — React Native bindings",
5
5
  "main": "src/wrapper.ts",
6
6
  "types": "src/wrapper.ts",
@@ -1,5 +1,8 @@
1
1
  import {
2
2
  type SamplerConfig,
3
+ samplerPresetConstrainWithGrammar,
4
+ samplerPresetConstrainWithJsonSchema,
5
+ samplerPresetConstrainWithRegex,
3
6
  samplerPresetDefault,
4
7
  samplerPresetDry,
5
8
  samplerPresetGrammar,
@@ -52,12 +55,35 @@ export class SamplerPresets {
52
55
  return samplerPresetDry() as SamplerConfig;
53
56
  }
54
57
 
55
- /** Create a sampler configured for JSON output generation. */
58
+ /** Create a sampler configured for JSON output generation (any valid JSON, GBNF-based). */
56
59
  static json(): SamplerConfig {
57
60
  return samplerPresetJson() as SamplerConfig;
58
61
  }
59
62
 
60
- /** Create a sampler with a custom grammar constraint. */
63
+ /** Constrain output to a JSON schema via llguidance. Accepts a schema object or a JSON string. */
64
+ static constrainWithJsonSchema(schema: object | string): SamplerConfig {
65
+ const schemaStr = typeof schema === "string" ? schema : JSON.stringify(schema);
66
+ return samplerPresetConstrainWithJsonSchema(schemaStr) as SamplerConfig;
67
+ }
68
+
69
+ /** Constrain output to a regular expression via llguidance. Accepts a RegExp or a pattern string. */
70
+ static constrainWithRegex(pattern: RegExp | string): SamplerConfig {
71
+ const patternStr = pattern instanceof RegExp ? pattern.source : pattern;
72
+ return samplerPresetConstrainWithRegex(patternStr) as SamplerConfig;
73
+ }
74
+
75
+ /**
76
+ * Constrain output using a grammar via llguidance.
77
+ * Accepts both Lark syntax (`start: "yes" | "no"`) and GBNF (`root ::= "yes" | "no"`).
78
+ * GBNF is automatically converted to Lark before use.
79
+ */
80
+ static constrainWithGrammar(grammar: string): SamplerConfig {
81
+ return samplerPresetConstrainWithGrammar(grammar) as SamplerConfig;
82
+ }
83
+
84
+ /**
85
+ * @deprecated Use {@link constrainWithGrammar} instead. It accepts both Lark and GBNF strings.
86
+ */
61
87
  static grammar(grammar: string): SamplerConfig {
62
88
  return samplerPresetGrammar(grammar) as SamplerConfig;
63
89
  }