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.
- package/README.md +143 -2
- package/android/build/.transforms/550f2d3d50c89e495845cc30f2214044/transformed/classes/classes_dex/classes.dex +0 -0
- package/android/build/.transforms/e7552020676c2f8a620fec964bf11729/transformed/bundleLibRuntimeToDirDebug/bundleLibRuntimeToDirDebug_dex/expo/modules/aikit/ExpoAiKitModule$definition$1$2$conversationPrompt$2.dex +0 -0
- package/android/build/.transforms/e7552020676c2f8a620fec964bf11729/transformed/bundleLibRuntimeToDirDebug/bundleLibRuntimeToDirDebug_dex/expo/modules/aikit/ExpoAiKitModule$definition$1$3$conversationPrompt$2.dex +0 -0
- package/android/build/.transforms/e7552020676c2f8a620fec964bf11729/transformed/bundleLibRuntimeToDirDebug/bundleLibRuntimeToDirDebug_dex/expo/modules/aikit/ExpoAiKitModule$definition$1$3$job$1$1.dex +0 -0
- package/android/build/.transforms/e7552020676c2f8a620fec964bf11729/transformed/bundleLibRuntimeToDirDebug/bundleLibRuntimeToDirDebug_dex/expo/modules/aikit/ExpoAiKitModule$definition$1$3$job$1.dex +0 -0
- package/android/build/.transforms/e7552020676c2f8a620fec964bf11729/transformed/bundleLibRuntimeToDirDebug/bundleLibRuntimeToDirDebug_dex/expo/modules/aikit/ExpoAiKitModule$definition$lambda$11$$inlined$AsyncFunction$1.dex +0 -0
- package/android/build/.transforms/e7552020676c2f8a620fec964bf11729/transformed/bundleLibRuntimeToDirDebug/bundleLibRuntimeToDirDebug_dex/expo/modules/aikit/ExpoAiKitModule$definition$lambda$11$$inlined$AsyncFunction$2.dex +0 -0
- package/android/build/.transforms/e7552020676c2f8a620fec964bf11729/transformed/bundleLibRuntimeToDirDebug/bundleLibRuntimeToDirDebug_dex/expo/modules/aikit/ExpoAiKitModule$definition$lambda$11$$inlined$AsyncFunction$3.dex +0 -0
- package/android/build/.transforms/e7552020676c2f8a620fec964bf11729/transformed/bundleLibRuntimeToDirDebug/bundleLibRuntimeToDirDebug_dex/expo/modules/aikit/ExpoAiKitModule$definition$lambda$11$$inlined$AsyncFunction$4.dex +0 -0
- package/android/build/.transforms/e7552020676c2f8a620fec964bf11729/transformed/bundleLibRuntimeToDirDebug/bundleLibRuntimeToDirDebug_dex/expo/modules/aikit/ExpoAiKitModule$definition$lambda$11$$inlined$AsyncFunction$5.dex +0 -0
- package/android/build/.transforms/e7552020676c2f8a620fec964bf11729/transformed/bundleLibRuntimeToDirDebug/bundleLibRuntimeToDirDebug_dex/expo/modules/aikit/ExpoAiKitModule$definition$lambda$11$$inlined$AsyncFunction$6.dex +0 -0
- package/android/build/.transforms/e7552020676c2f8a620fec964bf11729/transformed/bundleLibRuntimeToDirDebug/bundleLibRuntimeToDirDebug_dex/expo/modules/aikit/ExpoAiKitModule$definition$lambda$11$$inlined$AsyncFunction$7.dex +0 -0
- package/android/build/.transforms/e7552020676c2f8a620fec964bf11729/transformed/bundleLibRuntimeToDirDebug/bundleLibRuntimeToDirDebug_dex/expo/modules/aikit/ExpoAiKitModule$definition$lambda$11$$inlined$Coroutine$1.dex +0 -0
- package/android/build/.transforms/e7552020676c2f8a620fec964bf11729/transformed/bundleLibRuntimeToDirDebug/bundleLibRuntimeToDirDebug_dex/expo/modules/aikit/ExpoAiKitModule$definition$lambda$11$$inlined$Coroutine$2.dex +0 -0
- package/android/build/.transforms/e7552020676c2f8a620fec964bf11729/transformed/bundleLibRuntimeToDirDebug/bundleLibRuntimeToDirDebug_dex/expo/modules/aikit/ExpoAiKitModule$definition$lambda$11$$inlined$Coroutine$3.dex +0 -0
- package/android/build/.transforms/e7552020676c2f8a620fec964bf11729/transformed/bundleLibRuntimeToDirDebug/bundleLibRuntimeToDirDebug_dex/expo/modules/aikit/ExpoAiKitModule$definition$lambda$11$$inlined$FunctionWithoutArgs$1.dex +0 -0
- package/android/build/.transforms/e7552020676c2f8a620fec964bf11729/transformed/bundleLibRuntimeToDirDebug/bundleLibRuntimeToDirDebug_dex/expo/modules/aikit/ExpoAiKitModule.dex +0 -0
- package/android/build/.transforms/e7552020676c2f8a620fec964bf11729/transformed/bundleLibRuntimeToDirDebug/bundleLibRuntimeToDirDebug_dex/expo/modules/aikit/PromptApiClient$generateText$2.dex +0 -0
- package/android/build/.transforms/e7552020676c2f8a620fec964bf11729/transformed/bundleLibRuntimeToDirDebug/bundleLibRuntimeToDirDebug_dex/expo/modules/aikit/PromptApiClient$generateTextStream$2$1.dex +0 -0
- package/android/build/.transforms/e7552020676c2f8a620fec964bf11729/transformed/bundleLibRuntimeToDirDebug/bundleLibRuntimeToDirDebug_dex/expo/modules/aikit/PromptApiClient$generateTextStream$2.dex +0 -0
- package/android/build/.transforms/e7552020676c2f8a620fec964bf11729/transformed/bundleLibRuntimeToDirDebug/bundleLibRuntimeToDirDebug_dex/expo/modules/aikit/PromptApiClient$isAvailable$1.dex +0 -0
- package/android/build/.transforms/e7552020676c2f8a620fec964bf11729/transformed/bundleLibRuntimeToDirDebug/bundleLibRuntimeToDirDebug_dex/expo/modules/aikit/PromptApiClient$isAvailableBlocking$1.dex +0 -0
- package/android/build/.transforms/e7552020676c2f8a620fec964bf11729/transformed/bundleLibRuntimeToDirDebug/bundleLibRuntimeToDirDebug_dex/expo/modules/aikit/PromptApiClient.dex +0 -0
- package/android/build/intermediates/compile_library_classes_jar/debug/bundleLibCompileToJarDebug/classes.jar +0 -0
- package/android/build/intermediates/runtime_library_classes_dir/debug/bundleLibRuntimeToDirDebug/expo/modules/aikit/ExpoAiKitModule$definition$1$2$conversationPrompt$2.class +0 -0
- package/android/build/intermediates/runtime_library_classes_dir/debug/bundleLibRuntimeToDirDebug/expo/modules/aikit/ExpoAiKitModule$definition$1$3$conversationPrompt$2.class +0 -0
- package/android/build/intermediates/runtime_library_classes_dir/debug/bundleLibRuntimeToDirDebug/expo/modules/aikit/ExpoAiKitModule$definition$1$3$job$1$1.class +0 -0
- package/android/build/intermediates/runtime_library_classes_dir/debug/bundleLibRuntimeToDirDebug/expo/modules/aikit/ExpoAiKitModule$definition$1$3$job$1.class +0 -0
- package/android/build/intermediates/runtime_library_classes_dir/debug/bundleLibRuntimeToDirDebug/expo/modules/aikit/ExpoAiKitModule$definition$lambda$11$$inlined$AsyncFunction$1.class +0 -0
- 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
- 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
- package/android/build/intermediates/runtime_library_classes_dir/debug/bundleLibRuntimeToDirDebug/expo/modules/aikit/ExpoAiKitModule$definition$lambda$11$$inlined$AsyncFunction$4.class +0 -0
- package/android/build/intermediates/runtime_library_classes_dir/debug/bundleLibRuntimeToDirDebug/expo/modules/aikit/ExpoAiKitModule$definition$lambda$11$$inlined$AsyncFunction$5.class +0 -0
- package/android/build/intermediates/runtime_library_classes_dir/debug/bundleLibRuntimeToDirDebug/expo/modules/aikit/ExpoAiKitModule$definition$lambda$11$$inlined$AsyncFunction$6.class +0 -0
- package/android/build/intermediates/runtime_library_classes_dir/debug/bundleLibRuntimeToDirDebug/expo/modules/aikit/ExpoAiKitModule$definition$lambda$11$$inlined$AsyncFunction$7.class +0 -0
- package/android/build/intermediates/runtime_library_classes_dir/debug/bundleLibRuntimeToDirDebug/expo/modules/aikit/ExpoAiKitModule$definition$lambda$11$$inlined$Coroutine$1.class +0 -0
- package/android/build/intermediates/runtime_library_classes_dir/debug/bundleLibRuntimeToDirDebug/expo/modules/aikit/ExpoAiKitModule$definition$lambda$11$$inlined$Coroutine$2.class +0 -0
- package/android/build/intermediates/runtime_library_classes_dir/debug/bundleLibRuntimeToDirDebug/expo/modules/aikit/ExpoAiKitModule$definition$lambda$11$$inlined$Coroutine$3.class +0 -0
- package/android/build/intermediates/runtime_library_classes_dir/debug/bundleLibRuntimeToDirDebug/expo/modules/aikit/ExpoAiKitModule$definition$lambda$11$$inlined$FunctionWithoutArgs$1.class +0 -0
- package/android/build/intermediates/runtime_library_classes_dir/debug/bundleLibRuntimeToDirDebug/expo/modules/aikit/ExpoAiKitModule.class +0 -0
- package/android/build/intermediates/runtime_library_classes_dir/debug/bundleLibRuntimeToDirDebug/expo/modules/aikit/PromptApiClient$generateText$2.class +0 -0
- package/android/build/intermediates/runtime_library_classes_dir/debug/bundleLibRuntimeToDirDebug/expo/modules/aikit/PromptApiClient$generateTextStream$2$1.class +0 -0
- package/android/build/intermediates/runtime_library_classes_dir/debug/bundleLibRuntimeToDirDebug/expo/modules/aikit/PromptApiClient$generateTextStream$2.class +0 -0
- package/android/build/intermediates/runtime_library_classes_dir/debug/bundleLibRuntimeToDirDebug/expo/modules/aikit/PromptApiClient$isAvailable$1.class +0 -0
- package/android/build/intermediates/runtime_library_classes_dir/debug/bundleLibRuntimeToDirDebug/expo/modules/aikit/PromptApiClient$isAvailableBlocking$1.class +0 -0
- package/android/build/intermediates/runtime_library_classes_dir/debug/bundleLibRuntimeToDirDebug/expo/modules/aikit/PromptApiClient.class +0 -0
- package/android/build/intermediates/runtime_library_classes_jar/debug/bundleLibRuntimeToJarDebug/classes.jar +0 -0
- package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/inputs/source-to-output.tab +0 -0
- package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/inputs/source-to-output.tab.values.at +0 -0
- package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/class-attributes.tab +0 -0
- package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/class-attributes.tab.values.at +0 -0
- package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/class-fq-name-to-source.tab +0 -0
- package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/class-fq-name-to-source.tab.values.at +0 -0
- package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/internal-name-to-source.tab +0 -0
- package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/internal-name-to-source.tab.keystream +0 -0
- package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/internal-name-to-source.tab.keystream.len +0 -0
- package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/internal-name-to-source.tab.len +0 -0
- package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/internal-name-to-source.tab.values.at +0 -0
- package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/internal-name-to-source.tab_i +0 -0
- package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/proto.tab +0 -0
- package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/proto.tab.values.at +0 -0
- package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/source-to-classes.tab +0 -0
- package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/source-to-classes.tab.values.at +0 -0
- package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/subtypes.tab +0 -0
- package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/subtypes.tab.values.at +0 -0
- package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/supertypes.tab +0 -0
- package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/supertypes.tab.values.at +0 -0
- package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/lookups/counters.tab +1 -1
- package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/lookups/file-to-id.tab +0 -0
- package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/lookups/file-to-id.tab.values.at +0 -0
- package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/lookups/id-to-file.tab +0 -0
- package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/lookups/id-to-file.tab.keystream +0 -0
- package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/lookups/id-to-file.tab.keystream.len +0 -0
- package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/lookups/id-to-file.tab.len +0 -0
- package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/lookups/id-to-file.tab.values.at +0 -0
- package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/lookups/id-to-file.tab_i +0 -0
- package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/lookups/lookups.tab +0 -0
- package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/lookups/lookups.tab.keystream +0 -0
- package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/lookups/lookups.tab.keystream.len +0 -0
- package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/lookups/lookups.tab.len +0 -0
- package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/lookups/lookups.tab.values.at +0 -0
- package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/lookups/lookups.tab_i +0 -0
- package/android/build/kotlin/compileDebugKotlin/cacheable/last-build.bin +0 -0
- package/android/build/kotlin/compileDebugKotlin/classpath-snapshot/shrunk-classpath-snapshot.bin +0 -0
- package/android/build/kotlin/compileDebugKotlin/local-state/build-history.bin +0 -0
- package/android/build/tmp/kotlin-classes/debug/expo/modules/aikit/ExpoAiKitModule$definition$1$2$conversationPrompt$2.class +0 -0
- package/android/build/tmp/kotlin-classes/debug/expo/modules/aikit/ExpoAiKitModule$definition$1$3$conversationPrompt$2.class +0 -0
- package/android/build/tmp/kotlin-classes/debug/expo/modules/aikit/ExpoAiKitModule$definition$1$3$job$1$1.class +0 -0
- package/android/build/tmp/kotlin-classes/debug/expo/modules/aikit/ExpoAiKitModule$definition$1$3$job$1.class +0 -0
- package/android/build/tmp/kotlin-classes/debug/expo/modules/aikit/ExpoAiKitModule$definition$lambda$11$$inlined$AsyncFunction$1.class +0 -0
- package/android/build/tmp/kotlin-classes/debug/expo/modules/aikit/ExpoAiKitModule$definition$lambda$11$$inlined$AsyncFunction$2.class +0 -0
- package/android/build/tmp/kotlin-classes/debug/expo/modules/aikit/ExpoAiKitModule$definition$lambda$11$$inlined$AsyncFunction$3.class +0 -0
- package/android/build/tmp/kotlin-classes/debug/expo/modules/aikit/ExpoAiKitModule$definition$lambda$11$$inlined$AsyncFunction$4.class +0 -0
- package/android/build/tmp/kotlin-classes/debug/expo/modules/aikit/ExpoAiKitModule$definition$lambda$11$$inlined$AsyncFunction$5.class +0 -0
- package/android/build/tmp/kotlin-classes/debug/expo/modules/aikit/ExpoAiKitModule$definition$lambda$11$$inlined$AsyncFunction$6.class +0 -0
- package/android/build/tmp/kotlin-classes/debug/expo/modules/aikit/ExpoAiKitModule$definition$lambda$11$$inlined$AsyncFunction$7.class +0 -0
- package/android/build/tmp/kotlin-classes/debug/expo/modules/aikit/ExpoAiKitModule$definition$lambda$11$$inlined$Coroutine$1.class +0 -0
- package/android/build/tmp/kotlin-classes/debug/expo/modules/aikit/ExpoAiKitModule$definition$lambda$11$$inlined$Coroutine$2.class +0 -0
- package/android/build/tmp/kotlin-classes/debug/expo/modules/aikit/ExpoAiKitModule$definition$lambda$11$$inlined$Coroutine$3.class +0 -0
- package/android/build/tmp/kotlin-classes/debug/expo/modules/aikit/ExpoAiKitModule$definition$lambda$11$$inlined$FunctionWithoutArgs$1.class +0 -0
- package/android/build/tmp/kotlin-classes/debug/expo/modules/aikit/ExpoAiKitModule.class +0 -0
- package/android/build/tmp/kotlin-classes/debug/expo/modules/aikit/PromptApiClient$generateText$2.class +0 -0
- package/android/build/tmp/kotlin-classes/debug/expo/modules/aikit/PromptApiClient$generateTextStream$2$1.class +0 -0
- package/android/build/tmp/kotlin-classes/debug/expo/modules/aikit/PromptApiClient$generateTextStream$2.class +0 -0
- package/android/build/tmp/kotlin-classes/debug/expo/modules/aikit/PromptApiClient$isAvailable$1.class +0 -0
- package/android/build/tmp/kotlin-classes/debug/expo/modules/aikit/PromptApiClient$isAvailableBlocking$1.class +0 -0
- package/android/build/tmp/kotlin-classes/debug/expo/modules/aikit/PromptApiClient.class +0 -0
- package/android/src/main/java/expo/modules/aikit/ExpoAiKitModule.kt +20 -12
- package/build/index.d.ts +1 -0
- package/build/index.d.ts.map +1 -1
- package/build/index.js +1 -0
- package/build/index.js.map +1 -1
- package/build/memory.d.ts +218 -0
- package/build/memory.d.ts.map +1 -0
- package/build/memory.js +310 -0
- package/build/memory.js.map +1 -0
- package/build/types.d.ts +28 -0
- package/build/types.d.ts.map +1 -1
- package/build/types.js.map +1 -1
- package/ios/ExpoAiKitModule.swift +28 -20
- package/package.json +1 -1
- package/src/index.ts +1 -0
- package/src/memory.ts +342 -0
- package/src/types.ts +34 -0
- package/android/build/.transforms/e7552020676c2f8a620fec964bf11729/transformed/bundleLibRuntimeToDirDebug/bundleLibRuntimeToDirDebug_dex/expo/modules/aikit/ExpoAiKitModule$definition$lambda$3$$inlined$AsyncFunctionWithoutArgs$1.dex +0 -0
- package/android/build/.transforms/e7552020676c2f8a620fec964bf11729/transformed/bundleLibRuntimeToDirDebug/bundleLibRuntimeToDirDebug_dex/expo/modules/aikit/ExpoAiKitModule$definition$lambda$3$$inlined$Coroutine$1.dex +0 -0
- package/android/build/.transforms/e7552020676c2f8a620fec964bf11729/transformed/bundleLibRuntimeToDirDebug/bundleLibRuntimeToDirDebug_dex/expo/modules/aikit/ExpoAiKitModule$definition$lambda$3$$inlined$Coroutine$2.dex +0 -0
- package/android/build/intermediates/runtime_library_classes_dir/debug/bundleLibRuntimeToDirDebug/expo/modules/aikit/ExpoAiKitModule$definition$lambda$3$$inlined$AsyncFunctionWithoutArgs$1.class +0 -0
- package/android/build/intermediates/runtime_library_classes_dir/debug/bundleLibRuntimeToDirDebug/expo/modules/aikit/ExpoAiKitModule$definition$lambda$3$$inlined$Coroutine$2.class +0 -0
- package/android/build/tmp/kotlin-classes/debug/expo/modules/aikit/ExpoAiKitModule$definition$lambda$3$$inlined$AsyncFunctionWithoutArgs$1.class +0 -0
- 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,
|
|
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
|
-
|
|
|
771
|
+
| ✅ Chat memory management | Done | - |
|
|
631
772
|
| Web/generic fallback | Idea | Medium |
|
|
632
773
|
| Configurable hyperparameters (temperature, etc.) | Idea | Low |
|
|
633
774
|
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/inputs/source-to-output.tab
CHANGED
|
Binary file
|
|
Binary file
|
package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/class-attributes.tab
CHANGED
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/proto.tab.values.at
CHANGED
|
Binary file
|
|
Binary file
|
|
Binary file
|
package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/subtypes.tab
CHANGED
|
Binary file
|
|
Binary file
|
package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/supertypes.tab
CHANGED
|
Binary file
|
|
Binary file
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
|
|
1
|
+
3
|
|
2
2
|
0
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/lookups/id-to-file.tab.len
CHANGED
|
Binary file
|
|
Binary file
|
package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/lookups/id-to-file.tab_i
CHANGED
|
Binary file
|
|
Binary file
|
package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/lookups/lookups.tab.keystream
CHANGED
|
Binary file
|
|
Binary file
|
package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/lookups/lookups.tab.len
CHANGED
|
Binary file
|
package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/lookups/lookups.tab.values.at
CHANGED
|
Binary file
|
|
Binary file
|
|
Binary file
|
package/android/build/kotlin/compileDebugKotlin/classpath-snapshot/shrunk-classpath-snapshot.bin
CHANGED
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
@@ -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
|
-
//
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
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(
|
|
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
|
-
//
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
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(
|
|
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.).
|
package/build/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAEA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IAAE,OAAO,EAAE,OAAO,CAAC,WAAW,CAAC,CAAC;IAAC,IAAI,EAAE,MAAM,IAAI,CAAA;CAAE,CAkBrD;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,wBAAsB,cAAc,CAClC,QAAQ,EAAE,MAAM,EAChB,OAAO,EAAE,MAAM,EACf,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() {
|