capacitor-native-agent 0.3.5 → 0.3.6

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 (19) hide show
  1. package/Package.swift +3 -1
  2. package/android/build.gradle +1 -0
  3. package/android/src/main/java/com/t6x/plugins/nativeagent/LanceDBBridge.kt +27 -0
  4. package/android/src/main/java/com/t6x/plugins/nativeagent/MemoryProviderImpl.kt +177 -0
  5. package/android/src/main/java/com/t6x/plugins/nativeagent/NativeAgentPlugin.kt +6 -0
  6. package/android/src/main/java/uniffi/native_agent_ffi/native_agent_ffi.kt +230 -8
  7. package/android/src/main/jniLibs/arm64-v8a/libnative_agent_ffi.so +0 -0
  8. package/ios/Frameworks/NativeAgentFFI.xcframework/ios-arm64/Headers/{native_agent_ffiFFI → native_agent_ffi}/module.modulemap +1 -1
  9. package/ios/Frameworks/NativeAgentFFI.xcframework/ios-arm64/Headers/{native_agent_ffiFFI → native_agent_ffi}/native_agent_ffiFFI.h +93 -0
  10. package/ios/Frameworks/NativeAgentFFI.xcframework/ios-arm64/libnative_agent_ffi.a +0 -0
  11. package/ios/Frameworks/NativeAgentFFI.xcframework/ios-arm64-simulator/Headers/{native_agent_ffiFFI → native_agent_ffi}/module.modulemap +1 -1
  12. package/ios/Frameworks/NativeAgentFFI.xcframework/ios-arm64-simulator/Headers/{native_agent_ffiFFI → native_agent_ffi}/native_agent_ffiFFI.h +93 -0
  13. package/ios/Frameworks/NativeAgentFFI.xcframework/ios-arm64-simulator/libnative_agent_ffi.a +0 -0
  14. package/ios/Sources/NativeAgentPlugin/Generated/native_agent_ffi.swift +252 -7
  15. package/ios/Sources/NativeAgentPlugin/Generated/native_agent_ffiFFI.h +93 -0
  16. package/ios/Sources/NativeAgentPlugin/LanceDBBridge.swift +70 -0
  17. package/ios/Sources/NativeAgentPlugin/MemoryProviderImpl.swift +206 -0
  18. package/ios/Sources/NativeAgentPlugin/NativeAgentPlugin.swift +3 -0
  19. package/package.json +8 -2
package/Package.swift CHANGED
@@ -11,7 +11,8 @@ let package = Package(
11
11
  )
12
12
  ],
13
13
  dependencies: [
14
- .package(url: "https://github.com/ionic-team/capacitor-swift-pm.git", from: "8.0.0")
14
+ .package(url: "https://github.com/ionic-team/capacitor-swift-pm.git", from: "8.0.0"),
15
+ .package(path: "../capacitor-lancedb")
15
16
  ],
16
17
  targets: [
17
18
  .binaryTarget(
@@ -23,6 +24,7 @@ let package = Package(
23
24
  dependencies: [
24
25
  .product(name: "Capacitor", package: "capacitor-swift-pm"),
25
26
  .product(name: "Cordova", package: "capacitor-swift-pm"),
27
+ .product(name: "CapacitorLancedb", package: "capacitor-lancedb"),
26
28
  "NativeAgentFFI"
27
29
  ],
28
30
  path: "ios/Sources/NativeAgentPlugin",
@@ -22,6 +22,7 @@ kotlin {
22
22
 
23
23
  dependencies {
24
24
  implementation project(':capacitor-android')
25
+ compileOnly project(':capacitor-lancedb')
25
26
  implementation 'net.java.dev.jna:jna:5.14.0@aar'
26
27
  implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.8.1'
27
28
  }
@@ -0,0 +1,27 @@
1
+ package com.t6x.plugins.nativeagent
2
+
3
+ import android.content.Context
4
+ import java.io.File
5
+ import kotlinx.coroutines.runBlocking
6
+ import uniffi.lancedb_ffi.LanceDbHandle
7
+
8
+ object LanceDBBridge {
9
+ const val EMBEDDING_DIM = 1536
10
+
11
+ @Volatile
12
+ private var handle: LanceDbHandle? = null
13
+
14
+ fun getOrCreateHandle(context: Context): LanceDbHandle? {
15
+ handle?.let { return it }
16
+ synchronized(this) {
17
+ handle?.let { return it }
18
+ val dbPath = File(context.filesDir, "lancedb-memories").absolutePath
19
+ handle = runCatching {
20
+ runBlocking {
21
+ LanceDbHandle.open(dbPath, EMBEDDING_DIM)
22
+ }
23
+ }.getOrNull()
24
+ return handle
25
+ }
26
+ }
27
+ }
@@ -0,0 +1,177 @@
1
+ package com.t6x.plugins.nativeagent
2
+
3
+ import android.content.Context
4
+ import java.util.Locale
5
+ import java.util.UUID
6
+ import kotlinx.coroutines.runBlocking
7
+ import org.json.JSONArray
8
+ import org.json.JSONObject
9
+ import uniffi.lancedb_ffi.HybridSearchResult
10
+ import uniffi.lancedb_ffi.SearchResult
11
+ import uniffi.native_agent_ffi.MemoryProvider
12
+
13
+ class MemoryProviderImpl(private val context: Context) : MemoryProvider {
14
+ fun isAvailable(): Boolean = LanceDBBridge.getOrCreateHandle(context) != null
15
+
16
+ override fun store(key: String, text: String, metadataJson: String?): String {
17
+ val handle = LanceDBBridge.getOrCreateHandle(context) ?: return unavailableJson()
18
+ val resolvedKey = key.ifBlank {
19
+ "mem-${System.currentTimeMillis()}-${UUID.randomUUID().toString().take(8)}"
20
+ }
21
+ val embedding = localHashEmbed(text, LanceDBBridge.EMBEDDING_DIM)
22
+ return runCatching {
23
+ runBlocking {
24
+ handle.store(resolvedKey, DEFAULT_AGENT_ID, text, embedding, metadataJson)
25
+ }
26
+ JSONObject()
27
+ .put("success", true)
28
+ .put("key", resolvedKey)
29
+ .toString()
30
+ }.getOrElse { errorJson(it) }
31
+ }
32
+
33
+ override fun recall(query: String, limit: UInt): String {
34
+ val handle = LanceDBBridge.getOrCreateHandle(context) ?: return unavailableJson()
35
+ val embedding = localHashEmbed(query, LanceDBBridge.EMBEDDING_DIM)
36
+ return runCatching {
37
+ val results = runBlocking {
38
+ handle.hybridSearch(
39
+ embedding,
40
+ query,
41
+ limit,
42
+ "agent_id = '$DEFAULT_AGENT_ID'",
43
+ null,
44
+ null,
45
+ )
46
+ }
47
+ hybridResultsJson(results)
48
+ }.getOrElse { errorJson(it) }
49
+ }
50
+
51
+ override fun forget(key: String): String {
52
+ val handle = LanceDBBridge.getOrCreateHandle(context) ?: return unavailableJson()
53
+ if (key.isBlank()) {
54
+ return JSONObject().put("error", "Provide query or key.").toString()
55
+ }
56
+ return runCatching {
57
+ runBlocking {
58
+ handle.delete(key)
59
+ }
60
+ JSONObject()
61
+ .put("success", true)
62
+ .put("key", key)
63
+ .toString()
64
+ }.getOrElse { errorJson(it) }
65
+ }
66
+
67
+ override fun search(query: String, maxResults: UInt): String {
68
+ val handle = LanceDBBridge.getOrCreateHandle(context) ?: return unavailableJson()
69
+ val embedding = localHashEmbed(query, LanceDBBridge.EMBEDDING_DIM)
70
+ return runCatching {
71
+ val results = runBlocking {
72
+ handle.search(embedding, maxResults, "agent_id = '$DEFAULT_AGENT_ID'")
73
+ }
74
+ searchResultsJson(results)
75
+ }.getOrElse { errorJson(it) }
76
+ }
77
+
78
+ override fun list(prefix: String?, limit: UInt?): String {
79
+ val handle = LanceDBBridge.getOrCreateHandle(context) ?: return unavailableJson()
80
+ return runCatching {
81
+ val keys = runBlocking {
82
+ handle.list(prefix, limit)
83
+ }
84
+ JSONArray(keys).toString()
85
+ }.getOrElse { errorJson(it) }
86
+ }
87
+
88
+ private fun hybridResultsJson(results: List<HybridSearchResult>): String {
89
+ val array = JSONArray()
90
+ results.forEach { result ->
91
+ array.put(
92
+ JSONObject()
93
+ .put("key", result.key)
94
+ .put("text", result.text)
95
+ .put("vectorRank", result.vectorRank.toInt())
96
+ .put("textRank", result.textRank.toInt())
97
+ .put("rrfScore", result.rrfScore)
98
+ .apply {
99
+ result.metadata?.let { put("metadata", it) }
100
+ }
101
+ )
102
+ }
103
+ return array.toString()
104
+ }
105
+
106
+ private fun searchResultsJson(results: List<SearchResult>): String {
107
+ val array = JSONArray()
108
+ results.forEach { result ->
109
+ array.put(
110
+ JSONObject()
111
+ .put("key", result.key)
112
+ .put("text", result.text)
113
+ .put("score", result.score)
114
+ .apply {
115
+ result.metadata?.let { put("metadata", it) }
116
+ }
117
+ )
118
+ }
119
+ return array.toString()
120
+ }
121
+
122
+ private fun unavailableJson(): String {
123
+ return JSONObject().put("error", "Memory provider not configured").toString()
124
+ }
125
+
126
+ private fun errorJson(error: Throwable): String {
127
+ return JSONObject()
128
+ .put("error", error.message ?: error::class.java.simpleName)
129
+ .toString()
130
+ }
131
+
132
+ private companion object {
133
+ private const val DEFAULT_AGENT_ID = "main"
134
+ private val WHITESPACE = Regex("\\s+")
135
+ private val UINT_MAX_DOUBLE = 0xffffffffu.toDouble()
136
+ private const val FNV_OFFSET = 0x811c9dc5u
137
+ private const val FNV_PRIME = 0x01000193u
138
+ private const val GOLDEN_RATIO = 2654435761u
139
+ private const val MIX = 0x45d9f3bu
140
+
141
+ private fun fnv1a(text: String): UInt {
142
+ var hash = FNV_OFFSET
143
+ text.forEach { char ->
144
+ hash = hash xor char.code.toUInt()
145
+ hash *= FNV_PRIME
146
+ }
147
+ return hash
148
+ }
149
+
150
+ private fun seededRandom(seed: UInt, dim: Int): Float {
151
+ var h = seed xor (dim.toUInt() * GOLDEN_RATIO)
152
+ h = (((h shr 16) xor h) * MIX)
153
+ h = (((h shr 16) xor h) * MIX)
154
+ h = (h shr 16) xor h
155
+ return (((h.toDouble() / UINT_MAX_DOUBLE) * 2.0) - 1.0).toFloat()
156
+ }
157
+
158
+ private fun localHashEmbed(text: String, dim: Int): List<Float> {
159
+ val tokens = text.lowercase(Locale.ROOT).split(WHITESPACE).filter { it.isNotBlank() }
160
+ val vector = DoubleArray(dim)
161
+ tokens.forEach { token ->
162
+ val hash = fnv1a(token)
163
+ for (index in 0 until dim) {
164
+ vector[index] += seededRandom(hash, index).toDouble()
165
+ }
166
+ }
167
+
168
+ var norm = 0.0
169
+ for (value in vector) {
170
+ norm += value * value
171
+ }
172
+ norm = kotlin.math.sqrt(norm).takeIf { it > 0.0 } ?: 1.0
173
+
174
+ return List(dim) { index -> (vector[index] / norm).toFloat() }
175
+ }
176
+ }
177
+ }
@@ -93,6 +93,12 @@ class NativeAgentPlugin : Plugin() {
93
93
  }
94
94
  })
95
95
  h.setNotifier(NativeNotifierImpl(context.applicationContext))
96
+ runCatching {
97
+ val memoryProvider = MemoryProviderImpl(context.applicationContext)
98
+ if (memoryProvider.isAvailable()) {
99
+ h.setMemoryProvider(memoryProvider)
100
+ }
101
+ }
96
102
  h.persistConfig()
97
103
  handle = h
98
104
  context
@@ -654,12 +654,55 @@ internal open class UniffiForeignFutureStructVoid(
654
654
  internal interface UniffiForeignFutureCompleteVoid : com.sun.jna.Callback {
655
655
  fun callback(`callbackData`: Long,`result`: UniffiForeignFutureStructVoid.UniffiByValue,)
656
656
  }
657
+ internal interface UniffiCallbackInterfaceMemoryProviderMethod0 : com.sun.jna.Callback {
658
+ fun callback(`uniffiHandle`: Long,`key`: RustBuffer.ByValue,`text`: RustBuffer.ByValue,`metadataJson`: RustBuffer.ByValue,`uniffiOutReturn`: RustBuffer,uniffiCallStatus: UniffiRustCallStatus,)
659
+ }
660
+ internal interface UniffiCallbackInterfaceMemoryProviderMethod1 : com.sun.jna.Callback {
661
+ fun callback(`uniffiHandle`: Long,`query`: RustBuffer.ByValue,`limit`: Int,`uniffiOutReturn`: RustBuffer,uniffiCallStatus: UniffiRustCallStatus,)
662
+ }
663
+ internal interface UniffiCallbackInterfaceMemoryProviderMethod2 : com.sun.jna.Callback {
664
+ fun callback(`uniffiHandle`: Long,`key`: RustBuffer.ByValue,`uniffiOutReturn`: RustBuffer,uniffiCallStatus: UniffiRustCallStatus,)
665
+ }
666
+ internal interface UniffiCallbackInterfaceMemoryProviderMethod3 : com.sun.jna.Callback {
667
+ fun callback(`uniffiHandle`: Long,`query`: RustBuffer.ByValue,`maxResults`: Int,`uniffiOutReturn`: RustBuffer,uniffiCallStatus: UniffiRustCallStatus,)
668
+ }
669
+ internal interface UniffiCallbackInterfaceMemoryProviderMethod4 : com.sun.jna.Callback {
670
+ fun callback(`uniffiHandle`: Long,`prefix`: RustBuffer.ByValue,`limit`: RustBuffer.ByValue,`uniffiOutReturn`: RustBuffer,uniffiCallStatus: UniffiRustCallStatus,)
671
+ }
657
672
  internal interface UniffiCallbackInterfaceNativeEventCallbackMethod0 : com.sun.jna.Callback {
658
673
  fun callback(`uniffiHandle`: Long,`eventType`: RustBuffer.ByValue,`payloadJson`: RustBuffer.ByValue,`uniffiOutReturn`: Pointer,uniffiCallStatus: UniffiRustCallStatus,)
659
674
  }
660
675
  internal interface UniffiCallbackInterfaceNativeNotifierMethod0 : com.sun.jna.Callback {
661
676
  fun callback(`uniffiHandle`: Long,`title`: RustBuffer.ByValue,`body`: RustBuffer.ByValue,`dataJson`: RustBuffer.ByValue,`uniffiOutReturn`: RustBuffer,uniffiCallStatus: UniffiRustCallStatus,)
662
677
  }
678
+ @Structure.FieldOrder("store", "recall", "forget", "search", "list", "uniffiFree")
679
+ internal open class UniffiVTableCallbackInterfaceMemoryProvider(
680
+ @JvmField internal var `store`: UniffiCallbackInterfaceMemoryProviderMethod0? = null,
681
+ @JvmField internal var `recall`: UniffiCallbackInterfaceMemoryProviderMethod1? = null,
682
+ @JvmField internal var `forget`: UniffiCallbackInterfaceMemoryProviderMethod2? = null,
683
+ @JvmField internal var `search`: UniffiCallbackInterfaceMemoryProviderMethod3? = null,
684
+ @JvmField internal var `list`: UniffiCallbackInterfaceMemoryProviderMethod4? = null,
685
+ @JvmField internal var `uniffiFree`: UniffiCallbackInterfaceFree? = null,
686
+ ) : Structure() {
687
+ class UniffiByValue(
688
+ `store`: UniffiCallbackInterfaceMemoryProviderMethod0? = null,
689
+ `recall`: UniffiCallbackInterfaceMemoryProviderMethod1? = null,
690
+ `forget`: UniffiCallbackInterfaceMemoryProviderMethod2? = null,
691
+ `search`: UniffiCallbackInterfaceMemoryProviderMethod3? = null,
692
+ `list`: UniffiCallbackInterfaceMemoryProviderMethod4? = null,
693
+ `uniffiFree`: UniffiCallbackInterfaceFree? = null,
694
+ ): UniffiVTableCallbackInterfaceMemoryProvider(`store`,`recall`,`forget`,`search`,`list`,`uniffiFree`,), Structure.ByValue
695
+
696
+ internal fun uniffiSetValue(other: UniffiVTableCallbackInterfaceMemoryProvider) {
697
+ `store` = other.`store`
698
+ `recall` = other.`recall`
699
+ `forget` = other.`forget`
700
+ `search` = other.`search`
701
+ `list` = other.`list`
702
+ `uniffiFree` = other.`uniffiFree`
703
+ }
704
+
705
+ }
663
706
  @Structure.FieldOrder("onEvent", "uniffiFree")
664
707
  internal open class UniffiVTableCallbackInterfaceNativeEventCallback(
665
708
  @JvmField internal var `onEvent`: UniffiCallbackInterfaceNativeEventCallbackMethod0? = null,
@@ -833,6 +876,14 @@ internal open class UniffiVTableCallbackInterfaceNativeNotifier(
833
876
 
834
877
 
835
878
 
879
+
880
+
881
+
882
+
883
+
884
+
885
+
886
+
836
887
 
837
888
 
838
889
 
@@ -852,6 +903,7 @@ internal interface UniffiLib : Library {
852
903
  .also { lib: UniffiLib ->
853
904
  uniffiCheckContractApiVersion(lib)
854
905
  uniffiCheckApiChecksums(lib)
906
+ uniffiCallbackInterfaceMemoryProvider.register(lib)
855
907
  uniffiCallbackInterfaceNativeEventCallback.register(lib)
856
908
  uniffiCallbackInterfaceNativeNotifier.register(lib)
857
909
  }
@@ -935,6 +987,8 @@ internal interface UniffiLib : Library {
935
987
  ): Unit
936
988
  fun uniffi_native_agent_ffi_fn_method_nativeagenthandle_set_heartbeat_config(`ptr`: Pointer,`configJson`: RustBuffer.ByValue,uniffi_out_err: UniffiRustCallStatus,
937
989
  ): Unit
990
+ fun uniffi_native_agent_ffi_fn_method_nativeagenthandle_set_memory_provider(`ptr`: Pointer,`provider`: Long,uniffi_out_err: UniffiRustCallStatus,
991
+ ): Unit
938
992
  fun uniffi_native_agent_ffi_fn_method_nativeagenthandle_set_notifier(`ptr`: Pointer,`notifier`: Long,uniffi_out_err: UniffiRustCallStatus,
939
993
  ): Unit
940
994
  fun uniffi_native_agent_ffi_fn_method_nativeagenthandle_set_scheduler_config(`ptr`: Pointer,`configJson`: RustBuffer.ByValue,uniffi_out_err: UniffiRustCallStatus,
@@ -949,6 +1003,8 @@ internal interface UniffiLib : Library {
949
1003
  ): Unit
950
1004
  fun uniffi_native_agent_ffi_fn_method_nativeagenthandle_update_skill(`ptr`: Pointer,`id`: RustBuffer.ByValue,`patchJson`: RustBuffer.ByValue,uniffi_out_err: UniffiRustCallStatus,
951
1005
  ): Unit
1006
+ fun uniffi_native_agent_ffi_fn_init_callback_vtable_memoryprovider(`vtable`: UniffiVTableCallbackInterfaceMemoryProvider,
1007
+ ): Unit
952
1008
  fun uniffi_native_agent_ffi_fn_init_callback_vtable_nativeeventcallback(`vtable`: UniffiVTableCallbackInterfaceNativeEventCallback,
953
1009
  ): Unit
954
1010
  fun uniffi_native_agent_ffi_fn_init_callback_vtable_nativenotifier(`vtable`: UniffiVTableCallbackInterfaceNativeNotifier,
@@ -1139,6 +1195,8 @@ internal interface UniffiLib : Library {
1139
1195
  ): Short
1140
1196
  fun uniffi_native_agent_ffi_checksum_method_nativeagenthandle_set_heartbeat_config(
1141
1197
  ): Short
1198
+ fun uniffi_native_agent_ffi_checksum_method_nativeagenthandle_set_memory_provider(
1199
+ ): Short
1142
1200
  fun uniffi_native_agent_ffi_checksum_method_nativeagenthandle_set_notifier(
1143
1201
  ): Short
1144
1202
  fun uniffi_native_agent_ffi_checksum_method_nativeagenthandle_set_scheduler_config(
@@ -1155,6 +1213,16 @@ internal interface UniffiLib : Library {
1155
1213
  ): Short
1156
1214
  fun uniffi_native_agent_ffi_checksum_constructor_nativeagenthandle_new(
1157
1215
  ): Short
1216
+ fun uniffi_native_agent_ffi_checksum_method_memoryprovider_store(
1217
+ ): Short
1218
+ fun uniffi_native_agent_ffi_checksum_method_memoryprovider_recall(
1219
+ ): Short
1220
+ fun uniffi_native_agent_ffi_checksum_method_memoryprovider_forget(
1221
+ ): Short
1222
+ fun uniffi_native_agent_ffi_checksum_method_memoryprovider_search(
1223
+ ): Short
1224
+ fun uniffi_native_agent_ffi_checksum_method_memoryprovider_list(
1225
+ ): Short
1158
1226
  fun uniffi_native_agent_ffi_checksum_method_nativeeventcallback_on_event(
1159
1227
  ): Short
1160
1228
  fun uniffi_native_agent_ffi_checksum_method_nativenotifier_send_notification(
@@ -1281,6 +1349,9 @@ private fun uniffiCheckApiChecksums(lib: UniffiLib) {
1281
1349
  if (lib.uniffi_native_agent_ffi_checksum_method_nativeagenthandle_set_heartbeat_config() != 33968.toShort()) {
1282
1350
  throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
1283
1351
  }
1352
+ if (lib.uniffi_native_agent_ffi_checksum_method_nativeagenthandle_set_memory_provider() != 23171.toShort()) {
1353
+ throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
1354
+ }
1284
1355
  if (lib.uniffi_native_agent_ffi_checksum_method_nativeagenthandle_set_notifier() != 58795.toShort()) {
1285
1356
  throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
1286
1357
  }
@@ -1305,6 +1376,21 @@ private fun uniffiCheckApiChecksums(lib: UniffiLib) {
1305
1376
  if (lib.uniffi_native_agent_ffi_checksum_constructor_nativeagenthandle_new() != 18383.toShort()) {
1306
1377
  throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
1307
1378
  }
1379
+ if (lib.uniffi_native_agent_ffi_checksum_method_memoryprovider_store() != 49136.toShort()) {
1380
+ throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
1381
+ }
1382
+ if (lib.uniffi_native_agent_ffi_checksum_method_memoryprovider_recall() != 3170.toShort()) {
1383
+ throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
1384
+ }
1385
+ if (lib.uniffi_native_agent_ffi_checksum_method_memoryprovider_forget() != 43231.toShort()) {
1386
+ throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
1387
+ }
1388
+ if (lib.uniffi_native_agent_ffi_checksum_method_memoryprovider_search() != 19100.toShort()) {
1389
+ throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
1390
+ }
1391
+ if (lib.uniffi_native_agent_ffi_checksum_method_memoryprovider_list() != 46802.toShort()) {
1392
+ throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
1393
+ }
1308
1394
  if (lib.uniffi_native_agent_ffi_checksum_method_nativeeventcallback_on_event() != 29742.toShort()) {
1309
1395
  throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
1310
1396
  }
@@ -1815,6 +1901,8 @@ public interface NativeAgentHandleInterface {
1815
1901
  */
1816
1902
  fun `setHeartbeatConfig`(`configJson`: kotlin.String)
1817
1903
 
1904
+ fun `setMemoryProvider`(`provider`: MemoryProvider)
1905
+
1818
1906
  fun `setNotifier`(`notifier`: NativeNotifier)
1819
1907
 
1820
1908
  /**
@@ -2455,6 +2543,18 @@ open class NativeAgentHandle: Disposable, AutoCloseable, NativeAgentHandleInterf
2455
2543
 
2456
2544
 
2457
2545
 
2546
+ @Throws(NativeAgentException::class)override fun `setMemoryProvider`(`provider`: MemoryProvider)
2547
+ =
2548
+ callWithPointer {
2549
+ uniffiRustCallWithError(NativeAgentException) { _status ->
2550
+ UniffiLib.INSTANCE.uniffi_native_agent_ffi_fn_method_nativeagenthandle_set_memory_provider(
2551
+ it, FfiConverterTypeMemoryProvider.lower(`provider`),_status)
2552
+ }
2553
+ }
2554
+
2555
+
2556
+
2557
+
2458
2558
  @Throws(NativeAgentException::class)override fun `setNotifier`(`notifier`: NativeNotifier)
2459
2559
  =
2460
2560
  callWithPointer {
@@ -3043,16 +3143,20 @@ public object FfiConverterTypeNativeAgentError : FfiConverterRustBuffer<NativeAg
3043
3143
 
3044
3144
 
3045
3145
  /**
3046
- * Callback interface for events from the native agent.
3146
+ * Callback interface for memory operations (LanceDB or any vector store).
3147
+ * Implemented by Kotlin/Swift, which bridges to the actual memory backend.
3047
3148
  */
3048
- public interface NativeEventCallback {
3149
+ public interface MemoryProvider {
3049
3150
 
3050
- /**
3051
- * Called when the agent emits an event.
3052
- * `event_type`: text_delta, tool_use, tool_result, agent.completed, agent.error, etc.
3053
- * `payload_json`: JSON-encoded event data.
3054
- */
3055
- fun `onEvent`(`eventType`: kotlin.String, `payloadJson`: kotlin.String)
3151
+ fun `store`(`key`: kotlin.String, `text`: kotlin.String, `metadataJson`: kotlin.String?): kotlin.String
3152
+
3153
+ fun `recall`(`query`: kotlin.String, `limit`: kotlin.UInt): kotlin.String
3154
+
3155
+ fun `forget`(`key`: kotlin.String): kotlin.String
3156
+
3157
+ fun `search`(`query`: kotlin.String, `maxResults`: kotlin.UInt): kotlin.String
3158
+
3159
+ fun `list`(`prefix`: kotlin.String?, `limit`: kotlin.UInt?): kotlin.String
3056
3160
 
3057
3161
  companion object
3058
3162
  }
@@ -3090,6 +3194,124 @@ public abstract class FfiConverterCallbackInterface<CallbackInterface: Any>: Ffi
3090
3194
  }
3091
3195
  }
3092
3196
 
3197
+ // Put the implementation in an object so we don't pollute the top-level namespace
3198
+ internal object uniffiCallbackInterfaceMemoryProvider {
3199
+ internal object `store`: UniffiCallbackInterfaceMemoryProviderMethod0 {
3200
+ override fun callback(`uniffiHandle`: Long,`key`: RustBuffer.ByValue,`text`: RustBuffer.ByValue,`metadataJson`: RustBuffer.ByValue,`uniffiOutReturn`: RustBuffer,uniffiCallStatus: UniffiRustCallStatus,) {
3201
+ val uniffiObj = FfiConverterTypeMemoryProvider.handleMap.get(uniffiHandle)
3202
+ val makeCall = { ->
3203
+ uniffiObj.`store`(
3204
+ FfiConverterString.lift(`key`),
3205
+ FfiConverterString.lift(`text`),
3206
+ FfiConverterOptionalString.lift(`metadataJson`),
3207
+ )
3208
+ }
3209
+ val writeReturn = { value: kotlin.String -> uniffiOutReturn.setValue(FfiConverterString.lower(value)) }
3210
+ uniffiTraitInterfaceCall(uniffiCallStatus, makeCall, writeReturn)
3211
+ }
3212
+ }
3213
+ internal object `recall`: UniffiCallbackInterfaceMemoryProviderMethod1 {
3214
+ override fun callback(`uniffiHandle`: Long,`query`: RustBuffer.ByValue,`limit`: Int,`uniffiOutReturn`: RustBuffer,uniffiCallStatus: UniffiRustCallStatus,) {
3215
+ val uniffiObj = FfiConverterTypeMemoryProvider.handleMap.get(uniffiHandle)
3216
+ val makeCall = { ->
3217
+ uniffiObj.`recall`(
3218
+ FfiConverterString.lift(`query`),
3219
+ FfiConverterUInt.lift(`limit`),
3220
+ )
3221
+ }
3222
+ val writeReturn = { value: kotlin.String -> uniffiOutReturn.setValue(FfiConverterString.lower(value)) }
3223
+ uniffiTraitInterfaceCall(uniffiCallStatus, makeCall, writeReturn)
3224
+ }
3225
+ }
3226
+ internal object `forget`: UniffiCallbackInterfaceMemoryProviderMethod2 {
3227
+ override fun callback(`uniffiHandle`: Long,`key`: RustBuffer.ByValue,`uniffiOutReturn`: RustBuffer,uniffiCallStatus: UniffiRustCallStatus,) {
3228
+ val uniffiObj = FfiConverterTypeMemoryProvider.handleMap.get(uniffiHandle)
3229
+ val makeCall = { ->
3230
+ uniffiObj.`forget`(
3231
+ FfiConverterString.lift(`key`),
3232
+ )
3233
+ }
3234
+ val writeReturn = { value: kotlin.String -> uniffiOutReturn.setValue(FfiConverterString.lower(value)) }
3235
+ uniffiTraitInterfaceCall(uniffiCallStatus, makeCall, writeReturn)
3236
+ }
3237
+ }
3238
+ internal object `search`: UniffiCallbackInterfaceMemoryProviderMethod3 {
3239
+ override fun callback(`uniffiHandle`: Long,`query`: RustBuffer.ByValue,`maxResults`: Int,`uniffiOutReturn`: RustBuffer,uniffiCallStatus: UniffiRustCallStatus,) {
3240
+ val uniffiObj = FfiConverterTypeMemoryProvider.handleMap.get(uniffiHandle)
3241
+ val makeCall = { ->
3242
+ uniffiObj.`search`(
3243
+ FfiConverterString.lift(`query`),
3244
+ FfiConverterUInt.lift(`maxResults`),
3245
+ )
3246
+ }
3247
+ val writeReturn = { value: kotlin.String -> uniffiOutReturn.setValue(FfiConverterString.lower(value)) }
3248
+ uniffiTraitInterfaceCall(uniffiCallStatus, makeCall, writeReturn)
3249
+ }
3250
+ }
3251
+ internal object `list`: UniffiCallbackInterfaceMemoryProviderMethod4 {
3252
+ override fun callback(`uniffiHandle`: Long,`prefix`: RustBuffer.ByValue,`limit`: RustBuffer.ByValue,`uniffiOutReturn`: RustBuffer,uniffiCallStatus: UniffiRustCallStatus,) {
3253
+ val uniffiObj = FfiConverterTypeMemoryProvider.handleMap.get(uniffiHandle)
3254
+ val makeCall = { ->
3255
+ uniffiObj.`list`(
3256
+ FfiConverterOptionalString.lift(`prefix`),
3257
+ FfiConverterOptionalUInt.lift(`limit`),
3258
+ )
3259
+ }
3260
+ val writeReturn = { value: kotlin.String -> uniffiOutReturn.setValue(FfiConverterString.lower(value)) }
3261
+ uniffiTraitInterfaceCall(uniffiCallStatus, makeCall, writeReturn)
3262
+ }
3263
+ }
3264
+
3265
+ internal object uniffiFree: UniffiCallbackInterfaceFree {
3266
+ override fun callback(handle: Long) {
3267
+ FfiConverterTypeMemoryProvider.handleMap.remove(handle)
3268
+ }
3269
+ }
3270
+
3271
+ internal var vtable = UniffiVTableCallbackInterfaceMemoryProvider.UniffiByValue(
3272
+ `store`,
3273
+ `recall`,
3274
+ `forget`,
3275
+ `search`,
3276
+ `list`,
3277
+ uniffiFree,
3278
+ )
3279
+
3280
+ // Registers the foreign callback with the Rust side.
3281
+ // This method is generated for each callback interface.
3282
+ internal fun register(lib: UniffiLib) {
3283
+ lib.uniffi_native_agent_ffi_fn_init_callback_vtable_memoryprovider(vtable)
3284
+ }
3285
+ }
3286
+
3287
+ /**
3288
+ * The ffiConverter which transforms the Callbacks in to handles to pass to Rust.
3289
+ *
3290
+ * @suppress
3291
+ */
3292
+ public object FfiConverterTypeMemoryProvider: FfiConverterCallbackInterface<MemoryProvider>()
3293
+
3294
+
3295
+
3296
+
3297
+
3298
+ /**
3299
+ * Callback interface for events from the native agent.
3300
+ */
3301
+ public interface NativeEventCallback {
3302
+
3303
+ /**
3304
+ * Called when the agent emits an event.
3305
+ * `event_type`: text_delta, tool_use, tool_result, agent.completed, agent.error, etc.
3306
+ * `payload_json`: JSON-encoded event data.
3307
+ */
3308
+ fun `onEvent`(`eventType`: kotlin.String, `payloadJson`: kotlin.String)
3309
+
3310
+ companion object
3311
+ }
3312
+
3313
+
3314
+
3093
3315
  // Put the implementation in an object so we don't pollute the top-level namespace
3094
3316
  internal object uniffiCallbackInterfaceNativeEventCallback {
3095
3317
  internal object `onEvent`: UniffiCallbackInterfaceNativeEventCallbackMethod0 {
@@ -1,4 +1,4 @@
1
1
  module native_agent_ffiFFI {
2
2
  header "native_agent_ffiFFI.h"
3
3
  export *
4
- }
4
+ }