react-native-nobodywho 1.0.1 → 2.0.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.
@@ -211,6 +211,10 @@ protected:
211
211
  jsi::Runtime &rt, const jsi::Value &thisVal, const jsi::Value *args,
212
212
  size_t count);
213
213
  jsi::Value
214
+ cpp_uniffi_nobodywho_uniffi_fn_init_callback_vtable_rustdownloadprogresscallback(
215
+ jsi::Runtime &rt, const jsi::Value &thisVal, const jsi::Value *args,
216
+ size_t count);
217
+ jsi::Value
214
218
  cpp_uniffi_nobodywho_uniffi_fn_init_callback_vtable_rusttoolcallback(
215
219
  jsi::Runtime &rt, const jsi::Value &thisVal, const jsi::Value *args,
216
220
  size_t count);
@@ -573,6 +577,10 @@ protected:
573
577
  cpp_uniffi_nobodywho_uniffi_checksum_constructor_samplerconfig_from_json(
574
578
  jsi::Runtime &rt, const jsi::Value &thisVal, const jsi::Value *args,
575
579
  size_t count);
580
+ jsi::Value
581
+ cpp_uniffi_nobodywho_uniffi_checksum_method_rustdownloadprogresscallback_on_download_progress(
582
+ jsi::Runtime &rt, const jsi::Value &thisVal, const jsi::Value *args,
583
+ size_t count);
576
584
  jsi::Value cpp_uniffi_nobodywho_uniffi_checksum_method_rusttoolcallback_call(
577
585
  jsi::Runtime &rt, const jsi::Value &thisVal, const jsi::Value *args,
578
586
  size_t count);
@@ -77,9 +77,10 @@ interface NativeModuleInterface {
77
77
  ubrn_uniffi_nobodywho_uniffi_fn_free_samplerconfig(handle: bigint, uniffi_out_err: UniffiRustCallStatus): void;
78
78
  ubrn_uniffi_nobodywho_uniffi_fn_constructor_samplerconfig_from_json(jsonStr: Uint8Array, uniffi_out_err: UniffiRustCallStatus): bigint;
79
79
  ubrn_uniffi_nobodywho_uniffi_fn_method_samplerconfig_to_json(ptr: bigint, uniffi_out_err: UniffiRustCallStatus): Uint8Array;
80
+ ubrn_uniffi_nobodywho_uniffi_fn_init_callback_vtable_rustdownloadprogresscallback(vtable: UniffiVTableCallbackInterfaceRustDownloadProgressCallback): void;
80
81
  ubrn_uniffi_nobodywho_uniffi_fn_init_callback_vtable_rusttoolcallback(vtable: UniffiVTableCallbackInterfaceRustToolCallback): void;
81
82
  ubrn_uniffi_nobodywho_uniffi_fn_func_cosine_similarity(a: Uint8Array, b: Uint8Array, uniffi_out_err: UniffiRustCallStatus): number;
82
- ubrn_uniffi_nobodywho_uniffi_fn_func_load_model(modelPath: Uint8Array, useGpu: number, projectionModelPath: Uint8Array): bigint;
83
+ ubrn_uniffi_nobodywho_uniffi_fn_func_load_model(modelPath: Uint8Array, useGpu: number, projectionModelPath: Uint8Array, onDownloadProgress: Uint8Array): bigint;
83
84
  ubrn_uniffi_nobodywho_uniffi_fn_func_sampler_preset_default(uniffi_out_err: UniffiRustCallStatus): bigint;
84
85
  ubrn_uniffi_nobodywho_uniffi_fn_func_sampler_preset_dry(uniffi_out_err: UniffiRustCallStatus): bigint;
85
86
  ubrn_uniffi_nobodywho_uniffi_fn_func_sampler_preset_grammar(grammar: Uint8Array, uniffi_out_err: UniffiRustCallStatus): bigint;
@@ -189,6 +190,7 @@ interface NativeModuleInterface {
189
190
  ubrn_uniffi_nobodywho_uniffi_checksum_constructor_rusttool_new_async(): number;
190
191
  ubrn_uniffi_nobodywho_uniffi_checksum_constructor_samplerbuilder_new(): number;
191
192
  ubrn_uniffi_nobodywho_uniffi_checksum_constructor_samplerconfig_from_json(): number;
193
+ ubrn_uniffi_nobodywho_uniffi_checksum_method_rustdownloadprogresscallback_on_download_progress(): number;
192
194
  ubrn_uniffi_nobodywho_uniffi_checksum_method_rusttoolcallback_call(): number;
193
195
  ubrn_ffi_nobodywho_uniffi_uniffi_contract_version(): number;
194
196
  ubrn_uniffi_internal_fn_method_rustchat_ffi__bless_pointer(pointer: bigint, uniffi_out_err: UniffiRustCallStatus): UniffiGcObject;
@@ -278,8 +280,15 @@ export type UniffiForeignFutureResultVoid = {
278
280
  callStatus: UniffiRustCallStatus;
279
281
  };
280
282
  export type UniffiForeignFutureCompleteVoid = (callbackData: bigint, result: UniffiForeignFutureResultVoid) => void;
283
+ type UniffiCallbackInterfaceRustDownloadProgressCallbackMethod0 = (uniffiHandle: bigint, downloaded: bigint, total: bigint) => UniffiResult<void>
284
+ ;
281
285
  type UniffiCallbackInterfaceRustToolCallbackMethod0 = (uniffiHandle: bigint, argumentsJson: Uint8Array) => Uint8Array
282
286
  ;
287
+ export type UniffiVTableCallbackInterfaceRustDownloadProgressCallback = {
288
+ uniffiFree: UniffiCallbackInterfaceFree;
289
+ uniffiClone: UniffiCallbackInterfaceClone;
290
+ onDownloadProgress: UniffiCallbackInterfaceRustDownloadProgressCallbackMethod0;
291
+ };
283
292
  export type UniffiVTableCallbackInterfaceRustToolCallback = {
284
293
  uniffiFree: UniffiCallbackInterfaceFree;
285
294
  uniffiClone: UniffiCallbackInterfaceClone;
@@ -32,6 +32,7 @@ import nativeModule, {
32
32
  type UniffiForeignFutureCompleteRustBuffer,
33
33
  type UniffiForeignFutureResultVoid,
34
34
  type UniffiForeignFutureCompleteVoid,
35
+ type UniffiVTableCallbackInterfaceRustDownloadProgressCallback,
35
36
  type UniffiVTableCallbackInterfaceRustToolCallback,
36
37
  } from "./nobodywho-ffi";
37
38
  import {
@@ -104,13 +105,13 @@ export function cosineSimilarity(a: Array</*f32*/number>, b: Array</*f32*/number
104
105
  * uniffi-bindgen-react-native generates invalid JS (`async static` instead
105
106
  * of `static async`) for async constructors.
106
107
  */
107
- export async function loadModel(modelPath: string, useGpu: boolean, projectionModelPath: string | undefined, asyncOpts_?: { signal: AbortSignal }): Promise<RustModelInterface> /*throws*/ {
108
+ export async function loadModel(modelPath: string, useGpu: boolean, projectionModelPath: string | undefined, onDownloadProgress: RustDownloadProgressCallback | undefined, asyncOpts_?: { signal: AbortSignal }): Promise<RustModelInterface> /*throws*/ {
108
109
  const __stack = uniffiIsDebug ? new Error().stack : undefined;
109
110
  try {
110
111
  return await uniffiRustCallAsync(
111
112
  /*rustCaller:*/ uniffiCaller,
112
113
  /*rustFutureFunc:*/ () => {
113
- return nativeModule().ubrn_uniffi_nobodywho_uniffi_fn_func_load_model(FfiConverterString.lower(modelPath),FfiConverterBool.lower(useGpu),FfiConverterOptionalString.lower(projectionModelPath)
114
+ return nativeModule().ubrn_uniffi_nobodywho_uniffi_fn_func_load_model(FfiConverterString.lower(modelPath),FfiConverterBool.lower(useGpu),FfiConverterOptionalString.lower(projectionModelPath),FfiConverterOptionalTypeRustDownloadProgressCallback.lower(onDownloadProgress)
114
115
  );
115
116
  },
116
117
  /*pollFunc:*/ nativeModule().ubrn_ffi_nobodywho_uniffi_rust_future_poll_u64,
@@ -234,6 +235,69 @@ export function samplerPresetTopP(topP: /*f32*/number): SamplerConfigInterface {
234
235
 
235
236
 
236
237
 
238
+ /**
239
+ * Callback interface for download progress reporting. Implement this in your
240
+ * language to receive `(downloadedBytes, totalBytes)` events while a remote
241
+ * model is being downloaded. Throttled to ~10 Hz with a guaranteed final emit
242
+ * on completion. Not invoked for cached/local files.
243
+ */
244
+ export interface RustDownloadProgressCallback {
245
+
246
+ onDownloadProgress(downloaded: /*u64*/bigint, total: /*u64*/bigint) : void;
247
+ }
248
+
249
+
250
+ // Put the implementation in a struct so we don't pollute the top-level namespace
251
+ const uniffiCallbackInterfaceRustDownloadProgressCallback: { vtable: UniffiVTableCallbackInterfaceRustDownloadProgressCallback; register: () => void; } = {
252
+ // Create the VTable using a series of closures.
253
+ // ts automatically converts these into C callback functions.
254
+ vtable: {
255
+ onDownloadProgress: (
256
+ uniffiHandle: bigint,
257
+ downloaded: bigint,
258
+ total: bigint,) => {
259
+ const uniffiMakeCall =
260
+ ()
261
+ : void => {
262
+ const jsCallback = FfiConverterTypeRustDownloadProgressCallback.lift(uniffiHandle);
263
+ return jsCallback.onDownloadProgress(
264
+ FfiConverterUInt64.lift(downloaded),
265
+ FfiConverterUInt64.lift(total)
266
+ )
267
+ };
268
+ const uniffiResult = UniffiResult.ready<void>();
269
+ const uniffiHandleSuccess = (obj: any) => {};
270
+ const uniffiHandleError = (code: number, errBuf: UniffiByteArray) => {
271
+ UniffiResult.writeError(uniffiResult, code, errBuf);
272
+ };
273
+ uniffiTraitInterfaceCall(
274
+ /*makeCall:*/ uniffiMakeCall,
275
+ /*handleSuccess:*/ uniffiHandleSuccess,
276
+ /*handleError:*/ uniffiHandleError,
277
+ /*lowerString:*/ FfiConverterString.lower
278
+ )
279
+ return uniffiResult;
280
+ },
281
+ uniffiFree: (uniffiHandle: UniffiHandle): void => {
282
+ // RustDownloadProgressCallback: this will throw a stale handle error if the handle isn't found.
283
+ FfiConverterTypeRustDownloadProgressCallback.drop(uniffiHandle);
284
+ },
285
+ uniffiClone: (uniffiHandle: UniffiHandle): UniffiHandle => {
286
+ return FfiConverterTypeRustDownloadProgressCallback.clone(uniffiHandle);
287
+ }
288
+ },
289
+ register: () => {
290
+ nativeModule().ubrn_uniffi_nobodywho_uniffi_fn_init_callback_vtable_rustdownloadprogresscallback(
291
+ uniffiCallbackInterfaceRustDownloadProgressCallback.vtable
292
+ );
293
+ },
294
+ };
295
+
296
+ // FfiConverter protocol for callback interfaces
297
+ const FfiConverterTypeRustDownloadProgressCallback = new FfiConverterCallback<RustDownloadProgressCallback>();
298
+
299
+
300
+
237
301
  /**
238
302
  * Callback interface for tool functions.
239
303
  * Implement this in your language to provide the tool's logic.
@@ -555,38 +619,39 @@ const FfiConverterString = uniffiCreateFfiConverterString(stringConverter);
555
619
 
556
620
  // Enum: Message
557
621
  export enum Message_Tags {
558
- Message = "Message",
559
- ToolCalls = "ToolCalls",
560
- ToolResp = "ToolResp"
622
+ User = "User",
623
+ Assistant = "Assistant",
624
+ System = "System",
625
+ Tool = "Tool"
561
626
  }
562
627
  export const Message = (() => {
563
628
 
564
629
 
565
- type Message__interface = {
566
- tag: Message_Tags.Message;
567
- inner: Readonly<{role: Role; content: string; assets: Array<Asset>}>
630
+ type User__interface = {
631
+ tag: Message_Tags.User;
632
+ inner: Readonly<{content: string; assets: Array<Asset>}>
568
633
  };
569
634
 
570
635
 
571
- class Message_ extends UniffiEnum implements Message__interface {
636
+ class User_ extends UniffiEnum implements User__interface {
572
637
  /**
573
638
  * @private
574
639
  * This field is private and should not be used, use `tag` instead.
575
640
  */
576
641
  readonly [uniffiTypeNameSymbol] = "Message";
577
- readonly tag = Message_Tags.Message;
578
- readonly inner: Readonly<{role: Role; content: string; assets: Array<Asset>}>;
579
- constructor(inner: { role: Role, content: string, assets: Array<Asset> }) {
580
- super("Message", "Message");
642
+ readonly tag = Message_Tags.User;
643
+ readonly inner: Readonly<{content: string; assets: Array<Asset>}>;
644
+ constructor(inner: { content: string, assets: Array<Asset> }) {
645
+ super("Message", "User");
581
646
  this.inner = Object.freeze(inner);
582
647
  }
583
648
 
584
- static new(inner: { role: Role, content: string, assets: Array<Asset> }): Message_ {
585
- return new Message_(inner);
649
+ static new(inner: { content: string, assets: Array<Asset> }): User_ {
650
+ return new User_(inner);
586
651
  }
587
652
 
588
- static instanceOf(obj: any): obj is Message_ {
589
- return obj.tag === Message_Tags.Message;
653
+ static instanceOf(obj: any): obj is User_ {
654
+ return obj.tag === Message_Tags.User;
590
655
  }
591
656
 
592
657
 
@@ -595,31 +660,31 @@ export const Message = (() => {
595
660
  }
596
661
 
597
662
 
598
- type ToolCalls__interface = {
599
- tag: Message_Tags.ToolCalls;
600
- inner: Readonly<{role: Role; content: string; toolCalls: Array<ToolCall>}>
663
+ type Assistant__interface = {
664
+ tag: Message_Tags.Assistant;
665
+ inner: Readonly<{content: string; toolCalls: Array<ToolCall> | undefined}>
601
666
  };
602
667
 
603
668
 
604
- class ToolCalls_ extends UniffiEnum implements ToolCalls__interface {
669
+ class Assistant_ extends UniffiEnum implements Assistant__interface {
605
670
  /**
606
671
  * @private
607
672
  * This field is private and should not be used, use `tag` instead.
608
673
  */
609
674
  readonly [uniffiTypeNameSymbol] = "Message";
610
- readonly tag = Message_Tags.ToolCalls;
611
- readonly inner: Readonly<{role: Role; content: string; toolCalls: Array<ToolCall>}>;
612
- constructor(inner: { role: Role, content: string, toolCalls: Array<ToolCall> }) {
613
- super("Message", "ToolCalls");
675
+ readonly tag = Message_Tags.Assistant;
676
+ readonly inner: Readonly<{content: string; toolCalls: Array<ToolCall> | undefined}>;
677
+ constructor(inner: { content: string, toolCalls: Array<ToolCall> | undefined }) {
678
+ super("Message", "Assistant");
614
679
  this.inner = Object.freeze(inner);
615
680
  }
616
681
 
617
- static new(inner: { role: Role, content: string, toolCalls: Array<ToolCall> }): ToolCalls_ {
618
- return new ToolCalls_(inner);
682
+ static new(inner: { content: string, toolCalls: Array<ToolCall> | undefined }): Assistant_ {
683
+ return new Assistant_(inner);
619
684
  }
620
685
 
621
- static instanceOf(obj: any): obj is ToolCalls_ {
622
- return obj.tag === Message_Tags.ToolCalls;
686
+ static instanceOf(obj: any): obj is Assistant_ {
687
+ return obj.tag === Message_Tags.Assistant;
623
688
  }
624
689
 
625
690
 
@@ -628,31 +693,64 @@ export const Message = (() => {
628
693
  }
629
694
 
630
695
 
631
- type ToolResp__interface = {
632
- tag: Message_Tags.ToolResp;
633
- inner: Readonly<{role: Role; name: string; content: string}>
696
+ type System__interface = {
697
+ tag: Message_Tags.System;
698
+ inner: Readonly<{content: string}>
634
699
  };
635
700
 
636
701
 
637
- class ToolResp_ extends UniffiEnum implements ToolResp__interface {
702
+ class System_ extends UniffiEnum implements System__interface {
638
703
  /**
639
704
  * @private
640
705
  * This field is private and should not be used, use `tag` instead.
641
706
  */
642
707
  readonly [uniffiTypeNameSymbol] = "Message";
643
- readonly tag = Message_Tags.ToolResp;
644
- readonly inner: Readonly<{role: Role; name: string; content: string}>;
645
- constructor(inner: { role: Role, name: string, content: string }) {
646
- super("Message", "ToolResp");
708
+ readonly tag = Message_Tags.System;
709
+ readonly inner: Readonly<{content: string}>;
710
+ constructor(inner: { content: string }) {
711
+ super("Message", "System");
647
712
  this.inner = Object.freeze(inner);
648
713
  }
649
714
 
650
- static new(inner: { role: Role, name: string, content: string }): ToolResp_ {
651
- return new ToolResp_(inner);
715
+ static new(inner: { content: string }): System_ {
716
+ return new System_(inner);
652
717
  }
653
718
 
654
- static instanceOf(obj: any): obj is ToolResp_ {
655
- return obj.tag === Message_Tags.ToolResp;
719
+ static instanceOf(obj: any): obj is System_ {
720
+ return obj.tag === Message_Tags.System;
721
+ }
722
+
723
+
724
+
725
+
726
+ }
727
+
728
+
729
+ type Tool__interface = {
730
+ tag: Message_Tags.Tool;
731
+ inner: Readonly<{name: string; content: string}>
732
+ };
733
+
734
+
735
+ class Tool_ extends UniffiEnum implements Tool__interface {
736
+ /**
737
+ * @private
738
+ * This field is private and should not be used, use `tag` instead.
739
+ */
740
+ readonly [uniffiTypeNameSymbol] = "Message";
741
+ readonly tag = Message_Tags.Tool;
742
+ readonly inner: Readonly<{name: string; content: string}>;
743
+ constructor(inner: { name: string, content: string }) {
744
+ super("Message", "Tool");
745
+ this.inner = Object.freeze(inner);
746
+ }
747
+
748
+ static new(inner: { name: string, content: string }): Tool_ {
749
+ return new Tool_(inner);
750
+ }
751
+
752
+ static instanceOf(obj: any): obj is Tool_ {
753
+ return obj.tag === Message_Tags.Tool;
656
754
  }
657
755
 
658
756
 
@@ -666,9 +764,10 @@ export const Message = (() => {
666
764
 
667
765
  return Object.freeze({
668
766
  instanceOf,
669
- Message: Message_,
670
- ToolCalls: ToolCalls_,
671
- ToolResp: ToolResp_
767
+ User: User_,
768
+ Assistant: Assistant_,
769
+ System: System_,
770
+ Tool: Tool_
672
771
  });
673
772
 
674
773
  })();
@@ -686,34 +785,38 @@ const FfiConverterTypeMessage = (() => {
686
785
  class FFIConverter extends AbstractFfiConverterByteArray<TypeName> {
687
786
  read(from: RustBuffer): TypeName {
688
787
  switch (ordinalConverter.read(from)) {
689
- case 1: return new Message.Message({role: FfiConverterTypeRole.read(from), content: FfiConverterString.read(from), assets: FfiConverterArrayTypeAsset.read(from) });
690
- case 2: return new Message.ToolCalls({role: FfiConverterTypeRole.read(from), content: FfiConverterString.read(from), toolCalls: FfiConverterArrayTypeToolCall.read(from) });
691
- case 3: return new Message.ToolResp({role: FfiConverterTypeRole.read(from), name: FfiConverterString.read(from), content: FfiConverterString.read(from) });
788
+ case 1: return new Message.User({content: FfiConverterString.read(from), assets: FfiConverterArrayTypeAsset.read(from) });
789
+ case 2: return new Message.Assistant({content: FfiConverterString.read(from), toolCalls: FfiConverterOptionalArrayTypeToolCall.read(from) });
790
+ case 3: return new Message.System({content: FfiConverterString.read(from) });
791
+ case 4: return new Message.Tool({name: FfiConverterString.read(from), content: FfiConverterString.read(from) });
692
792
  default: throw new UniffiInternalError.UnexpectedEnumCase();
693
793
  }
694
794
  }
695
795
  write(value: TypeName, into: RustBuffer): void {
696
796
  switch (value.tag) {
697
- case Message_Tags.Message: {
797
+ case Message_Tags.User: {
698
798
  ordinalConverter.write(1, into);
699
799
  const inner = value.inner;
700
- FfiConverterTypeRole.write(inner.role, into);
701
800
  FfiConverterString.write(inner.content, into);
702
801
  FfiConverterArrayTypeAsset.write(inner.assets, into);
703
802
  return;
704
803
  }
705
- case Message_Tags.ToolCalls: {
804
+ case Message_Tags.Assistant: {
706
805
  ordinalConverter.write(2, into);
707
806
  const inner = value.inner;
708
- FfiConverterTypeRole.write(inner.role, into);
709
807
  FfiConverterString.write(inner.content, into);
710
- FfiConverterArrayTypeToolCall.write(inner.toolCalls, into);
808
+ FfiConverterOptionalArrayTypeToolCall.write(inner.toolCalls, into);
711
809
  return;
712
810
  }
713
- case Message_Tags.ToolResp: {
811
+ case Message_Tags.System: {
714
812
  ordinalConverter.write(3, into);
715
813
  const inner = value.inner;
716
- FfiConverterTypeRole.write(inner.role, into);
814
+ FfiConverterString.write(inner.content, into);
815
+ return;
816
+ }
817
+ case Message_Tags.Tool: {
818
+ ordinalConverter.write(4, into);
819
+ const inner = value.inner;
717
820
  FfiConverterString.write(inner.name, into);
718
821
  FfiConverterString.write(inner.content, into);
719
822
  return;
@@ -725,26 +828,29 @@ const FfiConverterTypeMessage = (() => {
725
828
  }
726
829
  allocationSize(value: TypeName): number {
727
830
  switch (value.tag) {
728
- case Message_Tags.Message: {
831
+ case Message_Tags.User: {
729
832
  const inner = value.inner;
730
833
  let size = ordinalConverter.allocationSize(1);
731
- size += FfiConverterTypeRole.allocationSize(inner.role);
732
834
  size += FfiConverterString.allocationSize(inner.content);
733
835
  size += FfiConverterArrayTypeAsset.allocationSize(inner.assets);
734
836
  return size;
735
837
  }
736
- case Message_Tags.ToolCalls: {
838
+ case Message_Tags.Assistant: {
737
839
  const inner = value.inner;
738
840
  let size = ordinalConverter.allocationSize(2);
739
- size += FfiConverterTypeRole.allocationSize(inner.role);
740
841
  size += FfiConverterString.allocationSize(inner.content);
741
- size += FfiConverterArrayTypeToolCall.allocationSize(inner.toolCalls);
842
+ size += FfiConverterOptionalArrayTypeToolCall.allocationSize(inner.toolCalls);
742
843
  return size;
743
844
  }
744
- case Message_Tags.ToolResp: {
845
+ case Message_Tags.System: {
745
846
  const inner = value.inner;
746
847
  let size = ordinalConverter.allocationSize(3);
747
- size += FfiConverterTypeRole.allocationSize(inner.role);
848
+ size += FfiConverterString.allocationSize(inner.content);
849
+ return size;
850
+ }
851
+ case Message_Tags.Tool: {
852
+ const inner = value.inner;
853
+ let size = ordinalConverter.allocationSize(4);
748
854
  size += FfiConverterString.allocationSize(inner.name);
749
855
  size += FfiConverterString.allocationSize(inner.content);
750
856
  return size;
@@ -1030,45 +1136,6 @@ const FfiConverterTypePromptPart = (() => {
1030
1136
 
1031
1137
 
1032
1138
 
1033
- export enum Role {
1034
- User,
1035
- Assistant,
1036
- System,
1037
- Tool
1038
- }
1039
-
1040
- const FfiConverterTypeRole = (() => {
1041
- const ordinalConverter = FfiConverterInt32;
1042
- type TypeName = Role;
1043
- class FFIConverter extends AbstractFfiConverterByteArray<TypeName> {
1044
- read(from: RustBuffer): TypeName {
1045
- switch (ordinalConverter.read(from)) {
1046
- case 1: return Role.User;
1047
- case 2: return Role.Assistant;
1048
- case 3: return Role.System;
1049
- case 4: return Role.Tool;
1050
- default: throw new UniffiInternalError.UnexpectedEnumCase();
1051
- }
1052
- }
1053
- write(value: TypeName, into: RustBuffer): void {
1054
- switch (value) {
1055
- case Role.User: return ordinalConverter.write(1, into);
1056
- case Role.Assistant: return ordinalConverter.write(2, into);
1057
- case Role.System: return ordinalConverter.write(3, into);
1058
- case Role.Tool: return ordinalConverter.write(4, into);
1059
- }
1060
- }
1061
- allocationSize(value: TypeName): number {
1062
- return ordinalConverter.allocationSize(0);
1063
- }
1064
- }
1065
- return new FFIConverter();
1066
- })();
1067
-
1068
-
1069
-
1070
-
1071
-
1072
1139
  // FfiConverter for Map<string, boolean>
1073
1140
  const FfiConverterMapStringBool = new FfiConverterMap(FfiConverterString, FfiConverterBool);
1074
1141
 
@@ -2891,6 +2958,10 @@ const uniffiTypeSamplerConfigObjectFactory: UniffiObjectFactory<SamplerConfigInt
2891
2958
  const FfiConverterTypeSamplerConfig = new FfiConverterObject(uniffiTypeSamplerConfigObjectFactory);
2892
2959
 
2893
2960
 
2961
+ // FfiConverter for RustDownloadProgressCallback | undefined
2962
+ const FfiConverterOptionalTypeRustDownloadProgressCallback = new FfiConverterOptional(FfiConverterTypeRustDownloadProgressCallback);
2963
+
2964
+
2894
2965
  // FfiConverter for PendingToolCall | undefined
2895
2966
  const FfiConverterOptionalTypePendingToolCall = new FfiConverterOptional(FfiConverterTypePendingToolCall);
2896
2967
 
@@ -2931,6 +3002,10 @@ const FfiConverterOptionalMapStringBool = new FfiConverterOptional(FfiConverterM
2931
3002
  const FfiConverterOptionalTypeSamplerConfig = new FfiConverterOptional(FfiConverterTypeSamplerConfig);
2932
3003
 
2933
3004
 
3005
+ // FfiConverter for Array<ToolCall> | undefined
3006
+ const FfiConverterOptionalArrayTypeToolCall = new FfiConverterOptional(FfiConverterArrayTypeToolCall);
3007
+
3008
+
2934
3009
  // FfiConverter for Array<Message>
2935
3010
  const FfiConverterArrayTypeMessage = new FfiConverterArray(FfiConverterTypeMessage);
2936
3011
 
@@ -2967,7 +3042,7 @@ function uniffiEnsureInitialized() {
2967
3042
  if (nativeModule().ubrn_uniffi_nobodywho_uniffi_checksum_func_cosine_similarity() !== 63439) {
2968
3043
  throw new UniffiInternalError.ApiChecksumMismatch("uniffi_nobodywho_uniffi_checksum_func_cosine_similarity");
2969
3044
  }
2970
- if (nativeModule().ubrn_uniffi_nobodywho_uniffi_checksum_func_load_model() !== 63144) {
3045
+ if (nativeModule().ubrn_uniffi_nobodywho_uniffi_checksum_func_load_model() !== 33587) {
2971
3046
  throw new UniffiInternalError.ApiChecksumMismatch("uniffi_nobodywho_uniffi_checksum_func_load_model");
2972
3047
  }
2973
3048
  if (nativeModule().ubrn_uniffi_nobodywho_uniffi_checksum_func_sampler_preset_default() !== 10834) {
@@ -3123,10 +3198,14 @@ function uniffiEnsureInitialized() {
3123
3198
  if (nativeModule().ubrn_uniffi_nobodywho_uniffi_checksum_constructor_samplerconfig_from_json() !== 6867) {
3124
3199
  throw new UniffiInternalError.ApiChecksumMismatch("uniffi_nobodywho_uniffi_checksum_constructor_samplerconfig_from_json");
3125
3200
  }
3201
+ if (nativeModule().ubrn_uniffi_nobodywho_uniffi_checksum_method_rustdownloadprogresscallback_on_download_progress() !== 28617) {
3202
+ throw new UniffiInternalError.ApiChecksumMismatch("uniffi_nobodywho_uniffi_checksum_method_rustdownloadprogresscallback_on_download_progress");
3203
+ }
3126
3204
  if (nativeModule().ubrn_uniffi_nobodywho_uniffi_checksum_method_rusttoolcallback_call() !== 43958) {
3127
3205
  throw new UniffiInternalError.ApiChecksumMismatch("uniffi_nobodywho_uniffi_checksum_method_rusttoolcallback_call");
3128
3206
  }
3129
3207
 
3208
+ uniffiCallbackInterfaceRustDownloadProgressCallback.register();
3130
3209
  uniffiCallbackInterfaceRustToolCallback.register();
3131
3210
  }
3132
3211
 
@@ -3138,7 +3217,6 @@ export default Object.freeze({
3138
3217
  FfiConverterTypeNobodyWhoError,
3139
3218
  FfiConverterTypePendingToolCall,
3140
3219
  FfiConverterTypePromptPart,
3141
- FfiConverterTypeRole,
3142
3220
  FfiConverterTypeRustChat,
3143
3221
  FfiConverterTypeRustCrossEncoder,
3144
3222
  FfiConverterTypeRustEncoder,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-nobodywho",
3
- "version": "1.0.1",
3
+ "version": "2.0.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",
package/src/chat.ts CHANGED
@@ -3,7 +3,7 @@ import {
3
3
  SamplerConfig,
4
4
  } from "../generated/ts/nobodywho";
5
5
  import { Model } from "./model";
6
- import { type ChatMessage, fromInternal, toInternal } from "./message";
6
+ import { type Message, fromInternal, toInternal } from "./message";
7
7
  import { TokenStream } from "./streaming";
8
8
  import type { Prompt } from "./prompt";
9
9
  import type { Tool } from "./tool";
@@ -69,11 +69,13 @@ export class Chat {
69
69
  templateVariables?: Record<string, boolean>;
70
70
  tools?: Tool[];
71
71
  sampler?: SamplerConfig;
72
+ onDownloadProgress?: (downloaded: number, total: number) => void;
72
73
  }): Promise<Chat> {
73
74
  const model = await Model.load({
74
75
  modelPath: opts.modelPath,
75
76
  useGpu: opts.useGpu,
76
77
  projectionModelPath: opts.projectionModelPath,
78
+ onDownloadProgress: opts.onDownloadProgress,
77
79
  });
78
80
  return new Chat({ model, ...opts });
79
81
  }
@@ -108,13 +110,13 @@ export class Chat {
108
110
  }
109
111
 
110
112
  /** Get the current chat history as a list of messages. */
111
- async getChatHistory(): Promise<ChatMessage[]> {
113
+ async getChatHistory(): Promise<Message[]> {
112
114
  const internal = await this._inner.getChatHistory();
113
115
  return internal.map(fromInternal);
114
116
  }
115
117
 
116
118
  /** Set the chat history from a list of messages. */
117
- async setChatHistory(messages: ChatMessage[]): Promise<void> {
119
+ async setChatHistory(messages: Message[]): Promise<void> {
118
120
  return this._inner.setChatHistory(messages.map(toInternal));
119
121
  }
120
122
 
@@ -35,8 +35,13 @@ export class CrossEncoder {
35
35
  modelPath: string;
36
36
  useGpu?: boolean;
37
37
  contextSize?: number;
38
+ onDownloadProgress?: (downloaded: number, total: number) => void;
38
39
  }): Promise<CrossEncoder> {
39
- const model = await Model.load({ modelPath: opts.modelPath, useGpu: opts.useGpu });
40
+ const model = await Model.load({
41
+ modelPath: opts.modelPath,
42
+ useGpu: opts.useGpu,
43
+ onDownloadProgress: opts.onDownloadProgress,
44
+ });
40
45
  return new CrossEncoder({ model, ...opts });
41
46
  }
42
47
 
package/src/encoder.ts CHANGED
@@ -31,8 +31,13 @@ export class Encoder {
31
31
  modelPath: string;
32
32
  useGpu?: boolean;
33
33
  contextSize?: number;
34
+ onDownloadProgress?: (downloaded: number, total: number) => void;
34
35
  }): Promise<Encoder> {
35
- const model = await Model.load({ modelPath: opts.modelPath, useGpu: opts.useGpu });
36
+ const model = await Model.load({
37
+ modelPath: opts.modelPath,
38
+ useGpu: opts.useGpu,
39
+ onDownloadProgress: opts.onDownloadProgress,
40
+ });
36
41
  return new Encoder({ model, ...opts });
37
42
  }
38
43