expo-ai-kit 0.1.21 → 0.2.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.
Files changed (239) hide show
  1. package/README.md +2 -2
  2. package/build/ExpoAiKitModule.d.ts +10 -1
  3. package/build/ExpoAiKitModule.d.ts.map +1 -1
  4. package/build/ExpoAiKitModule.js.map +1 -1
  5. package/build/hooks.d.ts +60 -1
  6. package/build/hooks.d.ts.map +1 -1
  7. package/build/hooks.js +134 -1
  8. package/build/hooks.js.map +1 -1
  9. package/build/index.d.ts +82 -1
  10. package/build/index.d.ts.map +1 -1
  11. package/build/index.js +140 -0
  12. package/build/index.js.map +1 -1
  13. package/build/memory.d.ts +21 -4
  14. package/build/memory.d.ts.map +1 -1
  15. package/build/memory.js +54 -11
  16. package/build/memory.js.map +1 -1
  17. package/build/models.d.ts +43 -0
  18. package/build/models.d.ts.map +1 -0
  19. package/build/models.js +45 -0
  20. package/build/models.js.map +1 -0
  21. package/build/types.d.ts +82 -0
  22. package/build/types.d.ts.map +1 -1
  23. package/build/types.js +13 -1
  24. package/build/types.js.map +1 -1
  25. package/ios/ExpoAiKit.podspec +1 -1
  26. package/package.json +4 -4
  27. package/src/ExpoAiKitModule.ts +35 -1
  28. package/src/hooks.ts +172 -1
  29. package/src/index.ts +171 -0
  30. package/src/memory.ts +63 -11
  31. package/src/models.ts +78 -0
  32. package/src/types.ts +112 -0
  33. package/android/.gradle/8.9/checksums/checksums.lock +0 -0
  34. package/android/.gradle/8.9/dependencies-accessors/gc.properties +0 -0
  35. package/android/.gradle/8.9/fileChanges/last-build.bin +0 -0
  36. package/android/.gradle/8.9/fileHashes/fileHashes.lock +0 -0
  37. package/android/.gradle/8.9/gc.properties +0 -0
  38. package/android/.gradle/buildOutputCleanup/buildOutputCleanup.lock +0 -0
  39. package/android/.gradle/buildOutputCleanup/cache.properties +0 -2
  40. package/android/.gradle/vcs-1/gc.properties +0 -0
  41. package/android/build/.transforms/550f2d3d50c89e495845cc30f2214044/results.bin +0 -1
  42. package/android/build/.transforms/550f2d3d50c89e495845cc30f2214044/transformed/classes/classes_dex/classes.dex +0 -0
  43. package/android/build/.transforms/a588f18db136c18b668ecd9727a7dc6b/results.bin +0 -1
  44. package/android/build/.transforms/a588f18db136c18b668ecd9727a7dc6b/transformed/classes/classes_dex/classes.dex +0 -0
  45. package/android/build/.transforms/c485bab123d2a96b9ef2e8051e8dcd8c/results.bin +0 -1
  46. package/android/build/.transforms/c485bab123d2a96b9ef2e8051e8dcd8c/transformed/bundleLibRuntimeToDirDebug/bundleLibRuntimeToDirDebug_dex/expo/modules/aikit/BuildConfig.dex +0 -0
  47. package/android/build/.transforms/c485bab123d2a96b9ef2e8051e8dcd8c/transformed/bundleLibRuntimeToDirDebug/bundleLibRuntimeToDirDebug_dex/expo/modules/aikit/ExpoAiKitModule$definition$1$5$1.dex +0 -0
  48. package/android/build/.transforms/c485bab123d2a96b9ef2e8051e8dcd8c/transformed/bundleLibRuntimeToDirDebug/bundleLibRuntimeToDirDebug_dex/expo/modules/aikit/ExpoAiKitModule$definition$lambda$6$$inlined$AsyncFunction$1.dex +0 -0
  49. package/android/build/.transforms/c485bab123d2a96b9ef2e8051e8dcd8c/transformed/bundleLibRuntimeToDirDebug/bundleLibRuntimeToDirDebug_dex/expo/modules/aikit/ExpoAiKitModule$definition$lambda$6$$inlined$AsyncFunction$2.dex +0 -0
  50. package/android/build/.transforms/c485bab123d2a96b9ef2e8051e8dcd8c/transformed/bundleLibRuntimeToDirDebug/bundleLibRuntimeToDirDebug_dex/expo/modules/aikit/ExpoAiKitModule$definition$lambda$6$$inlined$AsyncFunction$3.dex +0 -0
  51. package/android/build/.transforms/c485bab123d2a96b9ef2e8051e8dcd8c/transformed/bundleLibRuntimeToDirDebug/bundleLibRuntimeToDirDebug_dex/expo/modules/aikit/ExpoAiKitModule$definition$lambda$6$$inlined$AsyncFunctionWithoutArgs$1.dex +0 -0
  52. package/android/build/.transforms/c485bab123d2a96b9ef2e8051e8dcd8c/transformed/bundleLibRuntimeToDirDebug/bundleLibRuntimeToDirDebug_dex/expo/modules/aikit/ExpoAiKitModule$definition$lambda$6$$inlined$Constant$1.dex +0 -0
  53. package/android/build/.transforms/c485bab123d2a96b9ef2e8051e8dcd8c/transformed/bundleLibRuntimeToDirDebug/bundleLibRuntimeToDirDebug_dex/expo/modules/aikit/ExpoAiKitModule$definition$lambda$6$$inlined$FunctionWithoutArgs$1.dex +0 -0
  54. package/android/build/.transforms/c485bab123d2a96b9ef2e8051e8dcd8c/transformed/bundleLibRuntimeToDirDebug/bundleLibRuntimeToDirDebug_dex/expo/modules/aikit/ExpoAiKitModule$definition$lambda$6$$inlined$View$1.dex +0 -0
  55. package/android/build/.transforms/c485bab123d2a96b9ef2e8051e8dcd8c/transformed/bundleLibRuntimeToDirDebug/bundleLibRuntimeToDirDebug_dex/expo/modules/aikit/ExpoAiKitModule$definition$lambda$6$lambda$5$$inlined$Prop$1.dex +0 -0
  56. package/android/build/.transforms/c485bab123d2a96b9ef2e8051e8dcd8c/transformed/bundleLibRuntimeToDirDebug/bundleLibRuntimeToDirDebug_dex/expo/modules/aikit/ExpoAiKitModule.dex +0 -0
  57. package/android/build/.transforms/c485bab123d2a96b9ef2e8051e8dcd8c/transformed/bundleLibRuntimeToDirDebug/bundleLibRuntimeToDirDebug_dex/expo/modules/aikit/ExpoAiKitView$webView$1$1.dex +0 -0
  58. package/android/build/.transforms/c485bab123d2a96b9ef2e8051e8dcd8c/transformed/bundleLibRuntimeToDirDebug/bundleLibRuntimeToDirDebug_dex/expo/modules/aikit/ExpoAiKitView.dex +0 -0
  59. package/android/build/.transforms/c485bab123d2a96b9ef2e8051e8dcd8c/transformed/bundleLibRuntimeToDirDebug/bundleLibRuntimeToDirDebug_dex/expo/modules/aikit/PromptApiClient$isAvailable$1.dex +0 -0
  60. package/android/build/.transforms/c485bab123d2a96b9ef2e8051e8dcd8c/transformed/bundleLibRuntimeToDirDebug/bundleLibRuntimeToDirDebug_dex/expo/modules/aikit/PromptApiClient$isAvailableBlocking$1.dex +0 -0
  61. package/android/build/.transforms/c485bab123d2a96b9ef2e8051e8dcd8c/transformed/bundleLibRuntimeToDirDebug/bundleLibRuntimeToDirDebug_dex/expo/modules/aikit/PromptApiClient.dex +0 -0
  62. package/android/build/.transforms/c485bab123d2a96b9ef2e8051e8dcd8c/transformed/bundleLibRuntimeToDirDebug/desugar_graph.bin +0 -0
  63. package/android/build/.transforms/e7552020676c2f8a620fec964bf11729/results.bin +0 -1
  64. package/android/build/.transforms/e7552020676c2f8a620fec964bf11729/transformed/bundleLibRuntimeToDirDebug/bundleLibRuntimeToDirDebug_dex/expo/modules/aikit/BuildConfig.dex +0 -0
  65. package/android/build/.transforms/e7552020676c2f8a620fec964bf11729/transformed/bundleLibRuntimeToDirDebug/bundleLibRuntimeToDirDebug_dex/expo/modules/aikit/ExpoAiKitModule$definition$1$2$conversationPrompt$2.dex +0 -0
  66. package/android/build/.transforms/e7552020676c2f8a620fec964bf11729/transformed/bundleLibRuntimeToDirDebug/bundleLibRuntimeToDirDebug_dex/expo/modules/aikit/ExpoAiKitModule$definition$1$3$conversationPrompt$2.dex +0 -0
  67. package/android/build/.transforms/e7552020676c2f8a620fec964bf11729/transformed/bundleLibRuntimeToDirDebug/bundleLibRuntimeToDirDebug_dex/expo/modules/aikit/ExpoAiKitModule$definition$1$3$job$1$1.dex +0 -0
  68. package/android/build/.transforms/e7552020676c2f8a620fec964bf11729/transformed/bundleLibRuntimeToDirDebug/bundleLibRuntimeToDirDebug_dex/expo/modules/aikit/ExpoAiKitModule$definition$1$3$job$1.dex +0 -0
  69. package/android/build/.transforms/e7552020676c2f8a620fec964bf11729/transformed/bundleLibRuntimeToDirDebug/bundleLibRuntimeToDirDebug_dex/expo/modules/aikit/ExpoAiKitModule$definition$lambda$11$$inlined$AsyncFunction$1.dex +0 -0
  70. package/android/build/.transforms/e7552020676c2f8a620fec964bf11729/transformed/bundleLibRuntimeToDirDebug/bundleLibRuntimeToDirDebug_dex/expo/modules/aikit/ExpoAiKitModule$definition$lambda$11$$inlined$AsyncFunction$2.dex +0 -0
  71. package/android/build/.transforms/e7552020676c2f8a620fec964bf11729/transformed/bundleLibRuntimeToDirDebug/bundleLibRuntimeToDirDebug_dex/expo/modules/aikit/ExpoAiKitModule$definition$lambda$11$$inlined$AsyncFunction$3.dex +0 -0
  72. package/android/build/.transforms/e7552020676c2f8a620fec964bf11729/transformed/bundleLibRuntimeToDirDebug/bundleLibRuntimeToDirDebug_dex/expo/modules/aikit/ExpoAiKitModule$definition$lambda$11$$inlined$AsyncFunction$4.dex +0 -0
  73. package/android/build/.transforms/e7552020676c2f8a620fec964bf11729/transformed/bundleLibRuntimeToDirDebug/bundleLibRuntimeToDirDebug_dex/expo/modules/aikit/ExpoAiKitModule$definition$lambda$11$$inlined$AsyncFunction$5.dex +0 -0
  74. package/android/build/.transforms/e7552020676c2f8a620fec964bf11729/transformed/bundleLibRuntimeToDirDebug/bundleLibRuntimeToDirDebug_dex/expo/modules/aikit/ExpoAiKitModule$definition$lambda$11$$inlined$AsyncFunction$6.dex +0 -0
  75. package/android/build/.transforms/e7552020676c2f8a620fec964bf11729/transformed/bundleLibRuntimeToDirDebug/bundleLibRuntimeToDirDebug_dex/expo/modules/aikit/ExpoAiKitModule$definition$lambda$11$$inlined$AsyncFunction$7.dex +0 -0
  76. package/android/build/.transforms/e7552020676c2f8a620fec964bf11729/transformed/bundleLibRuntimeToDirDebug/bundleLibRuntimeToDirDebug_dex/expo/modules/aikit/ExpoAiKitModule$definition$lambda$11$$inlined$Coroutine$1.dex +0 -0
  77. package/android/build/.transforms/e7552020676c2f8a620fec964bf11729/transformed/bundleLibRuntimeToDirDebug/bundleLibRuntimeToDirDebug_dex/expo/modules/aikit/ExpoAiKitModule$definition$lambda$11$$inlined$Coroutine$2.dex +0 -0
  78. package/android/build/.transforms/e7552020676c2f8a620fec964bf11729/transformed/bundleLibRuntimeToDirDebug/bundleLibRuntimeToDirDebug_dex/expo/modules/aikit/ExpoAiKitModule$definition$lambda$11$$inlined$Coroutine$3.dex +0 -0
  79. package/android/build/.transforms/e7552020676c2f8a620fec964bf11729/transformed/bundleLibRuntimeToDirDebug/bundleLibRuntimeToDirDebug_dex/expo/modules/aikit/ExpoAiKitModule$definition$lambda$11$$inlined$FunctionWithoutArgs$1.dex +0 -0
  80. package/android/build/.transforms/e7552020676c2f8a620fec964bf11729/transformed/bundleLibRuntimeToDirDebug/bundleLibRuntimeToDirDebug_dex/expo/modules/aikit/ExpoAiKitModule.dex +0 -0
  81. package/android/build/.transforms/e7552020676c2f8a620fec964bf11729/transformed/bundleLibRuntimeToDirDebug/bundleLibRuntimeToDirDebug_dex/expo/modules/aikit/PromptApiClient$generateText$2.dex +0 -0
  82. package/android/build/.transforms/e7552020676c2f8a620fec964bf11729/transformed/bundleLibRuntimeToDirDebug/bundleLibRuntimeToDirDebug_dex/expo/modules/aikit/PromptApiClient$generateTextStream$2$1.dex +0 -0
  83. package/android/build/.transforms/e7552020676c2f8a620fec964bf11729/transformed/bundleLibRuntimeToDirDebug/bundleLibRuntimeToDirDebug_dex/expo/modules/aikit/PromptApiClient$generateTextStream$2.dex +0 -0
  84. package/android/build/.transforms/e7552020676c2f8a620fec964bf11729/transformed/bundleLibRuntimeToDirDebug/bundleLibRuntimeToDirDebug_dex/expo/modules/aikit/PromptApiClient$isAvailable$1.dex +0 -0
  85. package/android/build/.transforms/e7552020676c2f8a620fec964bf11729/transformed/bundleLibRuntimeToDirDebug/bundleLibRuntimeToDirDebug_dex/expo/modules/aikit/PromptApiClient$isAvailableBlocking$1.dex +0 -0
  86. package/android/build/.transforms/e7552020676c2f8a620fec964bf11729/transformed/bundleLibRuntimeToDirDebug/bundleLibRuntimeToDirDebug_dex/expo/modules/aikit/PromptApiClient.dex +0 -0
  87. package/android/build/.transforms/e7552020676c2f8a620fec964bf11729/transformed/bundleLibRuntimeToDirDebug/desugar_graph.bin +0 -0
  88. package/android/build/generated/source/buildConfig/debug/expo/modules/aikit/BuildConfig.java +0 -10
  89. package/android/build/intermediates/aapt_friendly_merged_manifests/debug/processDebugManifest/aapt/AndroidManifest.xml +0 -7
  90. package/android/build/intermediates/aapt_friendly_merged_manifests/debug/processDebugManifest/aapt/output-metadata.json +0 -18
  91. package/android/build/intermediates/aar_metadata/debug/writeDebugAarMetadata/aar-metadata.properties +0 -6
  92. package/android/build/intermediates/annotation_processor_list/debug/javaPreCompileDebug/annotationProcessors.json +0 -1
  93. package/android/build/intermediates/compile_library_classes_jar/debug/bundleLibCompileToJarDebug/classes.jar +0 -0
  94. package/android/build/intermediates/compile_r_class_jar/debug/generateDebugRFile/R.jar +0 -0
  95. package/android/build/intermediates/compile_symbol_list/debug/generateDebugRFile/R.txt +0 -0
  96. package/android/build/intermediates/incremental/debug/packageDebugResources/compile-file-map.properties +0 -1
  97. package/android/build/intermediates/incremental/debug/packageDebugResources/merger.xml +0 -2
  98. package/android/build/intermediates/incremental/mergeDebugAssets/merger.xml +0 -2
  99. package/android/build/intermediates/incremental/mergeDebugJniLibFolders/merger.xml +0 -2
  100. package/android/build/intermediates/incremental/mergeDebugShaders/merger.xml +0 -2
  101. package/android/build/intermediates/java_res/debug/processDebugJavaRes/out/META-INF/expo-ai-kit_debug.kotlin_module +0 -0
  102. package/android/build/intermediates/javac/debug/compileDebugJavaWithJavac/classes/expo/modules/aikit/BuildConfig.class +0 -0
  103. package/android/build/intermediates/local_only_symbol_list/debug/parseDebugLocalResources/R-def.txt +0 -2
  104. package/android/build/intermediates/manifest_merge_blame_file/debug/processDebugManifest/manifest-merger-blame-debug-report.txt +0 -7
  105. package/android/build/intermediates/merged_manifest/debug/processDebugManifest/AndroidManifest.xml +0 -7
  106. package/android/build/intermediates/navigation_json/debug/extractDeepLinksDebug/navigation.json +0 -1
  107. package/android/build/intermediates/nested_resources_validation_report/debug/generateDebugResources/nestedResourcesValidationReport.txt +0 -1
  108. package/android/build/intermediates/runtime_library_classes_dir/debug/bundleLibRuntimeToDirDebug/META-INF/expo-ai-kit_debug.kotlin_module +0 -0
  109. package/android/build/intermediates/runtime_library_classes_dir/debug/bundleLibRuntimeToDirDebug/expo/modules/aikit/BuildConfig.class +0 -0
  110. package/android/build/intermediates/runtime_library_classes_dir/debug/bundleLibRuntimeToDirDebug/expo/modules/aikit/ExpoAiKitModule$definition$1$2$conversationPrompt$2.class +0 -0
  111. package/android/build/intermediates/runtime_library_classes_dir/debug/bundleLibRuntimeToDirDebug/expo/modules/aikit/ExpoAiKitModule$definition$1$3$conversationPrompt$2.class +0 -0
  112. package/android/build/intermediates/runtime_library_classes_dir/debug/bundleLibRuntimeToDirDebug/expo/modules/aikit/ExpoAiKitModule$definition$1$3$job$1$1.class +0 -0
  113. package/android/build/intermediates/runtime_library_classes_dir/debug/bundleLibRuntimeToDirDebug/expo/modules/aikit/ExpoAiKitModule$definition$1$3$job$1.class +0 -0
  114. package/android/build/intermediates/runtime_library_classes_dir/debug/bundleLibRuntimeToDirDebug/expo/modules/aikit/ExpoAiKitModule$definition$lambda$11$$inlined$AsyncFunction$1.class +0 -0
  115. package/android/build/intermediates/runtime_library_classes_dir/debug/bundleLibRuntimeToDirDebug/expo/modules/aikit/ExpoAiKitModule$definition$lambda$11$$inlined$AsyncFunction$2.class +0 -0
  116. package/android/build/intermediates/runtime_library_classes_dir/debug/bundleLibRuntimeToDirDebug/expo/modules/aikit/ExpoAiKitModule$definition$lambda$11$$inlined$AsyncFunction$3.class +0 -0
  117. package/android/build/intermediates/runtime_library_classes_dir/debug/bundleLibRuntimeToDirDebug/expo/modules/aikit/ExpoAiKitModule$definition$lambda$11$$inlined$AsyncFunction$4.class +0 -0
  118. package/android/build/intermediates/runtime_library_classes_dir/debug/bundleLibRuntimeToDirDebug/expo/modules/aikit/ExpoAiKitModule$definition$lambda$11$$inlined$AsyncFunction$5.class +0 -0
  119. package/android/build/intermediates/runtime_library_classes_dir/debug/bundleLibRuntimeToDirDebug/expo/modules/aikit/ExpoAiKitModule$definition$lambda$11$$inlined$AsyncFunction$6.class +0 -0
  120. package/android/build/intermediates/runtime_library_classes_dir/debug/bundleLibRuntimeToDirDebug/expo/modules/aikit/ExpoAiKitModule$definition$lambda$11$$inlined$AsyncFunction$7.class +0 -0
  121. package/android/build/intermediates/runtime_library_classes_dir/debug/bundleLibRuntimeToDirDebug/expo/modules/aikit/ExpoAiKitModule$definition$lambda$11$$inlined$Coroutine$1.class +0 -0
  122. package/android/build/intermediates/runtime_library_classes_dir/debug/bundleLibRuntimeToDirDebug/expo/modules/aikit/ExpoAiKitModule$definition$lambda$11$$inlined$Coroutine$2.class +0 -0
  123. package/android/build/intermediates/runtime_library_classes_dir/debug/bundleLibRuntimeToDirDebug/expo/modules/aikit/ExpoAiKitModule$definition$lambda$11$$inlined$Coroutine$3.class +0 -0
  124. package/android/build/intermediates/runtime_library_classes_dir/debug/bundleLibRuntimeToDirDebug/expo/modules/aikit/ExpoAiKitModule$definition$lambda$11$$inlined$FunctionWithoutArgs$1.class +0 -0
  125. package/android/build/intermediates/runtime_library_classes_dir/debug/bundleLibRuntimeToDirDebug/expo/modules/aikit/ExpoAiKitModule.class +0 -0
  126. package/android/build/intermediates/runtime_library_classes_dir/debug/bundleLibRuntimeToDirDebug/expo/modules/aikit/PromptApiClient$generateText$2.class +0 -0
  127. package/android/build/intermediates/runtime_library_classes_dir/debug/bundleLibRuntimeToDirDebug/expo/modules/aikit/PromptApiClient$generateTextStream$2$1.class +0 -0
  128. package/android/build/intermediates/runtime_library_classes_dir/debug/bundleLibRuntimeToDirDebug/expo/modules/aikit/PromptApiClient$generateTextStream$2.class +0 -0
  129. package/android/build/intermediates/runtime_library_classes_dir/debug/bundleLibRuntimeToDirDebug/expo/modules/aikit/PromptApiClient$isAvailable$1.class +0 -0
  130. package/android/build/intermediates/runtime_library_classes_dir/debug/bundleLibRuntimeToDirDebug/expo/modules/aikit/PromptApiClient$isAvailableBlocking$1.class +0 -0
  131. package/android/build/intermediates/runtime_library_classes_dir/debug/bundleLibRuntimeToDirDebug/expo/modules/aikit/PromptApiClient.class +0 -0
  132. package/android/build/intermediates/runtime_library_classes_jar/debug/bundleLibRuntimeToJarDebug/classes.jar +0 -0
  133. package/android/build/intermediates/symbol_list_with_package_name/debug/generateDebugRFile/package-aware-r.txt +0 -1
  134. package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/inputs/source-to-output.tab +0 -0
  135. package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/inputs/source-to-output.tab.keystream +0 -0
  136. package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/inputs/source-to-output.tab.keystream.len +0 -0
  137. package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/inputs/source-to-output.tab.len +0 -0
  138. package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/inputs/source-to-output.tab.values.at +0 -0
  139. package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/inputs/source-to-output.tab_i +0 -0
  140. package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/inputs/source-to-output.tab_i.len +0 -0
  141. package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/class-attributes.tab +0 -0
  142. package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/class-attributes.tab.keystream +0 -0
  143. package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/class-attributes.tab.keystream.len +0 -0
  144. package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/class-attributes.tab.len +0 -0
  145. package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/class-attributes.tab.values.at +0 -0
  146. package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/class-attributes.tab_i +0 -0
  147. package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/class-attributes.tab_i.len +0 -0
  148. package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/class-fq-name-to-source.tab +0 -0
  149. package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/class-fq-name-to-source.tab.keystream +0 -0
  150. package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/class-fq-name-to-source.tab.keystream.len +0 -0
  151. package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/class-fq-name-to-source.tab.len +0 -0
  152. package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/class-fq-name-to-source.tab.values.at +0 -0
  153. package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/class-fq-name-to-source.tab_i +0 -0
  154. package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/class-fq-name-to-source.tab_i.len +0 -0
  155. package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/internal-name-to-source.tab +0 -0
  156. package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/internal-name-to-source.tab.keystream +0 -0
  157. package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/internal-name-to-source.tab.keystream.len +0 -0
  158. package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/internal-name-to-source.tab.len +0 -0
  159. package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/internal-name-to-source.tab.values.at +0 -0
  160. package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/internal-name-to-source.tab_i +0 -0
  161. package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/internal-name-to-source.tab_i.len +0 -0
  162. package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/proto.tab +0 -0
  163. package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/proto.tab.keystream +0 -0
  164. package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/proto.tab.keystream.len +0 -0
  165. package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/proto.tab.len +0 -0
  166. package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/proto.tab.values.at +0 -0
  167. package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/proto.tab_i +0 -0
  168. package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/proto.tab_i.len +0 -0
  169. package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/source-to-classes.tab +0 -0
  170. package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/source-to-classes.tab.keystream +0 -0
  171. package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/source-to-classes.tab.keystream.len +0 -0
  172. package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/source-to-classes.tab.len +0 -0
  173. package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/source-to-classes.tab.values.at +0 -0
  174. package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/source-to-classes.tab_i +0 -0
  175. package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/source-to-classes.tab_i.len +0 -0
  176. package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/subtypes.tab +0 -0
  177. package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/subtypes.tab.keystream +0 -0
  178. package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/subtypes.tab.keystream.len +0 -0
  179. package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/subtypes.tab.len +0 -0
  180. package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/subtypes.tab.values.at +0 -0
  181. package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/subtypes.tab_i +0 -0
  182. package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/subtypes.tab_i.len +0 -0
  183. package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/supertypes.tab +0 -0
  184. package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/supertypes.tab.keystream +0 -0
  185. package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/supertypes.tab.keystream.len +0 -0
  186. package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/supertypes.tab.len +0 -0
  187. package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/supertypes.tab.values.at +0 -0
  188. package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/supertypes.tab_i +0 -0
  189. package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/supertypes.tab_i.len +0 -0
  190. package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/lookups/counters.tab +0 -2
  191. package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/lookups/file-to-id.tab +0 -0
  192. package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/lookups/file-to-id.tab.keystream +0 -0
  193. package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/lookups/file-to-id.tab.keystream.len +0 -0
  194. package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/lookups/file-to-id.tab.len +0 -0
  195. package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/lookups/file-to-id.tab.values.at +0 -0
  196. package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/lookups/file-to-id.tab_i +0 -0
  197. package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/lookups/file-to-id.tab_i.len +0 -0
  198. package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/lookups/id-to-file.tab +0 -0
  199. package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/lookups/id-to-file.tab.keystream +0 -0
  200. package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/lookups/id-to-file.tab.keystream.len +0 -0
  201. package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/lookups/id-to-file.tab.len +0 -0
  202. package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/lookups/id-to-file.tab.values.at +0 -0
  203. package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/lookups/id-to-file.tab_i +0 -0
  204. package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/lookups/id-to-file.tab_i.len +0 -0
  205. package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/lookups/lookups.tab +0 -0
  206. package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/lookups/lookups.tab.keystream +0 -0
  207. package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/lookups/lookups.tab.keystream.len +0 -0
  208. package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/lookups/lookups.tab.len +0 -0
  209. package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/lookups/lookups.tab.values.at +0 -0
  210. package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/lookups/lookups.tab_i +0 -0
  211. package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/lookups/lookups.tab_i.len +0 -0
  212. package/android/build/kotlin/compileDebugKotlin/cacheable/last-build.bin +0 -0
  213. package/android/build/kotlin/compileDebugKotlin/classpath-snapshot/shrunk-classpath-snapshot.bin +0 -0
  214. package/android/build/kotlin/compileDebugKotlin/local-state/build-history.bin +0 -0
  215. package/android/build/outputs/logs/manifest-merger-debug-report.txt +0 -14
  216. package/android/build/tmp/compileDebugJavaWithJavac/previous-compilation-data.bin +0 -0
  217. package/android/build/tmp/kotlin-classes/debug/META-INF/expo-ai-kit_debug.kotlin_module +0 -0
  218. package/android/build/tmp/kotlin-classes/debug/expo/modules/aikit/ExpoAiKitModule$definition$1$2$conversationPrompt$2.class +0 -0
  219. package/android/build/tmp/kotlin-classes/debug/expo/modules/aikit/ExpoAiKitModule$definition$1$3$conversationPrompt$2.class +0 -0
  220. package/android/build/tmp/kotlin-classes/debug/expo/modules/aikit/ExpoAiKitModule$definition$1$3$job$1$1.class +0 -0
  221. package/android/build/tmp/kotlin-classes/debug/expo/modules/aikit/ExpoAiKitModule$definition$1$3$job$1.class +0 -0
  222. package/android/build/tmp/kotlin-classes/debug/expo/modules/aikit/ExpoAiKitModule$definition$lambda$11$$inlined$AsyncFunction$1.class +0 -0
  223. package/android/build/tmp/kotlin-classes/debug/expo/modules/aikit/ExpoAiKitModule$definition$lambda$11$$inlined$AsyncFunction$2.class +0 -0
  224. package/android/build/tmp/kotlin-classes/debug/expo/modules/aikit/ExpoAiKitModule$definition$lambda$11$$inlined$AsyncFunction$3.class +0 -0
  225. package/android/build/tmp/kotlin-classes/debug/expo/modules/aikit/ExpoAiKitModule$definition$lambda$11$$inlined$AsyncFunction$4.class +0 -0
  226. package/android/build/tmp/kotlin-classes/debug/expo/modules/aikit/ExpoAiKitModule$definition$lambda$11$$inlined$AsyncFunction$5.class +0 -0
  227. package/android/build/tmp/kotlin-classes/debug/expo/modules/aikit/ExpoAiKitModule$definition$lambda$11$$inlined$AsyncFunction$6.class +0 -0
  228. package/android/build/tmp/kotlin-classes/debug/expo/modules/aikit/ExpoAiKitModule$definition$lambda$11$$inlined$AsyncFunction$7.class +0 -0
  229. package/android/build/tmp/kotlin-classes/debug/expo/modules/aikit/ExpoAiKitModule$definition$lambda$11$$inlined$Coroutine$1.class +0 -0
  230. package/android/build/tmp/kotlin-classes/debug/expo/modules/aikit/ExpoAiKitModule$definition$lambda$11$$inlined$Coroutine$2.class +0 -0
  231. package/android/build/tmp/kotlin-classes/debug/expo/modules/aikit/ExpoAiKitModule$definition$lambda$11$$inlined$Coroutine$3.class +0 -0
  232. package/android/build/tmp/kotlin-classes/debug/expo/modules/aikit/ExpoAiKitModule$definition$lambda$11$$inlined$FunctionWithoutArgs$1.class +0 -0
  233. package/android/build/tmp/kotlin-classes/debug/expo/modules/aikit/ExpoAiKitModule.class +0 -0
  234. package/android/build/tmp/kotlin-classes/debug/expo/modules/aikit/PromptApiClient$generateText$2.class +0 -0
  235. package/android/build/tmp/kotlin-classes/debug/expo/modules/aikit/PromptApiClient$generateTextStream$2$1.class +0 -0
  236. package/android/build/tmp/kotlin-classes/debug/expo/modules/aikit/PromptApiClient$generateTextStream$2.class +0 -0
  237. package/android/build/tmp/kotlin-classes/debug/expo/modules/aikit/PromptApiClient$isAvailable$1.class +0 -0
  238. package/android/build/tmp/kotlin-classes/debug/expo/modules/aikit/PromptApiClient$isAvailableBlocking$1.class +0 -0
  239. package/android/build/tmp/kotlin-classes/debug/expo/modules/aikit/PromptApiClient.class +0 -0
package/README.md CHANGED
@@ -1138,7 +1138,7 @@ const { text } = await sendMessage(messages, { systemPrompt: '...' });
1138
1138
  | Web/generic fallback | Idea | Medium |
1139
1139
  | Configurable hyperparameters (temperature, etc.) | Idea | Low |
1140
1140
 
1141
- Have a feature request? [Open an issue](https://github.com/laraelmas/expo-ai-kit/issues)!
1141
+ Have a feature request? [Open an issue](https://github.com/saidkaban/expo-ai-kit/issues)!
1142
1142
 
1143
1143
  ## License
1144
1144
 
@@ -1152,6 +1152,6 @@ Contributions are welcome! Please refer to guidelines described in the [contribu
1152
1152
 
1153
1153
  - [Documentation](https://expo-ai-kit.com)
1154
1154
  - [npm package](https://www.npmjs.com/package/expo-ai-kit)
1155
- - [GitHub repository](https://github.com/laraelmas/expo-ai-kit)
1155
+ - [GitHub repository](https://github.com/saidkaban/expo-ai-kit)
1156
1156
  - [Apple Foundation Models](https://developer.apple.com/documentation/foundationmodels)
1157
1157
  - [Google ML Kit Prompt API](https://developers.google.com/ml-kit/genai)
@@ -1,13 +1,22 @@
1
1
  import type { EventSubscription } from 'expo-modules-core';
2
- import { LLMMessage, LLMResponse, LLMStreamEvent } from './types';
2
+ import { LLMMessage, LLMResponse, LLMStreamEvent, BuiltInModel, DownloadableModelStatus, ModelDownloadProgressEvent, ModelStateChangeEvent } from './types';
3
3
  export type ExpoAiKitModuleEvents = {
4
4
  onStreamToken: (event: LLMStreamEvent) => void;
5
+ onDownloadProgress: (event: ModelDownloadProgressEvent) => void;
6
+ onModelStateChange: (event: ModelStateChangeEvent) => void;
5
7
  };
6
8
  export interface ExpoAiKitNativeModule {
7
9
  isAvailable(): boolean;
8
10
  sendMessage(messages: LLMMessage[], systemPrompt: string): Promise<LLMResponse>;
9
11
  startStreaming(messages: LLMMessage[], systemPrompt: string, sessionId: string): Promise<void>;
10
12
  stopStreaming(sessionId: string): Promise<void>;
13
+ getBuiltInModels(): BuiltInModel[];
14
+ getDownloadableModelStatus(modelId: string): DownloadableModelStatus;
15
+ setModel(modelId: string): Promise<void>;
16
+ getActiveModel(): string;
17
+ unloadModel(): Promise<void>;
18
+ downloadModel(modelId: string, url: string, sha256: string): Promise<void>;
19
+ deleteModel(modelId: string): Promise<void>;
11
20
  addListener<K extends keyof ExpoAiKitModuleEvents>(eventName: K, listener: ExpoAiKitModuleEvents[K]): EventSubscription;
12
21
  }
13
22
  declare const ExpoAiKitModule: ExpoAiKitNativeModule;
@@ -1 +1 @@
1
- {"version":3,"file":"ExpoAiKitModule.d.ts","sourceRoot":"","sources":["../src/ExpoAiKitModule.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AAC3D,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AAElE,MAAM,MAAM,qBAAqB,GAAG;IAClC,aAAa,EAAE,CAAC,KAAK,EAAE,cAAc,KAAK,IAAI,CAAC;CAChD,CAAC;AAEF,MAAM,WAAW,qBAAqB;IACpC,WAAW,IAAI,OAAO,CAAC;IACvB,WAAW,CACT,QAAQ,EAAE,U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AM,GAChB,OAAO,CAAC,IAAI,CAAC,CAAC;IACjB,aAAa,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAGhD,gBAAgB,IAAI,YAAY,EAAE,CAAC;IACnC,0BAA0B,CAAC,OAAO,EAAE,MAAM,GAAG,uBAAuB,CAAC;IAKrE,QAAQ,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IACzC,cAAc,IAAI,MAAM,CAAC;IAGzB,WAAW,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;IAG7B,aAAa,CACX,OAAO,EAAE,MAAM,EACf,GAAG,EAAE,MAAM,EACX,MAAM,EAAE,MAAM,GACb,OAAO,CAAC,IAAI,CAAC,CAAC;IACjB,WAAW,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAG5C,WAAW,CAAC,CAAC,SAAS,MAAM,qBAAqB,EAC/C,SAAS,EAAE,CAAC,EACZ,QAAQ,EAAE,qBAAqB,CAAC,CAAC,CAAC,GACjC,iBAAiB,CAAC;CACtB;AAED,QAAA,MAAM,eAAe,uBACoC,CAAC;AAE1D,eAAe,eAAe,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"ExpoAiKitModule.js","sourceRoot":"","sources":["../src/ExpoAiKitModule.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,mBAAmB,CAAC;AA0BxD,MAAM,eAAe,GACnB,mBAAmB,CAAwB,WAAW,CAAC,CAAC;AAE1D,eAAe,eAAe,CAAC","sourcesContent":["import { requireNativeModule } from 'expo-modules-core';\nimport type { EventSubscription } from 'expo-modules-core';\nimport { LLMMessage, LLMResponse, LLMStreamEvent } from './types';\n\nexport type ExpoAiKitModuleEvents = {\n onStreamToken: (event: LLMStreamEvent) => void;\n};\n\nexport interface ExpoAiKitNativeModule {\n isAvailable(): boolean;\n sendMessage(\n messages: LLMMessage[],\n systemPrompt: string\n ): Promise<LLMResponse>;\n startStreaming(\n messages: LLMMessage[],\n systemPrompt: string,\n sessionId: string\n ): Promise<void>;\n stopStreaming(sessionId: string): Promise<void>;\n addListener<K extends keyof ExpoAiKitModuleEvents>(\n eventName: K,\n listener: ExpoAiKitModuleEvents[K]\n ): EventSubscription;\n}\n\nconst ExpoAiKitModule =\n requireNativeModule<ExpoAiKitNativeModule>('ExpoAiKit');\n\nexport default ExpoAiKitModule;\n"]}
1
+ {"version":3,"file":"ExpoAiKitModule.js","sourceRoot":"","sources":["../src/ExpoAiKitModule.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,mBAAmB,CAAC;AA4DxD,MAAM,eAAe,GACnB,mBAAmB,CAAwB,WAAW,CAAC,CAAC;AAE1D,eAAe,eAAe,CAAC","sourcesContent":["import { requireNativeModule } from 'expo-modules-core';\nimport type { EventSubscription } from 'expo-modules-core';\nimport {\n LLMMessage,\n LLMResponse,\n LLMStreamEvent,\n BuiltInModel,\n DownloadableModelStatus,\n ModelDownloadProgressEvent,\n ModelStateChangeEvent,\n} from './types';\n\nexport type ExpoAiKitModuleEvents = {\n onStreamToken: (event: LLMStreamEvent) => void;\n onDownloadProgress: (event: ModelDownloadProgressEvent) => void;\n onModelStateChange: (event: ModelStateChangeEvent) => void;\n};\n\nexport interface ExpoAiKitNativeModule {\n // Existing inference API\n isAvailable(): boolean;\n sendMessage(\n messages: LLMMessage[],\n systemPrompt: string\n ): Promise<LLMResponse>;\n startStreaming(\n messages: LLMMessage[],\n systemPrompt: string,\n sessionId: string\n ): Promise<void>;\n stopStreaming(sessionId: string): Promise<void>;\n\n // Model discovery\n getBuiltInModels(): BuiltInModel[];\n getDownloadableModelStatus(modelId: string): DownloadableModelStatus;\n\n // Model selection & memory management\n // setModel is async: switching to a downloadable model loads it into memory.\n // Auto-unloads the previous downloadable model (only one loaded at a time).\n setModel(modelId: string): Promise<void>;\n getActiveModel(): string;\n // Explicitly free memory from the loaded downloadable model.\n // Reverts to the platform built-in model.\n unloadModel(): Promise<void>;\n\n // Model lifecycle (downloadable models only)\n downloadModel(\n modelId: string,\n url: string,\n sha256: string\n ): Promise<void>;\n deleteModel(modelId: string): Promise<void>;\n\n // Event subscription\n addListener<K extends keyof ExpoAiKitModuleEvents>(\n eventName: K,\n listener: ExpoAiKitModuleEvents[K]\n ): EventSubscription;\n}\n\nconst ExpoAiKitModule =\n requireNativeModule<ExpoAiKitNativeModule>('ExpoAiKit');\n\nexport default ExpoAiKitModule;\n"]}
package/build/hooks.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import type { UseChatOptions, UseChatReturn, UseCompletionOptions, UseCompletionReturn, UseOnDeviceAIReturn } from './types';
1
+ import type { UseChatOptions, UseChatReturn, UseCompletionOptions, UseCompletionReturn, UseOnDeviceAIReturn, BuiltInModel, DownloadableModel, DownloadableModelStatus, ModelError } from './types';
2
2
  /**
3
3
  * React hook to check if on-device AI is available.
4
4
  *
@@ -85,4 +85,63 @@ export declare function useChat(options?: UseChatOptions): UseChatReturn;
85
85
  * ```
86
86
  */
87
87
  export declare function useCompletion(options?: UseCompletionOptions): UseCompletionReturn;
88
+ /**
89
+ * React hook for managing a downloadable model's lifecycle.
90
+ *
91
+ * Tracks download status, progress, and provides download/delete controls.
92
+ *
93
+ * @param modelId - The downloadable model ID (e.g. 'gemma-e2b')
94
+ * @returns Model status, progress, and control functions
95
+ *
96
+ * @example
97
+ * ```tsx
98
+ * function ModelManager() {
99
+ * const { status, progress, download, delete: remove, error } = useModel('gemma-e2b');
100
+ *
101
+ * if (status === 'not-downloaded') {
102
+ * return <Button title="Download" onPress={download} />;
103
+ * }
104
+ * if (status === 'downloading') {
105
+ * return <Text>Downloading: {Math.round(progress * 100)}%</Text>;
106
+ * }
107
+ * if (status === 'loading') {
108
+ * return <Text>Loading model...</Text>;
109
+ * }
110
+ * return <Text>Model ready!</Text>;
111
+ * }
112
+ * ```
113
+ */
114
+ export declare function useModel(modelId: string): {
115
+ status: DownloadableModelStatus;
116
+ progress: number;
117
+ download: () => Promise<void>;
118
+ delete: () => Promise<void>;
119
+ error: ModelError | null;
120
+ };
121
+ /**
122
+ * React hook to discover all available models (built-in and downloadable).
123
+ *
124
+ * @returns Built-in models, downloadable models, and loading state
125
+ *
126
+ * @example
127
+ * ```tsx
128
+ * function ModelPicker() {
129
+ * const { builtIn, downloadable, isLoading } = useAvailableModels();
130
+ *
131
+ * if (isLoading) return <Text>Loading models...</Text>;
132
+ *
133
+ * return (
134
+ * <View>
135
+ * <Text>Built-in: {builtIn.map(m => m.name).join(', ')}</Text>
136
+ * <Text>Downloadable: {downloadable.map(m => m.name).join(', ')}</Text>
137
+ * </View>
138
+ * );
139
+ * }
140
+ * ```
141
+ */
142
+ export declare function useAvailableModels(): {
143
+ builtIn: BuiltInModel[];
144
+ downloadable: DownloadableModel[];
145
+ isLoading: boolean;
146
+ };
88
147
  //# sourceMappingURL=hooks.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"hooks.d.ts","sourceRoot":"","sources":["../src/hooks.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAEV,cAAc,EACd,aAAa,EACb,oBAAoB,EACpB,mBAAmB,EACnB,mBAAmB,EACpB,MAAM,SAAS,CAAC;AAmBjB;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,aAAa,IAAI,mBAAmB,CAwBnD;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkCG;AACH,wBAAgB,OAAO,CAAC,OAAO,GAAE,cAAmB,GAAG,aAAa,CA8GnE;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,wBAAgB,aAAa,CAAC,OAAO,GAAE,oBAAyB,GAAG,mBAAmB,CAgFrF"}
1
+ {"version":3,"file":"hooks.d.ts","sourceRoot":"","sources":["../src/hooks.ts"],"names":[],"mappings":"AAWA,OAAO,KAAK,EAEV,cAAc,EACd,aAAa,EACb,oBAAoB,EACpB,mBAAmB,EACnB,mBAAmB,EACnB,YAAY,EACZ,iBAAiB,EACjB,uBAAuB,EACvB,UAAU,EACX,MAAM,SAAS,CAAC;AAmBjB;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,aAAa,IAAI,mBAAmB,CAwBnD;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkCG;AACH,wBAAgB,OAAO,CAAC,OAAO,GAAE,cAAmB,GAAG,aAAa,CA8GnE;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,wBAAgB,aAAa,CAAC,OAAO,GAAE,oBAAyB,GAAG,mBAAmB,CAgFrF;AAED;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,wBAAgB,QAAQ,CAAC,OAAO,EAAE,MAAM,GAAG;IACzC,MAAM,EAAE,uBAAuB,CAAC;IAChC,QAAQ,EAAE,MAAM,CAAC;IACjB,QAAQ,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;IAC9B,MAAM,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;IAC5B,KAAK,EAAE,UAAU,GAAG,IAAI,CAAC;CAC1B,CA0EA;AAED;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAgB,kBAAkB,IAAI;IACpC,OAAO,EAAE,YAAY,EAAE,CAAC;IACxB,YAAY,EAAE,iBAAiB,EAAE,CAAC;IAClC,SAAS,EAAE,OAAO,CAAC;CACpB,CAwBA"}
package/build/hooks.js CHANGED
@@ -1,6 +1,7 @@
1
1
  import { useState, useEffect, useRef, useCallback } from 'react';
2
- import { isAvailable, streamMessage } from './index';
2
+ import { isAvailable, streamMessage, getBuiltInModels as getBuiltInModelsApi, getDownloadableModels as getDownloadableModelsApi, downloadModel as downloadModelApi, deleteModel as deleteModelApi, } from './index';
3
3
  import { ChatMemoryManager } from './memory';
4
+ import ExpoAiKitModule from './ExpoAiKitModule';
4
5
  // Cache availability result across all hook instances
5
6
  let availabilityCache = null;
6
7
  let availabilityPromise = null;
@@ -290,4 +291,136 @@ export function useCompletion(options = {}) {
290
291
  error,
291
292
  };
292
293
  }
294
+ /**
295
+ * React hook for managing a downloadable model's lifecycle.
296
+ *
297
+ * Tracks download status, progress, and provides download/delete controls.
298
+ *
299
+ * @param modelId - The downloadable model ID (e.g. 'gemma-e2b')
300
+ * @returns Model status, progress, and control functions
301
+ *
302
+ * @example
303
+ * ```tsx
304
+ * function ModelManager() {
305
+ * const { status, progress, download, delete: remove, error } = useModel('gemma-e2b');
306
+ *
307
+ * if (status === 'not-downloaded') {
308
+ * return <Button title="Download" onPress={download} />;
309
+ * }
310
+ * if (status === 'downloading') {
311
+ * return <Text>Downloading: {Math.round(progress * 100)}%</Text>;
312
+ * }
313
+ * if (status === 'loading') {
314
+ * return <Text>Loading model...</Text>;
315
+ * }
316
+ * return <Text>Model ready!</Text>;
317
+ * }
318
+ * ```
319
+ */
320
+ export function useModel(modelId) {
321
+ const [status, setStatus] = useState('not-downloaded');
322
+ const [progress, setProgress] = useState(0);
323
+ const [error, setError] = useState(null);
324
+ const mountedRef = useRef(true);
325
+ useEffect(() => {
326
+ // Query initial status
327
+ try {
328
+ const initialStatus = ExpoAiKitModule.getDownloadableModelStatus(modelId);
329
+ setStatus(initialStatus);
330
+ }
331
+ catch {
332
+ // Model not found or native module not ready
333
+ }
334
+ // Listen for state changes
335
+ const stateSubscription = ExpoAiKitModule.addListener('onModelStateChange', (event) => {
336
+ if (event.modelId === modelId && mountedRef.current) {
337
+ setStatus(event.status);
338
+ }
339
+ });
340
+ // Listen for download progress
341
+ const progressSubscription = ExpoAiKitModule.addListener('onDownloadProgress', (event) => {
342
+ if (event.modelId === modelId && mountedRef.current) {
343
+ setProgress(event.progress);
344
+ }
345
+ });
346
+ return () => {
347
+ mountedRef.current = false;
348
+ stateSubscription.remove();
349
+ progressSubscription.remove();
350
+ };
351
+ }, [modelId]);
352
+ const download = useCallback(async () => {
353
+ setError(null);
354
+ setProgress(0);
355
+ try {
356
+ await downloadModelApi(modelId, {
357
+ onProgress: (p) => {
358
+ if (mountedRef.current)
359
+ setProgress(p);
360
+ },
361
+ });
362
+ }
363
+ catch (err) {
364
+ if (mountedRef.current) {
365
+ setError(err);
366
+ }
367
+ }
368
+ }, [modelId]);
369
+ const del = useCallback(async () => {
370
+ setError(null);
371
+ try {
372
+ await deleteModelApi(modelId);
373
+ if (mountedRef.current) {
374
+ setStatus('not-downloaded');
375
+ setProgress(0);
376
+ }
377
+ }
378
+ catch (err) {
379
+ if (mountedRef.current) {
380
+ setError(err);
381
+ }
382
+ }
383
+ }, [modelId]);
384
+ return { status, progress, download, delete: del, error };
385
+ }
386
+ /**
387
+ * React hook to discover all available models (built-in and downloadable).
388
+ *
389
+ * @returns Built-in models, downloadable models, and loading state
390
+ *
391
+ * @example
392
+ * ```tsx
393
+ * function ModelPicker() {
394
+ * const { builtIn, downloadable, isLoading } = useAvailableModels();
395
+ *
396
+ * if (isLoading) return <Text>Loading models...</Text>;
397
+ *
398
+ * return (
399
+ * <View>
400
+ * <Text>Built-in: {builtIn.map(m => m.name).join(', ')}</Text>
401
+ * <Text>Downloadable: {downloadable.map(m => m.name).join(', ')}</Text>
402
+ * </View>
403
+ * );
404
+ * }
405
+ * ```
406
+ */
407
+ export function useAvailableModels() {
408
+ const [builtIn, setBuiltIn] = useState([]);
409
+ const [downloadable, setDownloadable] = useState([]);
410
+ const [isLoading, setIsLoading] = useState(true);
411
+ useEffect(() => {
412
+ let mounted = true;
413
+ Promise.all([getBuiltInModelsApi(), getDownloadableModelsApi()]).then(([bi, dl]) => {
414
+ if (mounted) {
415
+ setBuiltIn(bi);
416
+ setDownloadable(dl);
417
+ setIsLoading(false);
418
+ }
419
+ });
420
+ return () => {
421
+ mounted = false;
422
+ };
423
+ }, []);
424
+ return { builtIn, downloadable, isLoading };
425
+ }
293
426
  //# sourceMappingURL=hooks.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"hooks.js","sourceRoot":"","sources":["../src/hooks.ts"],"names":[],"mappings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CAAC,EAAE,YAAY,EAAE,eAAe,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC,SAAS,CAChF,CAAC;YAEF,OAAO,CAAC,OAAO,GAAG,IAAI,CAAC;YACvB,MAAM,QAAQ,GAAG,MAAM,OAAO,CAAC;YAE/B,IAAI,CAAC,UAAU,CAAC,OAAO;gBAAE,OAAO,EAAE,CAAC;YAEnC,aAAa,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;YAC7B,WAAW,CAAC,OAAO,EAAE,CAAC,QAAQ,CAAC,CAAC;YAChC,OAAO,QAAQ,CAAC,IAAI,CAAC;QACvB,CAAC;QAAC,OAAO,GAAG,EAAE,CAAC;YACb,IAAI,CAAC,UAAU,CAAC,OAAO;gBAAE,OAAO,EAAE,CAAC;YACnC,MAAM,CAAC,GAAG,GAAG,YAAY,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,KAAK,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC;YAC9D,QAAQ,CAAC,CAAC,CAAC,CAAC;YACZ,UAAU,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC,CAAC;YACxB,OAAO,EAAE,CAAC;QACZ,CAAC;gBAAS,CAAC;YACT,OAAO,CAAC,OAAO,GAAG,IAAI,CAAC;YACvB,IAAI,UAAU,CAAC,OAAO,EAAE,CAAC;gBACvB,YAAY,CAAC,KAAK,CAAC,CAAC;YACtB,CAAC;QACH,CAAC;IACH,CAAC,EACD,EAAE,CACH,CAAC;IAEF,MAAM,IAAI,GAAG,WAAW,CAAC,GAAG,EAAE;QAC5B,OAAO,CAAC,OAAO,EAAE,EAAE,CAAC;IACtB,CAAC,EAAE,EAAE,CAAC,CAAC;IAEP,OAAO;QACL,UAAU;QACV,SAAS;QACT,QAAQ;QACR,IAAI;QACJ,KAAK;KACN,CAAC;AACJ,CAAC","sourcesContent":["import { useState, useEffect, useRef, useCallback } from 'react';\nimport { isAvailable, streamMessage } from './index';\nimport { ChatMemoryManager } from './memory';\nimport type {\n LLMMessage,\n UseChatOptions,\n UseChatReturn,\n UseCompletionOptions,\n UseCompletionReturn,\n UseOnDeviceAIReturn,\n} from './types';\n\n// Cache availability result across all hook instances\nlet availabilityCache: boolean | null = null;\nlet availabilityPromise: Promise<boolean> | null = null;\n\nfunction checkAvailability(): Promise<boolean> {\n if (availabilityCache !== null) {\n return Promise.resolve(availabilityCache);\n }\n if (!availabilityPromise) {\n availabilityPromise = isAvailable().then((result) => {\n availabilityCache = result;\n return result;\n });\n }\n return availabilityPromise;\n}\n\n/**\n * React hook to check if on-device AI is available.\n *\n * Caches the result so multiple components don't re-check.\n *\n * @returns Object with isAvailable and isChecking states\n *\n * @example\n * ```tsx\n * function MyComponent() {\n * const { isAvailable, isChecking } = useOnDeviceAI();\n *\n * if (isChecking) return <Text>Checking AI availability...</Text>;\n * if (!isAvailable) return <Text>On-device AI not available</Text>;\n *\n * return <ChatComponent />;\n * }\n * ```\n */\nexport function useOnDeviceAI(): UseOnDeviceAIReturn {\n const [available, setAvailable] = useState(availabilityCache ?? false);\n const [checking, setChecking] = useState(availabilityCache === null);\n\n useEffect(() => {\n if (availabilityCache !== null) {\n setAvailable(availabilityCache);\n setChecking(false);\n return;\n }\n\n let mounted = true;\n checkAvailability().then((result) => {\n if (mounted) {\n setAvailable(result);\n setChecking(false);\n }\n });\n return () => {\n mounted = false;\n };\n }, []);\n\n return { isAvailable: available, isChecking: checking };\n}\n\n/**\n * React hook for building chat interfaces with on-device AI.\n *\n * Manages messages, input state, streaming, and conversation memory automatically.\n * Built on top of ChatMemoryManager and streamMessage.\n *\n * @param options - Configuration options for the chat\n * @returns Chat state and control functions\n *\n * @example\n * ```tsx\n * function ChatScreen() {\n * const { messages, input, setInput, sendMessage, isStreaming, stop } = useChat({\n * systemPrompt: 'You are a helpful assistant.',\n * });\n *\n * return (\n * <View>\n * <FlatList\n * data={messages}\n * renderItem={({ item }) => (\n * <Text>{item.role}: {item.content}</Text>\n * )}\n * />\n * <TextInput value={input} onChangeText={setInput} />\n * {isStreaming ? (\n * <Button title=\"Stop\" onPress={stop} />\n * ) : (\n * <Button title=\"Send\" onPress={() => sendMessage()} />\n * )}\n * </View>\n * );\n * }\n * ```\n */\nexport function useChat(options: UseChatOptions = {}): UseChatReturn {\n const { systemPrompt, maxTurns, initialMessages, onFinish, onError } = options;\n\n const memoryRef = useRef(new ChatMemoryManager({ maxTurns, systemPrompt }));\n\n // Initialize with initial messages\n const initializedRef = useRef(false);\n if (!initializedRef.current && initialMessages) {\n for (const msg of initialMessages) {\n memoryRef.current.addMessage(msg);\n }\n initializedRef.current = true;\n }\n\n const [messages, setMessages] = useState<LLMMessage[]>(memoryRef.current.getMessages());\n const [input, setInput] = useState('');\n const [isStreaming, setIsStreaming] = useState(false);\n const [error, setError] = useState<Error | null>(null);\n const stopRef = useRef<(() => void) | null>(null);\n const mountedRef = useRef(true);\n const inputRef = useRef(input);\n inputRef.current = input;\n const streamingRef = useRef(isStreaming);\n streamingRef.current = isStreaming;\n const onFinishRef = useRef(onFinish);\n onFinishRef.current = onFinish;\n const onErrorRef = useRef(onError);\n onErrorRef.current = onError;\n\n useEffect(() => {\n return () => {\n mountedRef.current = false;\n stopRef.current?.();\n };\n }, []);\n\n const send = useCallback(\n async (text?: string) => {\n const content = (text ?? inputRef.current).trim();\n if (!content || streamingRef.current) return;\n\n setError(null);\n\n // Add user message\n memoryRef.current.addUserMessage(content);\n setMessages([...memoryRef.current.getMessages()]);\n if (!text) setInput('');\n\n setIsStreaming(true);\n\n try {\n const allMessages = memoryRef.current.getAllMessages();\n\n // Use a temporary message for streaming display\n let accumulatedText = '';\n const { promise, stop } = streamMessage(allMessages, (event) => {\n if (!mountedRef.current) return;\n accumulatedText = event.accumulatedText;\n // Update messages with streaming assistant response\n const currentMessages = memoryRef.current.getMessages();\n setMessages([\n ...currentMessages,\n { role: 'assistant' as const, content: accumulatedText },\n ]);\n });\n\n stopRef.current = stop;\n const response = await promise;\n\n if (!mountedRef.current) return;\n\n // Add the final assistant message to memory\n memoryRef.current.addAssistantMessage(response.text);\n setMessages([...memoryRef.current.getMessages()]);\n onFinishRef.current?.(response);\n } catch (err) {\n if (!mountedRef.current) return;\n const e = err instanceof Error ? err : new Error(String(err));\n setError(e);\n onErrorRef.current?.(e);\n } finally {\n stopRef.current = null;\n if (mountedRef.current) {\n setIsStreaming(false);\n }\n }\n },\n []\n );\n\n const stop = useCallback(() => {\n stopRef.current?.();\n }, []);\n\n const clear = useCallback(() => {\n memoryRef.current.clear();\n setMessages([]);\n setError(null);\n }, []);\n\n return {\n messages,\n input,\n setInput,\n sendMessage: send,\n isStreaming,\n stop,\n clear,\n error,\n };\n}\n\n/**\n * React hook for single-shot AI completions.\n *\n * Unlike useChat (which manages a conversation), useCompletion is for\n * one-off tasks like summarization, translation, or content generation.\n *\n * @param options - Configuration options\n * @returns Completion state and control functions\n *\n * @example\n * ```tsx\n * function SummarizerScreen() {\n * const { completion, isLoading, complete, stop } = useCompletion({\n * systemPrompt: 'You are a summarization assistant. Summarize the given text concisely.',\n * });\n *\n * return (\n * <View>\n * <Button\n * title=\"Summarize\"\n * onPress={() => complete('Long article text here...')}\n * />\n * {isLoading && <Button title=\"Stop\" onPress={stop} />}\n * <Text>{completion}</Text>\n * </View>\n * );\n * }\n * ```\n */\nexport function useCompletion(options: UseCompletionOptions = {}): UseCompletionReturn {\n const { systemPrompt, onFinish, onError } = options;\n\n const [completion, setCompletion] = useState('');\n const [isLoading, setIsLoading] = useState(false);\n const [error, setError] = useState<Error | null>(null);\n const stopRef = useRef<(() => void) | null>(null);\n const mountedRef = useRef(true);\n const loadingRef = useRef(isLoading);\n loadingRef.current = isLoading;\n const completionRef = useRef(completion);\n completionRef.current = completion;\n const systemPromptRef = useRef(systemPrompt);\n systemPromptRef.current = systemPrompt;\n const onFinishRef = useRef(onFinish);\n onFinishRef.current = onFinish;\n const onErrorRef = useRef(onError);\n onErrorRef.current = onError;\n\n useEffect(() => {\n return () => {\n mountedRef.current = false;\n stopRef.current?.();\n };\n }, []);\n\n const complete = useCallback(\n async (prompt: string) => {\n if (loadingRef.current) return completionRef.current;\n\n setError(null);\n setCompletion('');\n setIsLoading(true);\n\n try {\n const messages: LLMMessage[] = [{ role: 'user', content: prompt }];\n const { promise, stop } = streamMessage(\n messages,\n (event) => {\n if (!mountedRef.current) return;\n setCompletion(event.accumulatedText);\n },\n systemPromptRef.current ? { systemPrompt: systemPromptRef.current } : undefined\n );\n\n stopRef.current = stop;\n const response = await promise;\n\n if (!mountedRef.current) return '';\n\n setCompletion(response.text);\n onFinishRef.current?.(response);\n return response.text;\n } catch (err) {\n if (!mountedRef.current) return '';\n const e = err instanceof Error ? err : new Error(String(err));\n setError(e);\n onErrorRef.current?.(e);\n return '';\n } finally {\n stopRef.current = null;\n if (mountedRef.current) {\n setIsLoading(false);\n }\n }\n },\n []\n );\n\n const stop = useCallback(() => {\n stopRef.current?.();\n }, []);\n\n return {\n completion,\n isLoading,\n complete,\n stop,\n error,\n };\n}\n"]}
1
+ {"version":3,"file":"hooks.js","sourceRoot":"","sources":["../src/hooks.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,OAAO,CAAC;AACjE,OAAO,EACL,WAAW,EACX,aAAa,EACb,gBAAgB,IAAI,mBAAmB,EACvC,qBAAqB,IAAI,wBAAwB,EACjD,aAAa,IAAI,gBAAgB,EACjC,WAAW,IAAI,cAAc,GAC9B,MAAM,SAAS,CAAC;AACjB,OAAO,EAAE,iBAAiB,EAAE,MAAM,UAAU,CAAC;AAC7C,OAAO,eAAe,MAAM,mBAAmB,CAAC;AAchD,sDAAsD;AACtD,IAAI,iBAAiB,GAAmB,IAAI,CAAC;AAC7C,IAAI,mBAAmB,GAA4B,IAAI,CAAC;AAExD,SAAS,iBAAiB;IACxB,IAAI,iBAAiB,KAAK,IAAI,EAAE,CAAC;QAC/B,OAAO,OAAO,CAAC,OAAO,CAAC,iBA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EAAE,EAAE,CAAC,EAAE,EAAE;YACX,IAAI,OAAO,EAAE,CAAC;gBACZ,UAAU,CAAC,EAAE,CAAC,CAAC;gBACf,eAAe,CAAC,EAAE,CAAC,CAAC;gBACpB,YAAY,CAAC,KAAK,CAAC,CAAC;YACtB,CAAC;QACH,CAAC,CACF,CAAC;QAEF,OAAO,GAAG,EAAE;YACV,OAAO,GAAG,KAAK,CAAC;QAClB,CAAC,CAAC;IACJ,CAAC,EAAE,EAAE,CAAC,CAAC;IAEP,OAAO,EAAE,OAAO,EAAE,YAAY,EAAE,SAAS,EAAE,CAAC;AAC9C,CAAC","sourcesContent":["import { useState, useEffect, useRef, useCallback } from 'react';\nimport {\n isAvailable,\n streamMessage,\n getBuiltInModels as getBuiltInModelsApi,\n getDownloadableModels as getDownloadableModelsApi,\n downloadModel as downloadModelApi,\n deleteModel as deleteModelApi,\n} from './index';\nimport { ChatMemoryManager } from './memory';\nimport ExpoAiKitModule from './ExpoAiKitModule';\nimport type {\n LLMMessage,\n UseChatOptions,\n UseChatReturn,\n UseCompletionOptions,\n UseCompletionReturn,\n UseOnDeviceAIReturn,\n BuiltInModel,\n DownloadableModel,\n DownloadableModelStatus,\n ModelError,\n} from './types';\n\n// Cache availability result across all hook instances\nlet availabilityCache: boolean | null = null;\nlet availabilityPromise: Promise<boolean> | null = null;\n\nfunction checkAvailability(): Promise<boolean> {\n if (availabilityCache !== null) {\n return Promise.resolve(availabilityCache);\n }\n if (!availabilityPromise) {\n availabilityPromise = isAvailable().then((result) => {\n availabilityCache = result;\n return result;\n });\n }\n return availabilityPromise;\n}\n\n/**\n * React hook to check if on-device AI is available.\n *\n * Caches the result so multiple components don't re-check.\n *\n * @returns Object with isAvailable and isChecking states\n *\n * @example\n * ```tsx\n * function MyComponent() {\n * const { isAvailable, isChecking } = useOnDeviceAI();\n *\n * if (isChecking) return <Text>Checking AI availability...</Text>;\n * if (!isAvailable) return <Text>On-device AI not available</Text>;\n *\n * return <ChatComponent />;\n * }\n * ```\n */\nexport function useOnDeviceAI(): UseOnDeviceAIReturn {\n const [available, setAvailable] = useState(availabilityCache ?? false);\n const [checking, setChecking] = useState(availabilityCache === null);\n\n useEffect(() => {\n if (availabilityCache !== null) {\n setAvailable(availabilityCache);\n setChecking(false);\n return;\n }\n\n let mounted = true;\n checkAvailability().then((result) => {\n if (mounted) {\n setAvailable(result);\n setChecking(false);\n }\n });\n return () => {\n mounted = false;\n };\n }, []);\n\n return { isAvailable: available, isChecking: checking };\n}\n\n/**\n * React hook for building chat interfaces with on-device AI.\n *\n * Manages messages, input state, streaming, and conversation memory automatically.\n * Built on top of ChatMemoryManager and streamMessage.\n *\n * @param options - Configuration options for the chat\n * @returns Chat state and control functions\n *\n * @example\n * ```tsx\n * function ChatScreen() {\n * const { messages, input, setInput, sendMessage, isStreaming, stop } = useChat({\n * systemPrompt: 'You are a helpful assistant.',\n * });\n *\n * return (\n * <View>\n * <FlatList\n * data={messages}\n * renderItem={({ item }) => (\n * <Text>{item.role}: {item.content}</Text>\n * )}\n * />\n * <TextInput value={input} onChangeText={setInput} />\n * {isStreaming ? (\n * <Button title=\"Stop\" onPress={stop} />\n * ) : (\n * <Button title=\"Send\" onPress={() => sendMessage()} />\n * )}\n * </View>\n * );\n * }\n * ```\n */\nexport function useChat(options: UseChatOptions = {}): UseChatReturn {\n const { systemPrompt, maxTurns, initialMessages, onFinish, onError } = options;\n\n const memoryRef = useRef(new ChatMemoryManager({ maxTurns, systemPrompt }));\n\n // Initialize with initial messages\n const initializedRef = useRef(false);\n if (!initializedRef.current && initialMessages) {\n for (const msg of initialMessages) {\n memoryRef.current.addMessage(msg);\n }\n initializedRef.current = true;\n }\n\n const [messages, setMessages] = useState<LLMMessage[]>(memoryRef.current.getMessages());\n const [input, setInput] = useState('');\n const [isStreaming, setIsStreaming] = useState(false);\n const [error, setError] = useState<Error | null>(null);\n const stopRef = useRef<(() => void) | null>(null);\n const mountedRef = useRef(true);\n const inputRef = useRef(input);\n inputRef.current = input;\n const streamingRef = useRef(isStreaming);\n streamingRef.current = isStreaming;\n const onFinishRef = useRef(onFinish);\n onFinishRef.current = onFinish;\n const onErrorRef = useRef(onError);\n onErrorRef.current = onError;\n\n useEffect(() => {\n return () => {\n mountedRef.current = false;\n stopRef.current?.();\n };\n }, []);\n\n const send = useCallback(\n async (text?: string) => {\n const content = (text ?? inputRef.current).trim();\n if (!content || streamingRef.current) return;\n\n setError(null);\n\n // Add user message\n memoryRef.current.addUserMessage(content);\n setMessages([...memoryRef.current.getMessages()]);\n if (!text) setInput('');\n\n setIsStreaming(true);\n\n try {\n const allMessages = memoryRef.current.getAllMessages();\n\n // Use a temporary message for streaming display\n let accumulatedText = '';\n const { promise, stop } = streamMessage(allMessages, (event) => {\n if (!mountedRef.current) return;\n accumulatedText = event.accumulatedText;\n // Update messages with streaming assistant response\n const currentMessages = memoryRef.current.getMessages();\n setMessages([\n ...currentMessages,\n { role: 'assistant' as const, content: accumulatedText },\n ]);\n });\n\n stopRef.current = stop;\n const response = await promise;\n\n if (!mountedRef.current) return;\n\n // Add the final assistant message to memory\n memoryRef.current.addAssistantMessage(response.text);\n setMessages([...memoryRef.current.getMessages()]);\n onFinishRef.current?.(response);\n } catch (err) {\n if (!mountedRef.current) return;\n const e = err instanceof Error ? err : new Error(String(err));\n setError(e);\n onErrorRef.current?.(e);\n } finally {\n stopRef.current = null;\n if (mountedRef.current) {\n setIsStreaming(false);\n }\n }\n },\n []\n );\n\n const stop = useCallback(() => {\n stopRef.current?.();\n }, []);\n\n const clear = useCallback(() => {\n memoryRef.current.clear();\n setMessages([]);\n setError(null);\n }, []);\n\n return {\n messages,\n input,\n setInput,\n sendMessage: send,\n isStreaming,\n stop,\n clear,\n error,\n };\n}\n\n/**\n * React hook for single-shot AI completions.\n *\n * Unlike useChat (which manages a conversation), useCompletion is for\n * one-off tasks like summarization, translation, or content generation.\n *\n * @param options - Configuration options\n * @returns Completion state and control functions\n *\n * @example\n * ```tsx\n * function SummarizerScreen() {\n * const { completion, isLoading, complete, stop } = useCompletion({\n * systemPrompt: 'You are a summarization assistant. Summarize the given text concisely.',\n * });\n *\n * return (\n * <View>\n * <Button\n * title=\"Summarize\"\n * onPress={() => complete('Long article text here...')}\n * />\n * {isLoading && <Button title=\"Stop\" onPress={stop} />}\n * <Text>{completion}</Text>\n * </View>\n * );\n * }\n * ```\n */\nexport function useCompletion(options: UseCompletionOptions = {}): UseCompletionReturn {\n const { systemPrompt, onFinish, onError } = options;\n\n const [completion, setCompletion] = useState('');\n const [isLoading, setIsLoading] = useState(false);\n const [error, setError] = useState<Error | null>(null);\n const stopRef = useRef<(() => void) | null>(null);\n const mountedRef = useRef(true);\n const loadingRef = useRef(isLoading);\n loadingRef.current = isLoading;\n const completionRef = useRef(completion);\n completionRef.current = completion;\n const systemPromptRef = useRef(systemPrompt);\n systemPromptRef.current = systemPrompt;\n const onFinishRef = useRef(onFinish);\n onFinishRef.current = onFinish;\n const onErrorRef = useRef(onError);\n onErrorRef.current = onError;\n\n useEffect(() => {\n return () => {\n mountedRef.current = false;\n stopRef.current?.();\n };\n }, []);\n\n const complete = useCallback(\n async (prompt: string) => {\n if (loadingRef.current) return completionRef.current;\n\n setError(null);\n setCompletion('');\n setIsLoading(true);\n\n try {\n const messages: LLMMessage[] = [{ role: 'user', content: prompt }];\n const { promise, stop } = streamMessage(\n messages,\n (event) => {\n if (!mountedRef.current) return;\n setCompletion(event.accumulatedText);\n },\n systemPromptRef.current ? { systemPrompt: systemPromptRef.current } : undefined\n );\n\n stopRef.current = stop;\n const response = await promise;\n\n if (!mountedRef.current) return '';\n\n setCompletion(response.text);\n onFinishRef.current?.(response);\n return response.text;\n } catch (err) {\n if (!mountedRef.current) return '';\n const e = err instanceof Error ? err : new Error(String(err));\n setError(e);\n onErrorRef.current?.(e);\n return '';\n } finally {\n stopRef.current = null;\n if (mountedRef.current) {\n setIsLoading(false);\n }\n }\n },\n []\n );\n\n const stop = useCallback(() => {\n stopRef.current?.();\n }, []);\n\n return {\n completion,\n isLoading,\n complete,\n stop,\n error,\n };\n}\n\n/**\n * React hook for managing a downloadable model's lifecycle.\n *\n * Tracks download status, progress, and provides download/delete controls.\n *\n * @param modelId - The downloadable model ID (e.g. 'gemma-e2b')\n * @returns Model status, progress, and control functions\n *\n * @example\n * ```tsx\n * function ModelManager() {\n * const { status, progress, download, delete: remove, error } = useModel('gemma-e2b');\n *\n * if (status === 'not-downloaded') {\n * return <Button title=\"Download\" onPress={download} />;\n * }\n * if (status === 'downloading') {\n * return <Text>Downloading: {Math.round(progress * 100)}%</Text>;\n * }\n * if (status === 'loading') {\n * return <Text>Loading model...</Text>;\n * }\n * return <Text>Model ready!</Text>;\n * }\n * ```\n */\nexport function useModel(modelId: string): {\n status: DownloadableModelStatus;\n progress: number;\n download: () => Promise<void>;\n delete: () => Promise<void>;\n error: ModelError | null;\n} {\n const [status, setStatus] = useState<DownloadableModelStatus>('not-downloaded');\n const [progress, setProgress] = useState(0);\n const [error, setError] = useState<ModelError | null>(null);\n const mountedRef = useRef(true);\n\n useEffect(() => {\n // Query initial status\n try {\n const initialStatus = ExpoAiKitModule.getDownloadableModelStatus(modelId);\n setStatus(initialStatus);\n } catch {\n // Model not found or native module not ready\n }\n\n // Listen for state changes\n const stateSubscription = ExpoAiKitModule.addListener(\n 'onModelStateChange',\n (event) => {\n if (event.modelId === modelId && mountedRef.current) {\n setStatus(event.status);\n }\n }\n );\n\n // Listen for download progress\n const progressSubscription = ExpoAiKitModule.addListener(\n 'onDownloadProgress',\n (event) => {\n if (event.modelId === modelId && mountedRef.current) {\n setProgress(event.progress);\n }\n }\n );\n\n return () => {\n mountedRef.current = false;\n stateSubscription.remove();\n progressSubscription.remove();\n };\n }, [modelId]);\n\n const download = useCallback(async () => {\n setError(null);\n setProgress(0);\n try {\n await downloadModelApi(modelId, {\n onProgress: (p) => {\n if (mountedRef.current) setProgress(p);\n },\n });\n } catch (err) {\n if (mountedRef.current) {\n setError(err as ModelError);\n }\n }\n }, [modelId]);\n\n const del = useCallback(async () => {\n setError(null);\n try {\n await deleteModelApi(modelId);\n if (mountedRef.current) {\n setStatus('not-downloaded');\n setProgress(0);\n }\n } catch (err) {\n if (mountedRef.current) {\n setError(err as ModelError);\n }\n }\n }, [modelId]);\n\n return { status, progress, download, delete: del, error };\n}\n\n/**\n * React hook to discover all available models (built-in and downloadable).\n *\n * @returns Built-in models, downloadable models, and loading state\n *\n * @example\n * ```tsx\n * function ModelPicker() {\n * const { builtIn, downloadable, isLoading } = useAvailableModels();\n *\n * if (isLoading) return <Text>Loading models...</Text>;\n *\n * return (\n * <View>\n * <Text>Built-in: {builtIn.map(m => m.name).join(', ')}</Text>\n * <Text>Downloadable: {downloadable.map(m => m.name).join(', ')}</Text>\n * </View>\n * );\n * }\n * ```\n */\nexport function useAvailableModels(): {\n builtIn: BuiltInModel[];\n downloadable: DownloadableModel[];\n isLoading: boolean;\n} {\n const [builtIn, setBuiltIn] = useState<BuiltInModel[]>([]);\n const [downloadable, setDownloadable] = useState<DownloadableModel[]>([]);\n const [isLoading, setIsLoading] = useState(true);\n\n useEffect(() => {\n let mounted = true;\n\n Promise.all([getBuiltInModelsApi(), getDownloadableModelsApi()]).then(\n ([bi, dl]) => {\n if (mounted) {\n setBuiltIn(bi);\n setDownloadable(dl);\n setIsLoading(false);\n }\n }\n );\n\n return () => {\n mounted = false;\n };\n }, []);\n\n return { builtIn, downloadable, isLoading };\n}\n"]}
package/build/index.d.ts CHANGED
@@ -1,7 +1,8 @@
1
- import { LLMMessage, LLMSendOptions, LLMResponse, LLMStreamOptions, LLMStreamCallback, LLMSummarizeOptions, LLMTranslateOptions, LLMRewriteOptions, LLMExtractKeyPointsOptions, LLMAnswerQuestionOptions, LLMSuggestOptions, LLMSuggestResponse, LLMSmartReplyOptions, LLMAutocompleteOptions } from './types';
1
+ import { LLMMessage, LLMSendOptions, LLMResponse, LLMStreamOptions, LLMStreamCallback, LLMSummarizeOptions, LLMTranslateOptions, LLMRewriteOptions, LLMExtractKeyPointsOptions, LLMAnswerQuestionOptions, LLMSuggestOptions, LLMSuggestResponse, LLMSmartReplyOptions, LLMAutocompleteOptions, BuiltInModel, DownloadableModel } from './types';
2
2
  export * from './types';
3
3
  export * from './memory';
4
4
  export * from './hooks';
5
+ export * from './models';
5
6
  /**
6
7
  * Check if on-device AI is available on the current device.
7
8
  * Returns false on unsupported platforms (web, etc.).
@@ -513,4 +514,84 @@ export declare function streamAutocomplete(partialText: string, onToken: LLMStre
513
514
  * ```
514
515
  */
515
516
  export declare function parseSuggestResponse(raw: string): LLMSuggestResponse;
517
+ /**
518
+ * Get all built-in models available on the current platform.
519
+ *
520
+ * Built-in models are provided by the OS and require no download.
521
+ * On iOS this returns Apple Foundation Models; on Android, ML Kit.
522
+ *
523
+ * @returns Array of built-in models with availability status
524
+ */
525
+ export declare function getBuiltInModels(): Promise<BuiltInModel[]>;
526
+ /**
527
+ * Get all downloadable models from the registry, enriched with on-device status.
528
+ *
529
+ * Reads from the hardcoded MODEL_REGISTRY and queries the native layer
530
+ * for the current download/load status of each model.
531
+ *
532
+ * @returns Array of downloadable models with their current status
533
+ */
534
+ export declare function getDownloadableModels(): Promise<DownloadableModel[]>;
535
+ /**
536
+ * Download a model to the device.
537
+ *
538
+ * Looks up the model in the registry, validates platform support and
539
+ * device requirements, then initiates the download with integrity verification.
540
+ *
541
+ * @param modelId - ID of the model to download (e.g. 'gemma-e2b')
542
+ * @param options - Optional download configuration
543
+ * @param options.onProgress - Callback with download progress (0-1)
544
+ * @throws {ModelError} MODEL_NOT_FOUND if modelId is not in the registry
545
+ * @throws {ModelError} DEVICE_NOT_SUPPORTED if platform is not supported
546
+ * @throws {ModelError} DOWNLOAD_FAILED on network error
547
+ * @throws {ModelError} DOWNLOAD_STORAGE_FULL if insufficient disk space
548
+ * @throws {ModelError} DOWNLOAD_CORRUPT if SHA256 hash doesn't match
549
+ */
550
+ export declare function downloadModel(modelId: string, options?: {
551
+ onProgress?: (progress: number) => void;
552
+ }): Promise<void>;
553
+ /**
554
+ * Delete a downloaded model from the device.
555
+ *
556
+ * If the model is currently loaded, it will be unloaded first.
557
+ *
558
+ * @param modelId - ID of the model to delete
559
+ * @throws {ModelError} MODEL_NOT_FOUND if modelId is not in the registry
560
+ */
561
+ export declare function deleteModel(modelId: string): Promise<void>;
562
+ /**
563
+ * Set the active model for inference.
564
+ *
565
+ * This is the sole gatekeeper for model validity. If setModel succeeds,
566
+ * the model is loaded and ready -- sendMessage never needs its own check.
567
+ *
568
+ * For downloadable models, this loads the model into memory (status
569
+ * transitions: loading -> ready). Only one downloadable model can be
570
+ * loaded at a time; the previous one is auto-unloaded.
571
+ *
572
+ * For built-in models, this simply switches the active backend.
573
+ *
574
+ * If setModel was never called, sendMessage uses the platform built-in
575
+ * model (today's behavior, no error).
576
+ *
577
+ * @param modelId - ID of the model to activate (e.g. 'gemma-e2b', 'apple-fm', 'mlkit')
578
+ * @throws {ModelError} MODEL_NOT_FOUND if modelId is invalid
579
+ * @throws {ModelError} MODEL_NOT_DOWNLOADED if the downloadable model file is not on disk
580
+ * @throws {ModelError} MODEL_LOAD_FAILED if loading into memory fails
581
+ * @throws {ModelError} INFERENCE_OOM if device can't fit model in memory
582
+ */
583
+ export declare function setModel(modelId: string): Promise<void>;
584
+ /**
585
+ * Get the ID of the currently active model.
586
+ *
587
+ * @returns The active model ID (e.g. 'apple-fm', 'mlkit', 'gemma-e2b')
588
+ */
589
+ export declare function getActiveModel(): string;
590
+ /**
591
+ * Explicitly unload the current downloadable model from memory.
592
+ *
593
+ * Frees memory and reverts to the platform built-in model.
594
+ * No-op if no downloadable model is currently loaded.
595
+ */
596
+ export declare function unloadModel(): Promise<void>;
516
597
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAEA,OAAO,EACL,UAAU,EACV,cAAc,EACd,WAAW,EACX,gBAAgB,EAEhB,iBAAiB,EACjB,mBAAmB,EACnB,mBAAmB,EACnB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AC,EAAE,CAAC,QAAQ,EAAE,MAAM,KAAK,IAAI,CAAA;CAAE,GACpD,OAAO,CAAC,IAAI,CAAC,CAmCf;AAED;;;;;;;GAOG;AACH,wBAAsB,WAAW,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAOhE;AAED;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAsB,QAAQ,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAE7D;AAED;;;;GAIG;AACH,wBAAgB,cAAc,IAAI,MAAM,CAEvC;AAED;;;;;GAKG;AACH,wBAAsB,WAAW,IAAI,OAAO,CAAC,IAAI,CAAC,CAEjD"}
package/build/index.js CHANGED
@@ -1,8 +1,11 @@
1
1
  import ExpoAiKitModule from './ExpoAiKitModule';
2
2
  import { Platform } from 'react-native';
3
+ import { ModelError, } from './types';
4
+ import { MODEL_REGISTRY, getRegistryEntry } from './models';
3
5
  export * from './types';
4
6
  export * from './memory';
5
7
  export * from './hooks';
8
+ export * from './models';
6
9
  const DEFAULT_SYSTEM_PROMPT = 'You are a helpful, friendly assistant. Answer the user directly and concisely.';
7
10
  let streamIdCounter = 0;
8
11
  function generateSessionId() {
@@ -890,4 +893,141 @@ export function parseSuggestResponse(raw) {
890
893
  raw,
891
894
  };
892
895
  }
896
+ // ============================================================================
897
+ // Model Management API
898
+ // ============================================================================
899
+ /**
900
+ * Get all built-in models available on the current platform.
901
+ *
902
+ * Built-in models are provided by the OS and require no download.
903
+ * On iOS this returns Apple Foundation Models; on Android, ML Kit.
904
+ *
905
+ * @returns Array of built-in models with availability status
906
+ */
907
+ export async function getBuiltInModels() {
908
+ if (Platform.OS !== 'ios' && Platform.OS !== 'android') {
909
+ return [];
910
+ }
911
+ return ExpoAiKitModule.getBuiltInModels();
912
+ }
913
+ /**
914
+ * Get all downloadable models from the registry, enriched with on-device status.
915
+ *
916
+ * Reads from the hardcoded MODEL_REGISTRY and queries the native layer
917
+ * for the current download/load status of each model.
918
+ *
919
+ * @returns Array of downloadable models with their current status
920
+ */
921
+ export async function getDownloadableModels() {
922
+ if (Platform.OS !== 'ios' && Platform.OS !== 'android') {
923
+ return [];
924
+ }
925
+ const platformModels = MODEL_REGISTRY.filter((entry) => entry.supportedPlatforms.includes(Platform.OS));
926
+ return platformModels.map((entry) => {
927
+ const status = ExpoAiKitModule.getDownloadableModelStatus(entry.id);
928
+ return {
929
+ id: entry.id,
930
+ name: entry.name,
931
+ parameterCount: entry.parameterCount,
932
+ sizeBytes: entry.sizeBytes,
933
+ contextWindow: entry.contextWindow,
934
+ minRamBytes: entry.minRamBytes,
935
+ status,
936
+ };
937
+ });
938
+ }
939
+ /**
940
+ * Download a model to the device.
941
+ *
942
+ * Looks up the model in the registry, validates platform support and
943
+ * device requirements, then initiates the download with integrity verification.
944
+ *
945
+ * @param modelId - ID of the model to download (e.g. 'gemma-e2b')
946
+ * @param options - Optional download configuration
947
+ * @param options.onProgress - Callback with download progress (0-1)
948
+ * @throws {ModelError} MODEL_NOT_FOUND if modelId is not in the registry
949
+ * @throws {ModelError} DEVICE_NOT_SUPPORTED if platform is not supported
950
+ * @throws {ModelError} DOWNLOAD_FAILED on network error
951
+ * @throws {ModelError} DOWNLOAD_STORAGE_FULL if insufficient disk space
952
+ * @throws {ModelError} DOWNLOAD_CORRUPT if SHA256 hash doesn't match
953
+ */
954
+ export async function downloadModel(modelId, options) {
955
+ const entry = getRegistryEntry(modelId);
956
+ if (!entry) {
957
+ throw new ModelError('MODEL_NOT_FOUND', modelId);
958
+ }
959
+ if (!entry.supportedPlatforms.includes(Platform.OS)) {
960
+ throw new ModelError('DEVICE_NOT_SUPPORTED', modelId, `Model ${modelId} is not supported on ${Platform.OS}`);
961
+ }
962
+ let subscription;
963
+ if (options?.onProgress) {
964
+ subscription = ExpoAiKitModule.addListener('onDownloadProgress', (event) => {
965
+ if (event.modelId === modelId) {
966
+ options.onProgress(event.progress);
967
+ }
968
+ });
969
+ }
970
+ try {
971
+ await ExpoAiKitModule.downloadModel(modelId, entry.downloadUrl, entry.sha256);
972
+ }
973
+ finally {
974
+ subscription?.remove();
975
+ }
976
+ }
977
+ /**
978
+ * Delete a downloaded model from the device.
979
+ *
980
+ * If the model is currently loaded, it will be unloaded first.
981
+ *
982
+ * @param modelId - ID of the model to delete
983
+ * @throws {ModelError} MODEL_NOT_FOUND if modelId is not in the registry
984
+ */
985
+ export async function deleteModel(modelId) {
986
+ const entry = getRegistryEntry(modelId);
987
+ if (!entry) {
988
+ throw new ModelError('MODEL_NOT_FOUND', modelId);
989
+ }
990
+ await ExpoAiKitModule.deleteModel(modelId);
991
+ }
992
+ /**
993
+ * Set the active model for inference.
994
+ *
995
+ * This is the sole gatekeeper for model validity. If setModel succeeds,
996
+ * the model is loaded and ready -- sendMessage never needs its own check.
997
+ *
998
+ * For downloadable models, this loads the model into memory (status
999
+ * transitions: loading -> ready). Only one downloadable model can be
1000
+ * loaded at a time; the previous one is auto-unloaded.
1001
+ *
1002
+ * For built-in models, this simply switches the active backend.
1003
+ *
1004
+ * If setModel was never called, sendMessage uses the platform built-in
1005
+ * model (today's behavior, no error).
1006
+ *
1007
+ * @param modelId - ID of the model to activate (e.g. 'gemma-e2b', 'apple-fm', 'mlkit')
1008
+ * @throws {ModelError} MODEL_NOT_FOUND if modelId is invalid
1009
+ * @throws {ModelError} MODEL_NOT_DOWNLOADED if the downloadable model file is not on disk
1010
+ * @throws {ModelError} MODEL_LOAD_FAILED if loading into memory fails
1011
+ * @throws {ModelError} INFERENCE_OOM if device can't fit model in memory
1012
+ */
1013
+ export async function setModel(modelId) {
1014
+ await ExpoAiKitModule.setModel(modelId);
1015
+ }
1016
+ /**
1017
+ * Get the ID of the currently active model.
1018
+ *
1019
+ * @returns The active model ID (e.g. 'apple-fm', 'mlkit', 'gemma-e2b')
1020
+ */
1021
+ export function getActiveModel() {
1022
+ return ExpoAiKitModule.getActiveModel();
1023
+ }
1024
+ /**
1025
+ * Explicitly unload the current downloadable model from memory.
1026
+ *
1027
+ * Frees memory and reverts to the platform built-in model.
1028
+ * No-op if no downloadable model is currently loaded.
1029
+ */
1030
+ export async function unloadModel() {
1031
+ await ExpoAiKitModule.unloadModel();
1032
+ }
893
1033
  //# sourceMappingURL=index.js.map