capacitor-native-agent 0.9.3 → 0.9.5
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/android/src/main/java/com/t6x/plugins/nativeagent/NativeAgentBridge.kt +70 -0
- package/android/src/main/java/com/t6x/plugins/nativeagent/NativeAgentPlugin.kt +3 -0
- package/android/src/main/java/uniffi/native_agent_ffi/native_agent_ffi.kt +1310 -962
- package/android/src/main/jniLibs/arm64-v8a/libnative_agent_ffi.so +0 -0
- package/ios/Frameworks/NativeAgentFFI.xcframework/ios-arm64/Headers/native_agent_ffi/native_agent_ffi.swift +878 -411
- package/ios/Frameworks/NativeAgentFFI.xcframework/ios-arm64/Headers/native_agent_ffi/native_agent_ffiFFI.h +212 -162
- package/ios/Frameworks/NativeAgentFFI.xcframework/ios-arm64/libnative_agent_ffi.a +0 -0
- package/ios/Frameworks/NativeAgentFFI.xcframework/ios-arm64-simulator/Headers/native_agent_ffi/native_agent_ffi.swift +878 -411
- package/ios/Frameworks/NativeAgentFFI.xcframework/ios-arm64-simulator/Headers/native_agent_ffi/native_agent_ffiFFI.h +212 -162
- package/ios/Frameworks/NativeAgentFFI.xcframework/ios-arm64-simulator/libnative_agent_ffi.a +0 -0
- package/ios/Sources/NativeAgentPlugin/Generated/native_agent_ffi.swift +878 -411
- package/ios/Sources/NativeAgentPlugin/Generated/native_agent_ffiFFI.h +212 -162
- package/ios/Sources/NativeAgentPlugin/Generated/native_agent_ffiFFI.modulemap +3 -0
- package/ios/Sources/NativeAgentPlugin/NativeAgentBridge.swift +64 -0
- package/ios/Sources/NativeAgentPlugin/NativeAgentPlugin.swift +6 -0
- package/package.json +1 -1
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import Foundation
|
|
2
|
+
|
|
3
|
+
/// Listener protocol for in-process Swift code that wants to observe
|
|
4
|
+
/// raw FFI events alongside the WebView listener. Mirrors the shape of
|
|
5
|
+
/// the UniFFI-generated NativeEventCallback protocol but is registered
|
|
6
|
+
/// through NativeAgentBridge instead of the FFI itself, so multiple
|
|
7
|
+
/// consumers can subscribe at once.
|
|
8
|
+
public protocol NativeEventListener: AnyObject {
|
|
9
|
+
func onEvent(eventType: String, payloadJson: String)
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
/// Process-wide accessor that exposes the live NativeAgentHandle and a
|
|
13
|
+
/// multi-listener event fan-out to other modules in the same iOS
|
|
14
|
+
/// process — most notably the STOMP transport in theshell.
|
|
15
|
+
///
|
|
16
|
+
/// The single FFI-side NativeEventCallback registered by NativeAgentPlugin
|
|
17
|
+
/// (NativeAgentEventBridge in NativeAgentPlugin.swift) forwards every
|
|
18
|
+
/// event into `dispatch` in addition to its existing notifyListeners
|
|
19
|
+
/// call, so the WebView pipeline is byte-equivalent to before this
|
|
20
|
+
/// bridge existed.
|
|
21
|
+
///
|
|
22
|
+
/// Listeners are strong-referenced by ObjectIdentifier; callers MUST
|
|
23
|
+
/// call `removeNativeEventListener` when their lifecycle ends.
|
|
24
|
+
public enum NativeAgentBridge {
|
|
25
|
+
|
|
26
|
+
private static let lock = NSLock()
|
|
27
|
+
private static var handleRef: NativeAgentHandle?
|
|
28
|
+
private static var listeners: [ObjectIdentifier: NativeEventListener] = [:]
|
|
29
|
+
|
|
30
|
+
/// The live FFI handle, or nil if NativeAgent has not been
|
|
31
|
+
/// initialized yet (or has been destroyed).
|
|
32
|
+
public static func handle() -> NativeAgentHandle? {
|
|
33
|
+
lock.lock()
|
|
34
|
+
defer { lock.unlock() }
|
|
35
|
+
return handleRef
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
public static func addNativeEventListener(_ listener: NativeEventListener) {
|
|
39
|
+
lock.lock()
|
|
40
|
+
defer { lock.unlock() }
|
|
41
|
+
listeners[ObjectIdentifier(listener)] = listener
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
public static func removeNativeEventListener(_ listener: NativeEventListener) {
|
|
45
|
+
lock.lock()
|
|
46
|
+
defer { lock.unlock() }
|
|
47
|
+
listeners.removeValue(forKey: ObjectIdentifier(listener))
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
internal static func setHandle(_ h: NativeAgentHandle?) {
|
|
51
|
+
lock.lock()
|
|
52
|
+
defer { lock.unlock() }
|
|
53
|
+
handleRef = h
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
internal static func dispatch(eventType: String, payloadJson: String) {
|
|
57
|
+
lock.lock()
|
|
58
|
+
let snapshot = Array(listeners.values)
|
|
59
|
+
lock.unlock()
|
|
60
|
+
for l in snapshot {
|
|
61
|
+
l.onEvent(eventType: eventType, payloadJson: payloadJson)
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
}
|
|
@@ -66,6 +66,10 @@ public class NativeAgentPlugin: CAPPlugin, CAPBridgedPlugin {
|
|
|
66
66
|
|
|
67
67
|
private var handle: NativeAgentHandle?
|
|
68
68
|
|
|
69
|
+
deinit {
|
|
70
|
+
NativeAgentBridge.setHandle(nil)
|
|
71
|
+
}
|
|
72
|
+
|
|
69
73
|
// ── Helper ──────────────────────────────────────────────────────────────
|
|
70
74
|
|
|
71
75
|
/// Resolves a `files://` prefixed path to an absolute iOS path
|
|
@@ -173,6 +177,7 @@ public class NativeAgentPlugin: CAPPlugin, CAPBridgedPlugin {
|
|
|
173
177
|
}
|
|
174
178
|
try h.persistConfig()
|
|
175
179
|
self.handle = h
|
|
180
|
+
NativeAgentBridge.setHandle(h)
|
|
176
181
|
UserDefaults.standard.set(
|
|
177
182
|
self.resolveConfigPath(workspacePath: resolvedWorkspacePath),
|
|
178
183
|
forKey: Self.configPathKey
|
|
@@ -837,5 +842,6 @@ class NativeAgentEventBridge: NativeEventCallback {
|
|
|
837
842
|
"eventType": eventType,
|
|
838
843
|
"payloadJson": payloadJson,
|
|
839
844
|
])
|
|
845
|
+
NativeAgentBridge.dispatch(eventType: eventType, payloadJson: payloadJson)
|
|
840
846
|
}
|
|
841
847
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "capacitor-native-agent",
|
|
3
|
-
"version": "0.9.
|
|
3
|
+
"version": "0.9.5",
|
|
4
4
|
"description": "Native AI agent loop for Capacitor — runs LLM completions, tool execution, and cron jobs in native Rust, enabling background execution.",
|
|
5
5
|
"main": "dist/esm/index.js",
|
|
6
6
|
"types": "dist/esm/index.d.ts",
|