capacitor-native-agent 0.3.5 → 0.3.7

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 (27) 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 +16 -0
  6. package/android/src/main/java/uniffi/native_agent_ffi/native_agent_ffi.kt +260 -8
  7. package/android/src/main/jniLibs/arm64-v8a/libnative_agent_ffi.so +0 -0
  8. package/dist/esm/definitions.d.ts +11 -0
  9. package/dist/esm/definitions.d.ts.map +1 -1
  10. package/dist/esm/plugin.d.ts.map +1 -1
  11. package/dist/esm/plugin.js +1 -0
  12. package/dist/esm/plugin.js.map +1 -1
  13. package/ios/Frameworks/NativeAgentFFI.xcframework/Info.plist +4 -4
  14. package/ios/Frameworks/NativeAgentFFI.xcframework/ios-arm64/Headers/{native_agent_ffiFFI → native_agent_ffi}/module.modulemap +1 -1
  15. package/ios/Frameworks/NativeAgentFFI.xcframework/ios-arm64/Headers/native_agent_ffi/native_agent_ffi.swift +2594 -0
  16. package/ios/Frameworks/NativeAgentFFI.xcframework/ios-arm64/Headers/{native_agent_ffiFFI → native_agent_ffi}/native_agent_ffiFFI.h +104 -0
  17. package/ios/Frameworks/NativeAgentFFI.xcframework/ios-arm64/libnative_agent_ffi.a +0 -0
  18. package/ios/Frameworks/NativeAgentFFI.xcframework/ios-arm64-simulator/Headers/{native_agent_ffiFFI → native_agent_ffi}/module.modulemap +1 -1
  19. package/ios/Frameworks/NativeAgentFFI.xcframework/ios-arm64-simulator/Headers/native_agent_ffi/native_agent_ffi.swift +2594 -0
  20. package/ios/Frameworks/NativeAgentFFI.xcframework/ios-arm64-simulator/Headers/{native_agent_ffiFFI → native_agent_ffi}/native_agent_ffiFFI.h +104 -0
  21. package/ios/Frameworks/NativeAgentFFI.xcframework/ios-arm64-simulator/libnative_agent_ffi.a +0 -0
  22. package/ios/Sources/NativeAgentPlugin/Generated/native_agent_ffi.swift +273 -7
  23. package/ios/Sources/NativeAgentPlugin/Generated/native_agent_ffiFFI.h +104 -0
  24. package/ios/Sources/NativeAgentPlugin/LanceDBBridge.swift +70 -0
  25. package/ios/Sources/NativeAgentPlugin/MemoryProviderImpl.swift +206 -0
  26. package/ios/Sources/NativeAgentPlugin/NativeAgentPlugin.swift +31 -0
  27. 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
@@ -221,6 +227,16 @@ class NativeAgentPlugin : Plugin() {
221
227
  call.resolve(ret)
222
228
  }
223
229
 
230
+ @PluginMethod
231
+ fun exchangeOAuthCode(call: PluginCall) = withHandle(call) { h ->
232
+ val tokenUrl = call.getString("tokenUrl") ?: return@withHandle call.reject("tokenUrl is required")
233
+ val bodyJson = call.getString("bodyJson") ?: return@withHandle call.reject("bodyJson is required")
234
+ val contentType = call.getString("contentType")
235
+ val resultJson = h.exchangeOauthCode(tokenUrl, bodyJson, contentType)
236
+ val ret = JSObject(resultJson)
237
+ call.resolve(ret)
238
+ }
239
+
224
240
  // ── Sessions ──────────────────────────────────────────────────────
225
241
 
226
242
  @PluginMethod
@@ -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,
@@ -831,6 +874,16 @@ internal open class UniffiVTableCallbackInterfaceNativeNotifier(
831
874
 
832
875
 
833
876
 
877
+
878
+
879
+
880
+
881
+
882
+
883
+
884
+
885
+
886
+
834
887
 
835
888
 
836
889
 
@@ -852,6 +905,7 @@ internal interface UniffiLib : Library {
852
905
  .also { lib: UniffiLib ->
853
906
  uniffiCheckContractApiVersion(lib)
854
907
  uniffiCheckApiChecksums(lib)
908
+ uniffiCallbackInterfaceMemoryProvider.register(lib)
855
909
  uniffiCallbackInterfaceNativeEventCallback.register(lib)
856
910
  uniffiCallbackInterfaceNativeNotifier.register(lib)
857
911
  }
@@ -881,6 +935,8 @@ internal interface UniffiLib : Library {
881
935
  ): Unit
882
936
  fun uniffi_native_agent_ffi_fn_method_nativeagenthandle_end_skill(`ptr`: Pointer,`skillId`: RustBuffer.ByValue,uniffi_out_err: UniffiRustCallStatus,
883
937
  ): Unit
938
+ fun uniffi_native_agent_ffi_fn_method_nativeagenthandle_exchange_oauth_code(`ptr`: Pointer,`tokenUrl`: RustBuffer.ByValue,`bodyJson`: RustBuffer.ByValue,`contentType`: RustBuffer.ByValue,uniffi_out_err: UniffiRustCallStatus,
939
+ ): RustBuffer.ByValue
884
940
  fun uniffi_native_agent_ffi_fn_method_nativeagenthandle_follow_up(`ptr`: Pointer,`prompt`: RustBuffer.ByValue,uniffi_out_err: UniffiRustCallStatus,
885
941
  ): Unit
886
942
  fun uniffi_native_agent_ffi_fn_method_nativeagenthandle_get_auth_status(`ptr`: Pointer,`provider`: RustBuffer.ByValue,uniffi_out_err: UniffiRustCallStatus,
@@ -935,6 +991,8 @@ internal interface UniffiLib : Library {
935
991
  ): Unit
936
992
  fun uniffi_native_agent_ffi_fn_method_nativeagenthandle_set_heartbeat_config(`ptr`: Pointer,`configJson`: RustBuffer.ByValue,uniffi_out_err: UniffiRustCallStatus,
937
993
  ): Unit
994
+ fun uniffi_native_agent_ffi_fn_method_nativeagenthandle_set_memory_provider(`ptr`: Pointer,`provider`: Long,uniffi_out_err: UniffiRustCallStatus,
995
+ ): Unit
938
996
  fun uniffi_native_agent_ffi_fn_method_nativeagenthandle_set_notifier(`ptr`: Pointer,`notifier`: Long,uniffi_out_err: UniffiRustCallStatus,
939
997
  ): Unit
940
998
  fun uniffi_native_agent_ffi_fn_method_nativeagenthandle_set_scheduler_config(`ptr`: Pointer,`configJson`: RustBuffer.ByValue,uniffi_out_err: UniffiRustCallStatus,
@@ -949,6 +1007,8 @@ internal interface UniffiLib : Library {
949
1007
  ): Unit
950
1008
  fun uniffi_native_agent_ffi_fn_method_nativeagenthandle_update_skill(`ptr`: Pointer,`id`: RustBuffer.ByValue,`patchJson`: RustBuffer.ByValue,uniffi_out_err: UniffiRustCallStatus,
951
1009
  ): Unit
1010
+ fun uniffi_native_agent_ffi_fn_init_callback_vtable_memoryprovider(`vtable`: UniffiVTableCallbackInterfaceMemoryProvider,
1011
+ ): Unit
952
1012
  fun uniffi_native_agent_ffi_fn_init_callback_vtable_nativeeventcallback(`vtable`: UniffiVTableCallbackInterfaceNativeEventCallback,
953
1013
  ): Unit
954
1014
  fun uniffi_native_agent_ffi_fn_init_callback_vtable_nativenotifier(`vtable`: UniffiVTableCallbackInterfaceNativeNotifier,
@@ -1085,6 +1145,8 @@ internal interface UniffiLib : Library {
1085
1145
  ): Short
1086
1146
  fun uniffi_native_agent_ffi_checksum_method_nativeagenthandle_end_skill(
1087
1147
  ): Short
1148
+ fun uniffi_native_agent_ffi_checksum_method_nativeagenthandle_exchange_oauth_code(
1149
+ ): Short
1088
1150
  fun uniffi_native_agent_ffi_checksum_method_nativeagenthandle_follow_up(
1089
1151
  ): Short
1090
1152
  fun uniffi_native_agent_ffi_checksum_method_nativeagenthandle_get_auth_status(
@@ -1139,6 +1201,8 @@ internal interface UniffiLib : Library {
1139
1201
  ): Short
1140
1202
  fun uniffi_native_agent_ffi_checksum_method_nativeagenthandle_set_heartbeat_config(
1141
1203
  ): Short
1204
+ fun uniffi_native_agent_ffi_checksum_method_nativeagenthandle_set_memory_provider(
1205
+ ): Short
1142
1206
  fun uniffi_native_agent_ffi_checksum_method_nativeagenthandle_set_notifier(
1143
1207
  ): Short
1144
1208
  fun uniffi_native_agent_ffi_checksum_method_nativeagenthandle_set_scheduler_config(
@@ -1155,6 +1219,16 @@ internal interface UniffiLib : Library {
1155
1219
  ): Short
1156
1220
  fun uniffi_native_agent_ffi_checksum_constructor_nativeagenthandle_new(
1157
1221
  ): Short
1222
+ fun uniffi_native_agent_ffi_checksum_method_memoryprovider_store(
1223
+ ): Short
1224
+ fun uniffi_native_agent_ffi_checksum_method_memoryprovider_recall(
1225
+ ): Short
1226
+ fun uniffi_native_agent_ffi_checksum_method_memoryprovider_forget(
1227
+ ): Short
1228
+ fun uniffi_native_agent_ffi_checksum_method_memoryprovider_search(
1229
+ ): Short
1230
+ fun uniffi_native_agent_ffi_checksum_method_memoryprovider_list(
1231
+ ): Short
1158
1232
  fun uniffi_native_agent_ffi_checksum_method_nativeeventcallback_on_event(
1159
1233
  ): Short
1160
1234
  fun uniffi_native_agent_ffi_checksum_method_nativenotifier_send_notification(
@@ -1200,6 +1274,9 @@ private fun uniffiCheckApiChecksums(lib: UniffiLib) {
1200
1274
  if (lib.uniffi_native_agent_ffi_checksum_method_nativeagenthandle_end_skill() != 49984.toShort()) {
1201
1275
  throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
1202
1276
  }
1277
+ if (lib.uniffi_native_agent_ffi_checksum_method_nativeagenthandle_exchange_oauth_code() != 22859.toShort()) {
1278
+ throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
1279
+ }
1203
1280
  if (lib.uniffi_native_agent_ffi_checksum_method_nativeagenthandle_follow_up() != 816.toShort()) {
1204
1281
  throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
1205
1282
  }
@@ -1281,6 +1358,9 @@ private fun uniffiCheckApiChecksums(lib: UniffiLib) {
1281
1358
  if (lib.uniffi_native_agent_ffi_checksum_method_nativeagenthandle_set_heartbeat_config() != 33968.toShort()) {
1282
1359
  throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
1283
1360
  }
1361
+ if (lib.uniffi_native_agent_ffi_checksum_method_nativeagenthandle_set_memory_provider() != 23171.toShort()) {
1362
+ throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
1363
+ }
1284
1364
  if (lib.uniffi_native_agent_ffi_checksum_method_nativeagenthandle_set_notifier() != 58795.toShort()) {
1285
1365
  throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
1286
1366
  }
@@ -1305,6 +1385,21 @@ private fun uniffiCheckApiChecksums(lib: UniffiLib) {
1305
1385
  if (lib.uniffi_native_agent_ffi_checksum_constructor_nativeagenthandle_new() != 18383.toShort()) {
1306
1386
  throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
1307
1387
  }
1388
+ if (lib.uniffi_native_agent_ffi_checksum_method_memoryprovider_store() != 49136.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_recall() != 3170.toShort()) {
1392
+ throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
1393
+ }
1394
+ if (lib.uniffi_native_agent_ffi_checksum_method_memoryprovider_forget() != 43231.toShort()) {
1395
+ throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
1396
+ }
1397
+ if (lib.uniffi_native_agent_ffi_checksum_method_memoryprovider_search() != 19100.toShort()) {
1398
+ throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
1399
+ }
1400
+ if (lib.uniffi_native_agent_ffi_checksum_method_memoryprovider_list() != 46802.toShort()) {
1401
+ throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
1402
+ }
1308
1403
  if (lib.uniffi_native_agent_ffi_checksum_method_nativeeventcallback_on_event() != 29742.toShort()) {
1309
1404
  throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
1310
1405
  }
@@ -1683,6 +1778,11 @@ public interface NativeAgentHandleInterface {
1683
1778
  */
1684
1779
  fun `endSkill`(`skillId`: kotlin.String)
1685
1780
 
1781
+ /**
1782
+ * Exchange an OAuth authorization code for tokens.
1783
+ */
1784
+ fun `exchangeOauthCode`(`tokenUrl`: kotlin.String, `bodyJson`: kotlin.String, `contentType`: kotlin.String?): kotlin.String
1785
+
1686
1786
  /**
1687
1787
  * Follow up on the current conversation.
1688
1788
  */
@@ -1815,6 +1915,8 @@ public interface NativeAgentHandleInterface {
1815
1915
  */
1816
1916
  fun `setHeartbeatConfig`(`configJson`: kotlin.String)
1817
1917
 
1918
+ fun `setMemoryProvider`(`provider`: MemoryProvider)
1919
+
1818
1920
  fun `setNotifier`(`notifier`: NativeNotifier)
1819
1921
 
1820
1922
  /**
@@ -2039,6 +2141,22 @@ open class NativeAgentHandle: Disposable, AutoCloseable, NativeAgentHandleInterf
2039
2141
 
2040
2142
 
2041
2143
 
2144
+ /**
2145
+ * Exchange an OAuth authorization code for tokens.
2146
+ */
2147
+ @Throws(NativeAgentException::class)override fun `exchangeOauthCode`(`tokenUrl`: kotlin.String, `bodyJson`: kotlin.String, `contentType`: kotlin.String?): kotlin.String {
2148
+ return FfiConverterString.lift(
2149
+ callWithPointer {
2150
+ uniffiRustCallWithError(NativeAgentException) { _status ->
2151
+ UniffiLib.INSTANCE.uniffi_native_agent_ffi_fn_method_nativeagenthandle_exchange_oauth_code(
2152
+ it, FfiConverterString.lower(`tokenUrl`),FfiConverterString.lower(`bodyJson`),FfiConverterOptionalString.lower(`contentType`),_status)
2153
+ }
2154
+ }
2155
+ )
2156
+ }
2157
+
2158
+
2159
+
2042
2160
  /**
2043
2161
  * Follow up on the current conversation.
2044
2162
  */
@@ -2455,6 +2573,18 @@ open class NativeAgentHandle: Disposable, AutoCloseable, NativeAgentHandleInterf
2455
2573
 
2456
2574
 
2457
2575
 
2576
+ @Throws(NativeAgentException::class)override fun `setMemoryProvider`(`provider`: MemoryProvider)
2577
+ =
2578
+ callWithPointer {
2579
+ uniffiRustCallWithError(NativeAgentException) { _status ->
2580
+ UniffiLib.INSTANCE.uniffi_native_agent_ffi_fn_method_nativeagenthandle_set_memory_provider(
2581
+ it, FfiConverterTypeMemoryProvider.lower(`provider`),_status)
2582
+ }
2583
+ }
2584
+
2585
+
2586
+
2587
+
2458
2588
  @Throws(NativeAgentException::class)override fun `setNotifier`(`notifier`: NativeNotifier)
2459
2589
  =
2460
2590
  callWithPointer {
@@ -3043,16 +3173,20 @@ public object FfiConverterTypeNativeAgentError : FfiConverterRustBuffer<NativeAg
3043
3173
 
3044
3174
 
3045
3175
  /**
3046
- * Callback interface for events from the native agent.
3176
+ * Callback interface for memory operations (LanceDB or any vector store).
3177
+ * Implemented by Kotlin/Swift, which bridges to the actual memory backend.
3047
3178
  */
3048
- public interface NativeEventCallback {
3179
+ public interface MemoryProvider {
3049
3180
 
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)
3181
+ fun `store`(`key`: kotlin.String, `text`: kotlin.String, `metadataJson`: kotlin.String?): kotlin.String
3182
+
3183
+ fun `recall`(`query`: kotlin.String, `limit`: kotlin.UInt): kotlin.String
3184
+
3185
+ fun `forget`(`key`: kotlin.String): kotlin.String
3186
+
3187
+ fun `search`(`query`: kotlin.String, `maxResults`: kotlin.UInt): kotlin.String
3188
+
3189
+ fun `list`(`prefix`: kotlin.String?, `limit`: kotlin.UInt?): kotlin.String
3056
3190
 
3057
3191
  companion object
3058
3192
  }
@@ -3090,6 +3224,124 @@ public abstract class FfiConverterCallbackInterface<CallbackInterface: Any>: Ffi
3090
3224
  }
3091
3225
  }
3092
3226
 
3227
+ // Put the implementation in an object so we don't pollute the top-level namespace
3228
+ internal object uniffiCallbackInterfaceMemoryProvider {
3229
+ internal object `store`: UniffiCallbackInterfaceMemoryProviderMethod0 {
3230
+ override fun callback(`uniffiHandle`: Long,`key`: RustBuffer.ByValue,`text`: RustBuffer.ByValue,`metadataJson`: RustBuffer.ByValue,`uniffiOutReturn`: RustBuffer,uniffiCallStatus: UniffiRustCallStatus,) {
3231
+ val uniffiObj = FfiConverterTypeMemoryProvider.handleMap.get(uniffiHandle)
3232
+ val makeCall = { ->
3233
+ uniffiObj.`store`(
3234
+ FfiConverterString.lift(`key`),
3235
+ FfiConverterString.lift(`text`),
3236
+ FfiConverterOptionalString.lift(`metadataJson`),
3237
+ )
3238
+ }
3239
+ val writeReturn = { value: kotlin.String -> uniffiOutReturn.setValue(FfiConverterString.lower(value)) }
3240
+ uniffiTraitInterfaceCall(uniffiCallStatus, makeCall, writeReturn)
3241
+ }
3242
+ }
3243
+ internal object `recall`: UniffiCallbackInterfaceMemoryProviderMethod1 {
3244
+ override fun callback(`uniffiHandle`: Long,`query`: RustBuffer.ByValue,`limit`: Int,`uniffiOutReturn`: RustBuffer,uniffiCallStatus: UniffiRustCallStatus,) {
3245
+ val uniffiObj = FfiConverterTypeMemoryProvider.handleMap.get(uniffiHandle)
3246
+ val makeCall = { ->
3247
+ uniffiObj.`recall`(
3248
+ FfiConverterString.lift(`query`),
3249
+ FfiConverterUInt.lift(`limit`),
3250
+ )
3251
+ }
3252
+ val writeReturn = { value: kotlin.String -> uniffiOutReturn.setValue(FfiConverterString.lower(value)) }
3253
+ uniffiTraitInterfaceCall(uniffiCallStatus, makeCall, writeReturn)
3254
+ }
3255
+ }
3256
+ internal object `forget`: UniffiCallbackInterfaceMemoryProviderMethod2 {
3257
+ override fun callback(`uniffiHandle`: Long,`key`: RustBuffer.ByValue,`uniffiOutReturn`: RustBuffer,uniffiCallStatus: UniffiRustCallStatus,) {
3258
+ val uniffiObj = FfiConverterTypeMemoryProvider.handleMap.get(uniffiHandle)
3259
+ val makeCall = { ->
3260
+ uniffiObj.`forget`(
3261
+ FfiConverterString.lift(`key`),
3262
+ )
3263
+ }
3264
+ val writeReturn = { value: kotlin.String -> uniffiOutReturn.setValue(FfiConverterString.lower(value)) }
3265
+ uniffiTraitInterfaceCall(uniffiCallStatus, makeCall, writeReturn)
3266
+ }
3267
+ }
3268
+ internal object `search`: UniffiCallbackInterfaceMemoryProviderMethod3 {
3269
+ override fun callback(`uniffiHandle`: Long,`query`: RustBuffer.ByValue,`maxResults`: Int,`uniffiOutReturn`: RustBuffer,uniffiCallStatus: UniffiRustCallStatus,) {
3270
+ val uniffiObj = FfiConverterTypeMemoryProvider.handleMap.get(uniffiHandle)
3271
+ val makeCall = { ->
3272
+ uniffiObj.`search`(
3273
+ FfiConverterString.lift(`query`),
3274
+ FfiConverterUInt.lift(`maxResults`),
3275
+ )
3276
+ }
3277
+ val writeReturn = { value: kotlin.String -> uniffiOutReturn.setValue(FfiConverterString.lower(value)) }
3278
+ uniffiTraitInterfaceCall(uniffiCallStatus, makeCall, writeReturn)
3279
+ }
3280
+ }
3281
+ internal object `list`: UniffiCallbackInterfaceMemoryProviderMethod4 {
3282
+ override fun callback(`uniffiHandle`: Long,`prefix`: RustBuffer.ByValue,`limit`: RustBuffer.ByValue,`uniffiOutReturn`: RustBuffer,uniffiCallStatus: UniffiRustCallStatus,) {
3283
+ val uniffiObj = FfiConverterTypeMemoryProvider.handleMap.get(uniffiHandle)
3284
+ val makeCall = { ->
3285
+ uniffiObj.`list`(
3286
+ FfiConverterOptionalString.lift(`prefix`),
3287
+ FfiConverterOptionalUInt.lift(`limit`),
3288
+ )
3289
+ }
3290
+ val writeReturn = { value: kotlin.String -> uniffiOutReturn.setValue(FfiConverterString.lower(value)) }
3291
+ uniffiTraitInterfaceCall(uniffiCallStatus, makeCall, writeReturn)
3292
+ }
3293
+ }
3294
+
3295
+ internal object uniffiFree: UniffiCallbackInterfaceFree {
3296
+ override fun callback(handle: Long) {
3297
+ FfiConverterTypeMemoryProvider.handleMap.remove(handle)
3298
+ }
3299
+ }
3300
+
3301
+ internal var vtable = UniffiVTableCallbackInterfaceMemoryProvider.UniffiByValue(
3302
+ `store`,
3303
+ `recall`,
3304
+ `forget`,
3305
+ `search`,
3306
+ `list`,
3307
+ uniffiFree,
3308
+ )
3309
+
3310
+ // Registers the foreign callback with the Rust side.
3311
+ // This method is generated for each callback interface.
3312
+ internal fun register(lib: UniffiLib) {
3313
+ lib.uniffi_native_agent_ffi_fn_init_callback_vtable_memoryprovider(vtable)
3314
+ }
3315
+ }
3316
+
3317
+ /**
3318
+ * The ffiConverter which transforms the Callbacks in to handles to pass to Rust.
3319
+ *
3320
+ * @suppress
3321
+ */
3322
+ public object FfiConverterTypeMemoryProvider: FfiConverterCallbackInterface<MemoryProvider>()
3323
+
3324
+
3325
+
3326
+
3327
+
3328
+ /**
3329
+ * Callback interface for events from the native agent.
3330
+ */
3331
+ public interface NativeEventCallback {
3332
+
3333
+ /**
3334
+ * Called when the agent emits an event.
3335
+ * `event_type`: text_delta, tool_use, tool_result, agent.completed, agent.error, etc.
3336
+ * `payload_json`: JSON-encoded event data.
3337
+ */
3338
+ fun `onEvent`(`eventType`: kotlin.String, `payloadJson`: kotlin.String)
3339
+
3340
+ companion object
3341
+ }
3342
+
3343
+
3344
+
3093
3345
  // Put the implementation in an object so we don't pollute the top-level namespace
3094
3346
  internal object uniffiCallbackInterfaceNativeEventCallback {
3095
3347
  internal object `onEvent`: UniffiCallbackInterfaceNativeEventCallbackMethod0 {
@@ -182,6 +182,17 @@ export interface NativeAgentPlugin {
182
182
  getAuthStatus(options: {
183
183
  provider: string;
184
184
  }): Promise<AuthStatusResult>;
185
+ exchangeOAuthCode(options: {
186
+ tokenUrl: string;
187
+ bodyJson: string;
188
+ contentType?: string;
189
+ }): Promise<{
190
+ success: boolean;
191
+ status?: number;
192
+ data?: any;
193
+ text?: string;
194
+ error?: string;
195
+ }>;
185
196
  listSessions(options: {
186
197
  agentId: string;
187
198
  }): Promise<{