expo-ai-kit 0.1.17 → 0.1.19

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 (132) hide show
  1. package/README.md +143 -2
  2. package/android/build/.transforms/550f2d3d50c89e495845cc30f2214044/transformed/classes/classes_dex/classes.dex +0 -0
  3. package/android/build/.transforms/e7552020676c2f8a620fec964bf11729/transformed/bundleLibRuntimeToDirDebug/bundleLibRuntimeToDirDebug_dex/expo/modules/aikit/ExpoAiKitModule$definition$1$2$conversationPrompt$2.dex +0 -0
  4. package/android/build/.transforms/e7552020676c2f8a620fec964bf11729/transformed/bundleLibRuntimeToDirDebug/bundleLibRuntimeToDirDebug_dex/expo/modules/aikit/ExpoAiKitModule$definition$1$3$conversationPrompt$2.dex +0 -0
  5. package/android/build/.transforms/e7552020676c2f8a620fec964bf11729/transformed/bundleLibRuntimeToDirDebug/bundleLibRuntimeToDirDebug_dex/expo/modules/aikit/ExpoAiKitModule$definition$1$3$job$1$1.dex +0 -0
  6. package/android/build/.transforms/e7552020676c2f8a620fec964bf11729/transformed/bundleLibRuntimeToDirDebug/bundleLibRuntimeToDirDebug_dex/expo/modules/aikit/ExpoAiKitModule$definition$1$3$job$1.dex +0 -0
  7. package/android/build/.transforms/e7552020676c2f8a620fec964bf11729/transformed/bundleLibRuntimeToDirDebug/bundleLibRuntimeToDirDebug_dex/expo/modules/aikit/ExpoAiKitModule$definition$lambda$11$$inlined$AsyncFunction$1.dex +0 -0
  8. package/android/build/.transforms/e7552020676c2f8a620fec964bf11729/transformed/bundleLibRuntimeToDirDebug/bundleLibRuntimeToDirDebug_dex/expo/modules/aikit/ExpoAiKitModule$definition$lambda$11$$inlined$AsyncFunction$2.dex +0 -0
  9. package/android/build/.transforms/e7552020676c2f8a620fec964bf11729/transformed/bundleLibRuntimeToDirDebug/bundleLibRuntimeToDirDebug_dex/expo/modules/aikit/ExpoAiKitModule$definition$lambda$11$$inlined$AsyncFunction$3.dex +0 -0
  10. package/android/build/.transforms/e7552020676c2f8a620fec964bf11729/transformed/bundleLibRuntimeToDirDebug/bundleLibRuntimeToDirDebug_dex/expo/modules/aikit/ExpoAiKitModule$definition$lambda$11$$inlined$AsyncFunction$4.dex +0 -0
  11. package/android/build/.transforms/e7552020676c2f8a620fec964bf11729/transformed/bundleLibRuntimeToDirDebug/bundleLibRuntimeToDirDebug_dex/expo/modules/aikit/ExpoAiKitModule$definition$lambda$11$$inlined$AsyncFunction$5.dex +0 -0
  12. package/android/build/.transforms/e7552020676c2f8a620fec964bf11729/transformed/bundleLibRuntimeToDirDebug/bundleLibRuntimeToDirDebug_dex/expo/modules/aikit/ExpoAiKitModule$definition$lambda$11$$inlined$AsyncFunction$6.dex +0 -0
  13. package/android/build/.transforms/e7552020676c2f8a620fec964bf11729/transformed/bundleLibRuntimeToDirDebug/bundleLibRuntimeToDirDebug_dex/expo/modules/aikit/ExpoAiKitModule$definition$lambda$11$$inlined$AsyncFunction$7.dex +0 -0
  14. package/android/build/.transforms/e7552020676c2f8a620fec964bf11729/transformed/bundleLibRuntimeToDirDebug/bundleLibRuntimeToDirDebug_dex/expo/modules/aikit/ExpoAiKitModule$definition$lambda$11$$inlined$Coroutine$1.dex +0 -0
  15. package/android/build/.transforms/e7552020676c2f8a620fec964bf11729/transformed/bundleLibRuntimeToDirDebug/bundleLibRuntimeToDirDebug_dex/expo/modules/aikit/ExpoAiKitModule$definition$lambda$11$$inlined$Coroutine$2.dex +0 -0
  16. package/android/build/.transforms/e7552020676c2f8a620fec964bf11729/transformed/bundleLibRuntimeToDirDebug/bundleLibRuntimeToDirDebug_dex/expo/modules/aikit/ExpoAiKitModule$definition$lambda$11$$inlined$Coroutine$3.dex +0 -0
  17. package/android/build/.transforms/e7552020676c2f8a620fec964bf11729/transformed/bundleLibRuntimeToDirDebug/bundleLibRuntimeToDirDebug_dex/expo/modules/aikit/ExpoAiKitModule$definition$lambda$11$$inlined$FunctionWithoutArgs$1.dex +0 -0
  18. package/android/build/.transforms/e7552020676c2f8a620fec964bf11729/transformed/bundleLibRuntimeToDirDebug/bundleLibRuntimeToDirDebug_dex/expo/modules/aikit/ExpoAiKitModule.dex +0 -0
  19. package/android/build/.transforms/e7552020676c2f8a620fec964bf11729/transformed/bundleLibRuntimeToDirDebug/bundleLibRuntimeToDirDebug_dex/expo/modules/aikit/PromptApiClient$generateText$2.dex +0 -0
  20. package/android/build/.transforms/e7552020676c2f8a620fec964bf11729/transformed/bundleLibRuntimeToDirDebug/bundleLibRuntimeToDirDebug_dex/expo/modules/aikit/PromptApiClient$generateTextStream$2$1.dex +0 -0
  21. package/android/build/.transforms/e7552020676c2f8a620fec964bf11729/transformed/bundleLibRuntimeToDirDebug/bundleLibRuntimeToDirDebug_dex/expo/modules/aikit/PromptApiClient$generateTextStream$2.dex +0 -0
  22. package/android/build/.transforms/e7552020676c2f8a620fec964bf11729/transformed/bundleLibRuntimeToDirDebug/bundleLibRuntimeToDirDebug_dex/expo/modules/aikit/PromptApiClient$isAvailable$1.dex +0 -0
  23. package/android/build/.transforms/e7552020676c2f8a620fec964bf11729/transformed/bundleLibRuntimeToDirDebug/bundleLibRuntimeToDirDebug_dex/expo/modules/aikit/PromptApiClient$isAvailableBlocking$1.dex +0 -0
  24. package/android/build/.transforms/e7552020676c2f8a620fec964bf11729/transformed/bundleLibRuntimeToDirDebug/bundleLibRuntimeToDirDebug_dex/expo/modules/aikit/PromptApiClient.dex +0 -0
  25. package/android/build/intermediates/compile_library_classes_jar/debug/bundleLibCompileToJarDebug/classes.jar +0 -0
  26. package/android/build/intermediates/runtime_library_classes_dir/debug/bundleLibRuntimeToDirDebug/expo/modules/aikit/ExpoAiKitModule$definition$1$2$conversationPrompt$2.class +0 -0
  27. package/android/build/intermediates/runtime_library_classes_dir/debug/bundleLibRuntimeToDirDebug/expo/modules/aikit/ExpoAiKitModule$definition$1$3$conversationPrompt$2.class +0 -0
  28. package/android/build/intermediates/runtime_library_classes_dir/debug/bundleLibRuntimeToDirDebug/expo/modules/aikit/ExpoAiKitModule$definition$1$3$job$1$1.class +0 -0
  29. package/android/build/intermediates/runtime_library_classes_dir/debug/bundleLibRuntimeToDirDebug/expo/modules/aikit/ExpoAiKitModule$definition$1$3$job$1.class +0 -0
  30. package/android/build/intermediates/runtime_library_classes_dir/debug/bundleLibRuntimeToDirDebug/expo/modules/aikit/ExpoAiKitModule$definition$lambda$11$$inlined$AsyncFunction$1.class +0 -0
  31. package/android/build/intermediates/runtime_library_classes_dir/debug/bundleLibRuntimeToDirDebug/expo/modules/aikit/{ExpoAiKitModule$definition$lambda$3$$inlined$Coroutine$1.class → ExpoAiKitModule$definition$lambda$11$$inlined$AsyncFunction$2.class} +0 -0
  32. package/android/build/{tmp/kotlin-classes/debug/expo/modules/aikit/ExpoAiKitModule$definition$lambda$3$$inlined$Coroutine$1.class → intermediates/runtime_library_classes_dir/debug/bundleLibRuntimeToDirDebug/expo/modules/aikit/ExpoAiKitModule$definition$lambda$11$$inlined$AsyncFunction$3.class} +0 -0
  33. package/android/build/intermediates/runtime_library_classes_dir/debug/bundleLibRuntimeToDirDebug/expo/modules/aikit/ExpoAiKitModule$definition$lambda$11$$inlined$AsyncFunction$4.class +0 -0
  34. package/android/build/intermediates/runtime_library_classes_dir/debug/bundleLibRuntimeToDirDebug/expo/modules/aikit/ExpoAiKitModule$definition$lambda$11$$inlined$AsyncFunction$5.class +0 -0
  35. package/android/build/intermediates/runtime_library_classes_dir/debug/bundleLibRuntimeToDirDebug/expo/modules/aikit/ExpoAiKitModule$definition$lambda$11$$inlined$AsyncFunction$6.class +0 -0
  36. package/android/build/intermediates/runtime_library_classes_dir/debug/bundleLibRuntimeToDirDebug/expo/modules/aikit/ExpoAiKitModule$definition$lambda$11$$inlined$AsyncFunction$7.class +0 -0
  37. package/android/build/intermediates/runtime_library_classes_dir/debug/bundleLibRuntimeToDirDebug/expo/modules/aikit/ExpoAiKitModule$definition$lambda$11$$inlined$Coroutine$1.class +0 -0
  38. package/android/build/intermediates/runtime_library_classes_dir/debug/bundleLibRuntimeToDirDebug/expo/modules/aikit/ExpoAiKitModule$definition$lambda$11$$inlined$Coroutine$2.class +0 -0
  39. package/android/build/intermediates/runtime_library_classes_dir/debug/bundleLibRuntimeToDirDebug/expo/modules/aikit/ExpoAiKitModule$definition$lambda$11$$inlined$Coroutine$3.class +0 -0
  40. package/android/build/intermediates/runtime_library_classes_dir/debug/bundleLibRuntimeToDirDebug/expo/modules/aikit/ExpoAiKitModule$definition$lambda$11$$inlined$FunctionWithoutArgs$1.class +0 -0
  41. package/android/build/intermediates/runtime_library_classes_dir/debug/bundleLibRuntimeToDirDebug/expo/modules/aikit/ExpoAiKitModule.class +0 -0
  42. package/android/build/intermediates/runtime_library_classes_dir/debug/bundleLibRuntimeToDirDebug/expo/modules/aikit/PromptApiClient$generateText$2.class +0 -0
  43. package/android/build/intermediates/runtime_library_classes_dir/debug/bundleLibRuntimeToDirDebug/expo/modules/aikit/PromptApiClient$generateTextStream$2$1.class +0 -0
  44. package/android/build/intermediates/runtime_library_classes_dir/debug/bundleLibRuntimeToDirDebug/expo/modules/aikit/PromptApiClient$generateTextStream$2.class +0 -0
  45. package/android/build/intermediates/runtime_library_classes_dir/debug/bundleLibRuntimeToDirDebug/expo/modules/aikit/PromptApiClient$isAvailable$1.class +0 -0
  46. package/android/build/intermediates/runtime_library_classes_dir/debug/bundleLibRuntimeToDirDebug/expo/modules/aikit/PromptApiClient$isAvailableBlocking$1.class +0 -0
  47. package/android/build/intermediates/runtime_library_classes_dir/debug/bundleLibRuntimeToDirDebug/expo/modules/aikit/PromptApiClient.class +0 -0
  48. package/android/build/intermediates/runtime_library_classes_jar/debug/bundleLibRuntimeToJarDebug/classes.jar +0 -0
  49. package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/inputs/source-to-output.tab +0 -0
  50. package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/inputs/source-to-output.tab.values.at +0 -0
  51. package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/class-attributes.tab +0 -0
  52. package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/class-attributes.tab.values.at +0 -0
  53. package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/class-fq-name-to-source.tab +0 -0
  54. package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/class-fq-name-to-source.tab.values.at +0 -0
  55. package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/internal-name-to-source.tab +0 -0
  56. package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/internal-name-to-source.tab.keystream +0 -0
  57. package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/internal-name-to-source.tab.keystream.len +0 -0
  58. package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/internal-name-to-source.tab.len +0 -0
  59. package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/internal-name-to-source.tab.values.at +0 -0
  60. package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/internal-name-to-source.tab_i +0 -0
  61. package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/proto.tab +0 -0
  62. package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/proto.tab.values.at +0 -0
  63. package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/source-to-classes.tab +0 -0
  64. package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/source-to-classes.tab.values.at +0 -0
  65. package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/subtypes.tab +0 -0
  66. package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/subtypes.tab.values.at +0 -0
  67. package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/supertypes.tab +0 -0
  68. package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/supertypes.tab.values.at +0 -0
  69. package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/lookups/counters.tab +1 -1
  70. package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/lookups/file-to-id.tab +0 -0
  71. package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/lookups/file-to-id.tab.values.at +0 -0
  72. package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/lookups/id-to-file.tab +0 -0
  73. package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/lookups/id-to-file.tab.keystream +0 -0
  74. package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/lookups/id-to-file.tab.keystream.len +0 -0
  75. package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/lookups/id-to-file.tab.len +0 -0
  76. package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/lookups/id-to-file.tab.values.at +0 -0
  77. package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/lookups/id-to-file.tab_i +0 -0
  78. package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/lookups/lookups.tab +0 -0
  79. package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/lookups/lookups.tab.keystream +0 -0
  80. package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/lookups/lookups.tab.keystream.len +0 -0
  81. package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/lookups/lookups.tab.len +0 -0
  82. package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/lookups/lookups.tab.values.at +0 -0
  83. package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/lookups/lookups.tab_i +0 -0
  84. package/android/build/kotlin/compileDebugKotlin/cacheable/last-build.bin +0 -0
  85. package/android/build/kotlin/compileDebugKotlin/classpath-snapshot/shrunk-classpath-snapshot.bin +0 -0
  86. package/android/build/kotlin/compileDebugKotlin/local-state/build-history.bin +0 -0
  87. package/android/build/tmp/kotlin-classes/debug/expo/modules/aikit/ExpoAiKitModule$definition$1$2$conversationPrompt$2.class +0 -0
  88. package/android/build/tmp/kotlin-classes/debug/expo/modules/aikit/ExpoAiKitModule$definition$1$3$conversationPrompt$2.class +0 -0
  89. package/android/build/tmp/kotlin-classes/debug/expo/modules/aikit/ExpoAiKitModule$definition$1$3$job$1$1.class +0 -0
  90. package/android/build/tmp/kotlin-classes/debug/expo/modules/aikit/ExpoAiKitModule$definition$1$3$job$1.class +0 -0
  91. package/android/build/tmp/kotlin-classes/debug/expo/modules/aikit/ExpoAiKitModule$definition$lambda$11$$inlined$AsyncFunction$1.class +0 -0
  92. package/android/build/tmp/kotlin-classes/debug/expo/modules/aikit/ExpoAiKitModule$definition$lambda$11$$inlined$AsyncFunction$2.class +0 -0
  93. package/android/build/tmp/kotlin-classes/debug/expo/modules/aikit/ExpoAiKitModule$definition$lambda$11$$inlined$AsyncFunction$3.class +0 -0
  94. package/android/build/tmp/kotlin-classes/debug/expo/modules/aikit/ExpoAiKitModule$definition$lambda$11$$inlined$AsyncFunction$4.class +0 -0
  95. package/android/build/tmp/kotlin-classes/debug/expo/modules/aikit/ExpoAiKitModule$definition$lambda$11$$inlined$AsyncFunction$5.class +0 -0
  96. package/android/build/tmp/kotlin-classes/debug/expo/modules/aikit/ExpoAiKitModule$definition$lambda$11$$inlined$AsyncFunction$6.class +0 -0
  97. package/android/build/tmp/kotlin-classes/debug/expo/modules/aikit/ExpoAiKitModule$definition$lambda$11$$inlined$AsyncFunction$7.class +0 -0
  98. package/android/build/tmp/kotlin-classes/debug/expo/modules/aikit/ExpoAiKitModule$definition$lambda$11$$inlined$Coroutine$1.class +0 -0
  99. package/android/build/tmp/kotlin-classes/debug/expo/modules/aikit/ExpoAiKitModule$definition$lambda$11$$inlined$Coroutine$2.class +0 -0
  100. package/android/build/tmp/kotlin-classes/debug/expo/modules/aikit/ExpoAiKitModule$definition$lambda$11$$inlined$Coroutine$3.class +0 -0
  101. package/android/build/tmp/kotlin-classes/debug/expo/modules/aikit/ExpoAiKitModule$definition$lambda$11$$inlined$FunctionWithoutArgs$1.class +0 -0
  102. package/android/build/tmp/kotlin-classes/debug/expo/modules/aikit/ExpoAiKitModule.class +0 -0
  103. package/android/build/tmp/kotlin-classes/debug/expo/modules/aikit/PromptApiClient$generateText$2.class +0 -0
  104. package/android/build/tmp/kotlin-classes/debug/expo/modules/aikit/PromptApiClient$generateTextStream$2$1.class +0 -0
  105. package/android/build/tmp/kotlin-classes/debug/expo/modules/aikit/PromptApiClient$generateTextStream$2.class +0 -0
  106. package/android/build/tmp/kotlin-classes/debug/expo/modules/aikit/PromptApiClient$isAvailable$1.class +0 -0
  107. package/android/build/tmp/kotlin-classes/debug/expo/modules/aikit/PromptApiClient$isAvailableBlocking$1.class +0 -0
  108. package/android/build/tmp/kotlin-classes/debug/expo/modules/aikit/PromptApiClient.class +0 -0
  109. package/android/src/main/java/expo/modules/aikit/ExpoAiKitModule.kt +20 -12
  110. package/build/index.d.ts +1 -0
  111. package/build/index.d.ts.map +1 -1
  112. package/build/index.js +1 -0
  113. package/build/index.js.map +1 -1
  114. package/build/memory.d.ts +218 -0
  115. package/build/memory.d.ts.map +1 -0
  116. package/build/memory.js +310 -0
  117. package/build/memory.js.map +1 -0
  118. package/build/types.d.ts +28 -0
  119. package/build/types.d.ts.map +1 -1
  120. package/build/types.js.map +1 -1
  121. package/ios/ExpoAiKitModule.swift +28 -20
  122. package/package.json +1 -1
  123. package/src/index.ts +1 -0
  124. package/src/memory.ts +342 -0
  125. package/src/types.ts +34 -0
  126. package/android/build/.transforms/e7552020676c2f8a620fec964bf11729/transformed/bundleLibRuntimeToDirDebug/bundleLibRuntimeToDirDebug_dex/expo/modules/aikit/ExpoAiKitModule$definition$lambda$3$$inlined$AsyncFunctionWithoutArgs$1.dex +0 -0
  127. package/android/build/.transforms/e7552020676c2f8a620fec964bf11729/transformed/bundleLibRuntimeToDirDebug/bundleLibRuntimeToDirDebug_dex/expo/modules/aikit/ExpoAiKitModule$definition$lambda$3$$inlined$Coroutine$1.dex +0 -0
  128. package/android/build/.transforms/e7552020676c2f8a620fec964bf11729/transformed/bundleLibRuntimeToDirDebug/bundleLibRuntimeToDirDebug_dex/expo/modules/aikit/ExpoAiKitModule$definition$lambda$3$$inlined$Coroutine$2.dex +0 -0
  129. package/android/build/intermediates/runtime_library_classes_dir/debug/bundleLibRuntimeToDirDebug/expo/modules/aikit/ExpoAiKitModule$definition$lambda$3$$inlined$AsyncFunctionWithoutArgs$1.class +0 -0
  130. package/android/build/intermediates/runtime_library_classes_dir/debug/bundleLibRuntimeToDirDebug/expo/modules/aikit/ExpoAiKitModule$definition$lambda$3$$inlined$Coroutine$2.class +0 -0
  131. package/android/build/tmp/kotlin-classes/debug/expo/modules/aikit/ExpoAiKitModule$definition$lambda$3$$inlined$AsyncFunctionWithoutArgs$1.class +0 -0
  132. package/android/build/tmp/kotlin-classes/debug/expo/modules/aikit/ExpoAiKitModule$definition$lambda$3$$inlined$Coroutine$2.class +0 -0
package/README.md CHANGED
@@ -31,6 +31,7 @@ On-device AI for Expo apps. Run language models locally—no API keys, no cloud,
31
31
  - **Streaming support** — Progressive token streaming for responsive UIs
32
32
  - **Simple API** — Core functions plus prompt helpers for common tasks
33
33
  - **Prompt helpers** — Built-in `summarize()`, `translate()`, `rewrite()`, and more
34
+ - **Chat memory** — Built-in `ChatMemoryManager` for managing conversation history
34
35
 
35
36
  ## Requirements
36
37
 
@@ -126,7 +127,38 @@ console.log(response.text);
126
127
 
127
128
  ### Multi-turn Conversations
128
129
 
129
- For conversations with context, pass the full conversation history:
130
+ For conversations with context, use `ChatMemoryManager` to manage history:
131
+
132
+ ```tsx
133
+ import { ChatMemoryManager, streamMessage } from 'expo-ai-kit';
134
+
135
+ // Create a memory manager (handles history automatically)
136
+ const memory = new ChatMemoryManager({
137
+ maxTurns: 10,
138
+ systemPrompt: 'You are a helpful assistant.',
139
+ });
140
+
141
+ // Add user message and get response
142
+ memory.addUserMessage('My name is Alice.');
143
+ const { promise } = streamMessage(
144
+ memory.getAllMessages(),
145
+ (event) => console.log(event.accumulatedText)
146
+ );
147
+ const response = await promise;
148
+
149
+ // Store assistant response in memory
150
+ memory.addAssistantMessage(response.text);
151
+
152
+ // Continue the conversation (memory includes full history)
153
+ memory.addUserMessage('What is my name?');
154
+ const { promise: p2 } = streamMessage(
155
+ memory.getAllMessages(),
156
+ (event) => console.log(event.accumulatedText)
157
+ );
158
+ // Response: "Your name is Alice."
159
+ ```
160
+
161
+ Or manually manage the conversation array:
130
162
 
131
163
  ```tsx
132
164
  import { sendMessage, type LLMMessage } from 'expo-ai-kit';
@@ -505,6 +537,99 @@ function answerQuestion(question: string, context: string, options?: LLMAnswerQu
505
537
 
506
538
  ---
507
539
 
540
+ ### `ChatMemoryManager`
541
+
542
+ Manages conversation history for stateless on-device AI models. Automatically handles turn limits and provides the full message array for each request.
543
+
544
+ ```typescript
545
+ class ChatMemoryManager {
546
+ constructor(options?: ChatMemoryOptions);
547
+
548
+ addUserMessage(content: string): void;
549
+ addAssistantMessage(content: string): void;
550
+ addMessage(message: LLMMessage): void;
551
+
552
+ getAllMessages(): LLMMessage[];
553
+ getMessages(): LLMMessage[];
554
+ getPrompt(): string;
555
+ getSnapshot(): ChatMemorySnapshot;
556
+ getTurnCount(): number;
557
+
558
+ setSystemPrompt(prompt: string | undefined): void;
559
+ getSystemPrompt(): string | undefined;
560
+ setMaxTurns(maxTurns: number): void;
561
+
562
+ clear(): void;
563
+ reset(): void;
564
+ }
565
+ ```
566
+
567
+ | Option | Type | Description |
568
+ |--------|------|-------------|
569
+ | `maxTurns` | `number` | Maximum conversation turns to keep (default: `10`) |
570
+ | `systemPrompt` | `string` | System prompt to include in every request |
571
+
572
+ **Why use ChatMemoryManager?**
573
+
574
+ On-device models are stateless — they have no built-in memory. Each request must include the full conversation history. `ChatMemoryManager` handles this automatically:
575
+
576
+ - Stores messages client-side
577
+ - Automatically trims old messages when limit is reached
578
+ - Preserves the system prompt (never trimmed)
579
+ - Provides `getAllMessages()` for API calls
580
+
581
+ **Example with React:**
582
+
583
+ ```tsx
584
+ import { useRef } from 'react';
585
+ import { ChatMemoryManager, streamMessage } from 'expo-ai-kit';
586
+
587
+ function Chat() {
588
+ const memoryRef = useRef(new ChatMemoryManager({
589
+ maxTurns: 10,
590
+ systemPrompt: 'You are a helpful assistant.',
591
+ }));
592
+
593
+ const sendMessage = async (text: string) => {
594
+ memoryRef.current.addUserMessage(text);
595
+
596
+ const { promise } = streamMessage(
597
+ memoryRef.current.getAllMessages(),
598
+ (event) => setResponse(event.accumulatedText)
599
+ );
600
+
601
+ const response = await promise;
602
+ memoryRef.current.addAssistantMessage(response.text);
603
+ };
604
+
605
+ const clearChat = () => memoryRef.current.clear();
606
+ }
607
+ ```
608
+
609
+ ---
610
+
611
+ ### `buildPrompt(messages)`
612
+
613
+ Converts a message array to a single prompt string. Useful for debugging or custom implementations.
614
+
615
+ ```typescript
616
+ function buildPrompt(messages: LLMMessage[]): string
617
+ ```
618
+
619
+ **Example:**
620
+ ```tsx
621
+ import { buildPrompt } from 'expo-ai-kit';
622
+
623
+ const prompt = buildPrompt([
624
+ { role: 'system', content: 'You are helpful.' },
625
+ { role: 'user', content: 'Hi!' },
626
+ { role: 'assistant', content: 'Hello!' },
627
+ ]);
628
+ // "SYSTEM: You are helpful.\nUSER: Hi!\nASSISTANT: Hello!"
629
+ ```
630
+
631
+ ---
632
+
508
633
  ### Types
509
634
 
510
635
  ```typescript
@@ -566,6 +691,21 @@ type LLMExtractKeyPointsOptions = {
566
691
  type LLMAnswerQuestionOptions = {
567
692
  detail?: 'brief' | 'medium' | 'detailed';
568
693
  };
694
+
695
+ // Chat Memory Types
696
+ type ChatMemoryOptions = {
697
+ /** Maximum conversation turns to keep (default: 10) */
698
+ maxTurns?: number;
699
+ /** System prompt to include in every request */
700
+ systemPrompt?: string;
701
+ };
702
+
703
+ type ChatMemorySnapshot = {
704
+ messages: LLMMessage[];
705
+ systemPrompt: string | undefined;
706
+ turnCount: number;
707
+ maxTurns: number;
708
+ };
569
709
  ```
570
710
 
571
711
  ## Feature Comparison
@@ -576,6 +716,7 @@ type LLMAnswerQuestionOptions = {
576
716
  | `sendMessage()` | ✅ | ✅ |
577
717
  | `streamMessage()` | ✅ | ✅ |
578
718
  | Prompt helpers | ✅ | ✅ |
719
+ | `ChatMemoryManager` | ✅ | ✅ |
579
720
  | System prompts | ✅ Native | ✅ Prepended |
580
721
  | Multi-turn context | ✅ | ✅ |
581
722
  | Cancel streaming | ✅ | ✅ |
@@ -627,7 +768,7 @@ const { text } = await sendMessage(messages, { systemPrompt: '...' });
627
768
  |---------|--------|----------|
628
769
  | ✅ Streaming responses | Done | - |
629
770
  | ✅ Prompt helpers (summarize, translate, etc.) | Done | - |
630
- | Conversation memory (useChat hook) | Planned | High |
771
+ | Chat memory management | Done | - |
631
772
  | Web/generic fallback | Idea | Medium |
632
773
  | Configurable hyperparameters (temperature, etc.) | Idea | Low |
633
774
 
@@ -32,13 +32,17 @@ class ExpoAiKitModule : Module() {
32
32
  ?.get("content") as? String
33
33
  ?: fallbackSystemPrompt.ifBlank { "You are a helpful, friendly assistant." }
34
34
 
35
- // Get the last user message as the prompt
36
- val userPrompt = messages
37
- .lastOrNull { it["role"] == "user" }
38
- ?.get("content") as? String
39
- ?: ""
35
+ // Build conversation history prompt from all non-system messages
36
+ // On-device models are stateless, so we must include full history in each request
37
+ val conversationPrompt = messages
38
+ .filter { it["role"] != "system" }
39
+ .joinToString("\n") { msg ->
40
+ val role = (msg["role"] as? String ?: "user").uppercase()
41
+ val content = msg["content"] as? String ?: ""
42
+ "$role: $content"
43
+ } + "\nASSISTANT:"
40
44
 
41
- val text = promptClient.generateText(userPrompt, systemPrompt)
45
+ val text = promptClient.generateText(conversationPrompt, systemPrompt)
42
46
  mapOf("text" to text)
43
47
  }
44
48
 
@@ -49,15 +53,19 @@ class ExpoAiKitModule : Module() {
49
53
  ?.get("content") as? String
50
54
  ?: fallbackSystemPrompt.ifBlank { "You are a helpful, friendly assistant." }
51
55
 
52
- // Get the last user message as the prompt
53
- val userPrompt = messages
54
- .lastOrNull { it["role"] == "user" }
55
- ?.get("content") as? String
56
- ?: ""
56
+ // Build conversation history prompt from all non-system messages
57
+ // On-device models are stateless, so we must include full history in each request
58
+ val conversationPrompt = messages
59
+ .filter { it["role"] != "system" }
60
+ .joinToString("\n") { msg ->
61
+ val role = (msg["role"] as? String ?: "user").uppercase()
62
+ val content = msg["content"] as? String ?: ""
63
+ "$role: $content"
64
+ } + "\nASSISTANT:"
57
65
 
58
66
  // Launch streaming in a coroutine that can be cancelled
59
67
  val job = streamScope.launch {
60
- promptClient.generateTextStream(userPrompt, systemPrompt) { token, accumulatedText, isDone ->
68
+ promptClient.generateTextStream(conversationPrompt, systemPrompt) { token, accumulatedText, isDone ->
61
69
  sendEvent("onStreamToken", mapOf(
62
70
  "sessionId" to sessionId,
63
71
  "token" to token,
package/build/index.d.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  import { LLMMessage, LLMSendOptions, LLMResponse, LLMStreamOptions, LLMStreamCallback, LLMSummarizeOptions, LLMTranslateOptions, LLMRewriteOptions, LLMExtractKeyPointsOptions, LLMAnswerQuestionOptions } from './types';
2
2
  export * from './types';
3
+ export * from './memory';
3
4
  /**
4
5
  * Check if on-device AI is available on the current device.
5
6
  * Returns false on unsupported platforms (web, etc.).
@@ -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,iBAAiB,EACjB,0BAA0B,EAC1B,wBAAwB,EACzB,MAAM,SAAS,CAAC;AAEjB,cAAc,SAAS,CAAC;AAkGxB;;;GAGG;AACH,wBAAsB,WAAW,IAAI,OAAO,CAAC,OAAO,CAAC,CAKpD;AAED;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ACf,OAAO,CAAC,EAAE,wBAAwB,GACjC,OAAO,CAAC,WAAW,CAAC,CAkBtB;AAED;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAgB,oBAAoB,CAClC,QAAQ,EAAE,MAAM,EAChB,OAAO,EAAE,MAAM,EACf,OAAO,EAAE,iBAAiB,EAC1B,OAAO,CAAC,EAAE,wBAAwB,GACjC;IAAE,OAAO,EAAE,OAAO,CAAC,WAAW,CAAC,CAAC;IAAC,IAAI,EAAE,MAAM,IAAI,CAAA;CAAE,CA0BrD"}
package/build/index.js CHANGED
@@ -1,6 +1,7 @@
1
1
  import ExpoAiKitModule from './ExpoAiKitModule';
2
2
  import { Platform } from 'react-native';
3
3
  export * from './types';
4
+ export * from './memory';
4
5
  const DEFAULT_SYSTEM_PROMPT = 'You are a helpful, friendly assistant. Answer the user directly and concisely.';
5
6
  let streamIdCounter = 0;
6
7
  function generateSessionId() {