capacitor-native-agent 0.9.0 → 0.9.2
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 +26 -23
- package/android/src/main/java/com/t6x/plugins/nativeagent/NativeAgentPlugin.kt +8 -0
- package/android/src/main/java/uniffi/native_agent_ffi/native_agent_ffi.kt +22 -2
- package/android/src/main/jniLibs/arm64-v8a/libnative_agent_ffi.so +0 -0
- package/dist/esm/definitions.d.ts +22 -0
- package/dist/esm/definitions.d.ts.map +1 -1
- package/ios/Frameworks/NativeAgentFFI.xcframework/ios-arm64/Headers/native_agent_ffi/native_agent_ffi.swift +399 -17
- package/ios/Frameworks/NativeAgentFFI.xcframework/ios-arm64/Headers/native_agent_ffi/native_agent_ffiFFI.h +109 -2
- 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 +399 -17
- package/ios/Frameworks/NativeAgentFFI.xcframework/ios-arm64-simulator/Headers/native_agent_ffi/native_agent_ffiFFI.h +109 -2
- package/ios/Frameworks/NativeAgentFFI.xcframework/ios-arm64-simulator/libnative_agent_ffi.a +0 -0
- package/ios/Sources/NativeAgentPlugin/Generated/native_agent_ffi.swift +360 -9
- package/ios/Sources/NativeAgentPlugin/Generated/native_agent_ffiFFI.h +107 -0
- package/ios/Sources/NativeAgentPlugin/NativeAgentPlugin.swift +10 -2
- package/package.json +1 -1
|
@@ -657,8 +657,10 @@ public protocol NativeAgentHandleProtocol : AnyObject {
|
|
|
657
657
|
|
|
658
658
|
/**
|
|
659
659
|
* Resume a session (load messages into agent context).
|
|
660
|
+
* Returns `was_interrupted: true` if the session had an in-progress turn
|
|
661
|
+
* that was killed (e.g. app force-close). The caller can auto-resume.
|
|
660
662
|
*/
|
|
661
|
-
func resumeSession(sessionKey: String, agentId: String, messagesJson: String?, provider: String?, model: String?) throws
|
|
663
|
+
func resumeSession(sessionKey: String, agentId: String, messagesJson: String?, provider: String?, model: String?) throws -> Bool
|
|
662
664
|
|
|
663
665
|
/**
|
|
664
666
|
* Force-trigger a cron job.
|
|
@@ -678,13 +680,19 @@ public protocol NativeAgentHandleProtocol : AnyObject {
|
|
|
678
680
|
/**
|
|
679
681
|
* Set an auth key for a provider.
|
|
680
682
|
*/
|
|
681
|
-
func setAuthKey(key: String, provider: String, authType: String) throws
|
|
683
|
+
func setAuthKey(key: String, provider: String, authType: String, refresh: String?, expiresAt: Int64?) throws
|
|
682
684
|
|
|
683
685
|
/**
|
|
684
686
|
* Set the event callback for receiving agent events.
|
|
685
687
|
*/
|
|
686
688
|
func setEventCallback(callback: NativeEventCallback) throws
|
|
687
689
|
|
|
690
|
+
/**
|
|
691
|
+
* Set the optional governance provider (taint, audit, loop-guard, cost tracking).
|
|
692
|
+
* Typically called by capacitor-agent-os when it auto-registers at init time.
|
|
693
|
+
*/
|
|
694
|
+
func setGovernanceProvider(provider: GovernanceProvider) throws
|
|
695
|
+
|
|
688
696
|
/**
|
|
689
697
|
* Set heartbeat config.
|
|
690
698
|
*/
|
|
@@ -1124,8 +1132,11 @@ open func restartMcp(toolsJson: String)throws -> UInt32 {
|
|
|
1124
1132
|
|
|
1125
1133
|
/**
|
|
1126
1134
|
* Resume a session (load messages into agent context).
|
|
1135
|
+
* Returns `was_interrupted: true` if the session had an in-progress turn
|
|
1136
|
+
* that was killed (e.g. app force-close). The caller can auto-resume.
|
|
1127
1137
|
*/
|
|
1128
|
-
open func resumeSession(sessionKey: String, agentId: String, messagesJson: String?, provider: String?, model: String?)throws
|
|
1138
|
+
open func resumeSession(sessionKey: String, agentId: String, messagesJson: String?, provider: String?, model: String?)throws -> Bool {
|
|
1139
|
+
return try FfiConverterBool.lift(try rustCallWithError(FfiConverterTypeNativeAgentError.lift) {
|
|
1129
1140
|
uniffi_native_agent_ffi_fn_method_nativeagenthandle_resume_session(self.uniffiClonePointer(),
|
|
1130
1141
|
FfiConverterString.lower(sessionKey),
|
|
1131
1142
|
FfiConverterString.lower(agentId),
|
|
@@ -1133,7 +1144,7 @@ open func resumeSession(sessionKey: String, agentId: String, messagesJson: Strin
|
|
|
1133
1144
|
FfiConverterOptionString.lower(provider),
|
|
1134
1145
|
FfiConverterOptionString.lower(model),$0
|
|
1135
1146
|
)
|
|
1136
|
-
}
|
|
1147
|
+
})
|
|
1137
1148
|
}
|
|
1138
1149
|
|
|
1139
1150
|
/**
|
|
@@ -1171,11 +1182,13 @@ open func sendMessage(params: SendMessageParams)throws -> String {
|
|
|
1171
1182
|
/**
|
|
1172
1183
|
* Set an auth key for a provider.
|
|
1173
1184
|
*/
|
|
1174
|
-
open func setAuthKey(key: String, provider: String, authType: String)throws {try rustCallWithError(FfiConverterTypeNativeAgentError.lift) {
|
|
1185
|
+
open func setAuthKey(key: String, provider: String, authType: String, refresh: String?, expiresAt: Int64?)throws {try rustCallWithError(FfiConverterTypeNativeAgentError.lift) {
|
|
1175
1186
|
uniffi_native_agent_ffi_fn_method_nativeagenthandle_set_auth_key(self.uniffiClonePointer(),
|
|
1176
1187
|
FfiConverterString.lower(key),
|
|
1177
1188
|
FfiConverterString.lower(provider),
|
|
1178
|
-
FfiConverterString.lower(authType)
|
|
1189
|
+
FfiConverterString.lower(authType),
|
|
1190
|
+
FfiConverterOptionString.lower(refresh),
|
|
1191
|
+
FfiConverterOptionInt64.lower(expiresAt),$0
|
|
1179
1192
|
)
|
|
1180
1193
|
}
|
|
1181
1194
|
}
|
|
@@ -1188,6 +1201,17 @@ open func setEventCallback(callback: NativeEventCallback)throws {try rustCallWi
|
|
|
1188
1201
|
FfiConverterCallbackInterfaceNativeEventCallback.lower(callback),$0
|
|
1189
1202
|
)
|
|
1190
1203
|
}
|
|
1204
|
+
}
|
|
1205
|
+
|
|
1206
|
+
/**
|
|
1207
|
+
* Set the optional governance provider (taint, audit, loop-guard, cost tracking).
|
|
1208
|
+
* Typically called by capacitor-agent-os when it auto-registers at init time.
|
|
1209
|
+
*/
|
|
1210
|
+
open func setGovernanceProvider(provider: GovernanceProvider)throws {try rustCallWithError(FfiConverterTypeNativeAgentError.lift) {
|
|
1211
|
+
uniffi_native_agent_ffi_fn_method_nativeagenthandle_set_governance_provider(self.uniffiClonePointer(),
|
|
1212
|
+
FfiConverterCallbackInterfaceGovernanceProvider.lower(provider),$0
|
|
1213
|
+
)
|
|
1214
|
+
}
|
|
1191
1215
|
}
|
|
1192
1216
|
|
|
1193
1217
|
/**
|
|
@@ -1509,6 +1533,20 @@ public struct InitConfig {
|
|
|
1509
1533
|
* Path to auth-profiles.json.
|
|
1510
1534
|
*/
|
|
1511
1535
|
public var authProfilesPath: String
|
|
1536
|
+
/**
|
|
1537
|
+
* Configured default LLM provider for this agent. When a per-call
|
|
1538
|
+
* `SendMessageParams.provider` is unset, the resolver falls back to
|
|
1539
|
+
* this value. `None` falls through to the hardcoded "anthropic"
|
|
1540
|
+
* safety net — which any properly-configured install should never hit.
|
|
1541
|
+
*/
|
|
1542
|
+
public var defaultProvider: String?
|
|
1543
|
+
/**
|
|
1544
|
+
* Configured default model. Only used when the resolver also took
|
|
1545
|
+
* `default_provider` (i.e. the caller didn't override provider) — if
|
|
1546
|
+
* provider is overridden, the per-provider default model is used
|
|
1547
|
+
* instead, since model strings are tied to providers.
|
|
1548
|
+
*/
|
|
1549
|
+
public var defaultModel: String?
|
|
1512
1550
|
|
|
1513
1551
|
// Default memberwise initializers are never public by default, so we
|
|
1514
1552
|
// declare one manually.
|
|
@@ -1521,10 +1559,24 @@ public struct InitConfig {
|
|
|
1521
1559
|
*/workspacePath: String,
|
|
1522
1560
|
/**
|
|
1523
1561
|
* Path to auth-profiles.json.
|
|
1524
|
-
*/authProfilesPath: String
|
|
1562
|
+
*/authProfilesPath: String,
|
|
1563
|
+
/**
|
|
1564
|
+
* Configured default LLM provider for this agent. When a per-call
|
|
1565
|
+
* `SendMessageParams.provider` is unset, the resolver falls back to
|
|
1566
|
+
* this value. `None` falls through to the hardcoded "anthropic"
|
|
1567
|
+
* safety net — which any properly-configured install should never hit.
|
|
1568
|
+
*/defaultProvider: String?,
|
|
1569
|
+
/**
|
|
1570
|
+
* Configured default model. Only used when the resolver also took
|
|
1571
|
+
* `default_provider` (i.e. the caller didn't override provider) — if
|
|
1572
|
+
* provider is overridden, the per-provider default model is used
|
|
1573
|
+
* instead, since model strings are tied to providers.
|
|
1574
|
+
*/defaultModel: String?) {
|
|
1525
1575
|
self.dbPath = dbPath
|
|
1526
1576
|
self.workspacePath = workspacePath
|
|
1527
1577
|
self.authProfilesPath = authProfilesPath
|
|
1578
|
+
self.defaultProvider = defaultProvider
|
|
1579
|
+
self.defaultModel = defaultModel
|
|
1528
1580
|
}
|
|
1529
1581
|
}
|
|
1530
1582
|
|
|
@@ -1541,6 +1593,12 @@ extension InitConfig: Equatable, Hashable {
|
|
|
1541
1593
|
if lhs.authProfilesPath != rhs.authProfilesPath {
|
|
1542
1594
|
return false
|
|
1543
1595
|
}
|
|
1596
|
+
if lhs.defaultProvider != rhs.defaultProvider {
|
|
1597
|
+
return false
|
|
1598
|
+
}
|
|
1599
|
+
if lhs.defaultModel != rhs.defaultModel {
|
|
1600
|
+
return false
|
|
1601
|
+
}
|
|
1544
1602
|
return true
|
|
1545
1603
|
}
|
|
1546
1604
|
|
|
@@ -1548,6 +1606,8 @@ extension InitConfig: Equatable, Hashable {
|
|
|
1548
1606
|
hasher.combine(dbPath)
|
|
1549
1607
|
hasher.combine(workspacePath)
|
|
1550
1608
|
hasher.combine(authProfilesPath)
|
|
1609
|
+
hasher.combine(defaultProvider)
|
|
1610
|
+
hasher.combine(defaultModel)
|
|
1551
1611
|
}
|
|
1552
1612
|
}
|
|
1553
1613
|
|
|
@@ -1561,7 +1621,9 @@ public struct FfiConverterTypeInitConfig: FfiConverterRustBuffer {
|
|
|
1561
1621
|
try InitConfig(
|
|
1562
1622
|
dbPath: FfiConverterString.read(from: &buf),
|
|
1563
1623
|
workspacePath: FfiConverterString.read(from: &buf),
|
|
1564
|
-
authProfilesPath: FfiConverterString.read(from: &buf)
|
|
1624
|
+
authProfilesPath: FfiConverterString.read(from: &buf),
|
|
1625
|
+
defaultProvider: FfiConverterOptionString.read(from: &buf),
|
|
1626
|
+
defaultModel: FfiConverterOptionString.read(from: &buf)
|
|
1565
1627
|
)
|
|
1566
1628
|
}
|
|
1567
1629
|
|
|
@@ -1569,6 +1631,8 @@ public struct FfiConverterTypeInitConfig: FfiConverterRustBuffer {
|
|
|
1569
1631
|
FfiConverterString.write(value.dbPath, into: &buf)
|
|
1570
1632
|
FfiConverterString.write(value.workspacePath, into: &buf)
|
|
1571
1633
|
FfiConverterString.write(value.authProfilesPath, into: &buf)
|
|
1634
|
+
FfiConverterOptionString.write(value.defaultProvider, into: &buf)
|
|
1635
|
+
FfiConverterOptionString.write(value.defaultModel, into: &buf)
|
|
1572
1636
|
}
|
|
1573
1637
|
}
|
|
1574
1638
|
|
|
@@ -1995,6 +2059,284 @@ extension NativeAgentError: Foundation.LocalizedError {
|
|
|
1995
2059
|
|
|
1996
2060
|
|
|
1997
2061
|
|
|
2062
|
+
/**
|
|
2063
|
+
* Optional governance provider for security, audit, and loop-guard checks.
|
|
2064
|
+
* Implemented by Kotlin/Swift — typically backed by capacitor-agent-os when
|
|
2065
|
+
* that plugin is installed. When absent, the agent loop runs without
|
|
2066
|
+
* governance checks.
|
|
2067
|
+
*/
|
|
2068
|
+
public protocol GovernanceProvider : AnyObject {
|
|
2069
|
+
|
|
2070
|
+
/**
|
|
2071
|
+
* Check if a tool call should proceed. Returns JSON verdict:
|
|
2072
|
+
* `{"type":"Allow"}` | `{"type":"Warn","reason":"..."}` |
|
|
2073
|
+
* `{"type":"Block","reason":"..."}` | `{"type":"CircuitBreak","reason":"..."}`
|
|
2074
|
+
*/
|
|
2075
|
+
func checkLoop(toolName: String, paramsJson: String) -> String
|
|
2076
|
+
|
|
2077
|
+
/**
|
|
2078
|
+
* Record tool outcome for loop detection. Returns optional warning string.
|
|
2079
|
+
*/
|
|
2080
|
+
func recordOutcome(toolName: String, paramsJson: String, result: String) -> String?
|
|
2081
|
+
|
|
2082
|
+
/**
|
|
2083
|
+
* Record an audit trail entry.
|
|
2084
|
+
*/
|
|
2085
|
+
func recordAudit(agentId: String, action: String, detail: String, outcome: String)
|
|
2086
|
+
|
|
2087
|
+
/**
|
|
2088
|
+
* Check if content is tainted before passing to LLM. Returns JSON:
|
|
2089
|
+
* `{"blocked":true/false,"reason":"...","matchedLabels":[...]}`
|
|
2090
|
+
*/
|
|
2091
|
+
func checkSink(sinkType: String, content: String) -> String
|
|
2092
|
+
|
|
2093
|
+
/**
|
|
2094
|
+
* Reset loop guard state (e.g. on new session).
|
|
2095
|
+
*/
|
|
2096
|
+
func reset()
|
|
2097
|
+
|
|
2098
|
+
/**
|
|
2099
|
+
* Record token usage for cost tracking.
|
|
2100
|
+
*/
|
|
2101
|
+
func recordUsage(modelId: String, inputTokens: UInt32, outputTokens: UInt32)
|
|
2102
|
+
|
|
2103
|
+
}
|
|
2104
|
+
|
|
2105
|
+
// Magic number for the Rust proxy to call using the same mechanism as every other method,
|
|
2106
|
+
// to free the callback once it's dropped by Rust.
|
|
2107
|
+
private let IDX_CALLBACK_FREE: Int32 = 0
|
|
2108
|
+
// Callback return codes
|
|
2109
|
+
private let UNIFFI_CALLBACK_SUCCESS: Int32 = 0
|
|
2110
|
+
private let UNIFFI_CALLBACK_ERROR: Int32 = 1
|
|
2111
|
+
private let UNIFFI_CALLBACK_UNEXPECTED_ERROR: Int32 = 2
|
|
2112
|
+
|
|
2113
|
+
// Put the implementation in a struct so we don't pollute the top-level namespace
|
|
2114
|
+
fileprivate struct UniffiCallbackInterfaceGovernanceProvider {
|
|
2115
|
+
|
|
2116
|
+
// Create the VTable using a series of closures.
|
|
2117
|
+
// Swift automatically converts these into C callback functions.
|
|
2118
|
+
static var vtable: UniffiVTableCallbackInterfaceGovernanceProvider = UniffiVTableCallbackInterfaceGovernanceProvider(
|
|
2119
|
+
checkLoop: { (
|
|
2120
|
+
uniffiHandle: UInt64,
|
|
2121
|
+
toolName: RustBuffer,
|
|
2122
|
+
paramsJson: RustBuffer,
|
|
2123
|
+
uniffiOutReturn: UnsafeMutablePointer<RustBuffer>,
|
|
2124
|
+
uniffiCallStatus: UnsafeMutablePointer<RustCallStatus>
|
|
2125
|
+
) in
|
|
2126
|
+
let makeCall = {
|
|
2127
|
+
() throws -> String in
|
|
2128
|
+
guard let uniffiObj = try? FfiConverterCallbackInterfaceGovernanceProvider.handleMap.get(handle: uniffiHandle) else {
|
|
2129
|
+
throw UniffiInternalError.unexpectedStaleHandle
|
|
2130
|
+
}
|
|
2131
|
+
return uniffiObj.checkLoop(
|
|
2132
|
+
toolName: try FfiConverterString.lift(toolName),
|
|
2133
|
+
paramsJson: try FfiConverterString.lift(paramsJson)
|
|
2134
|
+
)
|
|
2135
|
+
}
|
|
2136
|
+
|
|
2137
|
+
|
|
2138
|
+
let writeReturn = { uniffiOutReturn.pointee = FfiConverterString.lower($0) }
|
|
2139
|
+
uniffiTraitInterfaceCall(
|
|
2140
|
+
callStatus: uniffiCallStatus,
|
|
2141
|
+
makeCall: makeCall,
|
|
2142
|
+
writeReturn: writeReturn
|
|
2143
|
+
)
|
|
2144
|
+
},
|
|
2145
|
+
recordOutcome: { (
|
|
2146
|
+
uniffiHandle: UInt64,
|
|
2147
|
+
toolName: RustBuffer,
|
|
2148
|
+
paramsJson: RustBuffer,
|
|
2149
|
+
result: RustBuffer,
|
|
2150
|
+
uniffiOutReturn: UnsafeMutablePointer<RustBuffer>,
|
|
2151
|
+
uniffiCallStatus: UnsafeMutablePointer<RustCallStatus>
|
|
2152
|
+
) in
|
|
2153
|
+
let makeCall = {
|
|
2154
|
+
() throws -> String? in
|
|
2155
|
+
guard let uniffiObj = try? FfiConverterCallbackInterfaceGovernanceProvider.handleMap.get(handle: uniffiHandle) else {
|
|
2156
|
+
throw UniffiInternalError.unexpectedStaleHandle
|
|
2157
|
+
}
|
|
2158
|
+
return uniffiObj.recordOutcome(
|
|
2159
|
+
toolName: try FfiConverterString.lift(toolName),
|
|
2160
|
+
paramsJson: try FfiConverterString.lift(paramsJson),
|
|
2161
|
+
result: try FfiConverterString.lift(result)
|
|
2162
|
+
)
|
|
2163
|
+
}
|
|
2164
|
+
|
|
2165
|
+
|
|
2166
|
+
let writeReturn = { uniffiOutReturn.pointee = FfiConverterOptionString.lower($0) }
|
|
2167
|
+
uniffiTraitInterfaceCall(
|
|
2168
|
+
callStatus: uniffiCallStatus,
|
|
2169
|
+
makeCall: makeCall,
|
|
2170
|
+
writeReturn: writeReturn
|
|
2171
|
+
)
|
|
2172
|
+
},
|
|
2173
|
+
recordAudit: { (
|
|
2174
|
+
uniffiHandle: UInt64,
|
|
2175
|
+
agentId: RustBuffer,
|
|
2176
|
+
action: RustBuffer,
|
|
2177
|
+
detail: RustBuffer,
|
|
2178
|
+
outcome: RustBuffer,
|
|
2179
|
+
uniffiOutReturn: UnsafeMutableRawPointer,
|
|
2180
|
+
uniffiCallStatus: UnsafeMutablePointer<RustCallStatus>
|
|
2181
|
+
) in
|
|
2182
|
+
let makeCall = {
|
|
2183
|
+
() throws -> () in
|
|
2184
|
+
guard let uniffiObj = try? FfiConverterCallbackInterfaceGovernanceProvider.handleMap.get(handle: uniffiHandle) else {
|
|
2185
|
+
throw UniffiInternalError.unexpectedStaleHandle
|
|
2186
|
+
}
|
|
2187
|
+
return uniffiObj.recordAudit(
|
|
2188
|
+
agentId: try FfiConverterString.lift(agentId),
|
|
2189
|
+
action: try FfiConverterString.lift(action),
|
|
2190
|
+
detail: try FfiConverterString.lift(detail),
|
|
2191
|
+
outcome: try FfiConverterString.lift(outcome)
|
|
2192
|
+
)
|
|
2193
|
+
}
|
|
2194
|
+
|
|
2195
|
+
|
|
2196
|
+
let writeReturn = { () }
|
|
2197
|
+
uniffiTraitInterfaceCall(
|
|
2198
|
+
callStatus: uniffiCallStatus,
|
|
2199
|
+
makeCall: makeCall,
|
|
2200
|
+
writeReturn: writeReturn
|
|
2201
|
+
)
|
|
2202
|
+
},
|
|
2203
|
+
checkSink: { (
|
|
2204
|
+
uniffiHandle: UInt64,
|
|
2205
|
+
sinkType: RustBuffer,
|
|
2206
|
+
content: RustBuffer,
|
|
2207
|
+
uniffiOutReturn: UnsafeMutablePointer<RustBuffer>,
|
|
2208
|
+
uniffiCallStatus: UnsafeMutablePointer<RustCallStatus>
|
|
2209
|
+
) in
|
|
2210
|
+
let makeCall = {
|
|
2211
|
+
() throws -> String in
|
|
2212
|
+
guard let uniffiObj = try? FfiConverterCallbackInterfaceGovernanceProvider.handleMap.get(handle: uniffiHandle) else {
|
|
2213
|
+
throw UniffiInternalError.unexpectedStaleHandle
|
|
2214
|
+
}
|
|
2215
|
+
return uniffiObj.checkSink(
|
|
2216
|
+
sinkType: try FfiConverterString.lift(sinkType),
|
|
2217
|
+
content: try FfiConverterString.lift(content)
|
|
2218
|
+
)
|
|
2219
|
+
}
|
|
2220
|
+
|
|
2221
|
+
|
|
2222
|
+
let writeReturn = { uniffiOutReturn.pointee = FfiConverterString.lower($0) }
|
|
2223
|
+
uniffiTraitInterfaceCall(
|
|
2224
|
+
callStatus: uniffiCallStatus,
|
|
2225
|
+
makeCall: makeCall,
|
|
2226
|
+
writeReturn: writeReturn
|
|
2227
|
+
)
|
|
2228
|
+
},
|
|
2229
|
+
reset: { (
|
|
2230
|
+
uniffiHandle: UInt64,
|
|
2231
|
+
uniffiOutReturn: UnsafeMutableRawPointer,
|
|
2232
|
+
uniffiCallStatus: UnsafeMutablePointer<RustCallStatus>
|
|
2233
|
+
) in
|
|
2234
|
+
let makeCall = {
|
|
2235
|
+
() throws -> () in
|
|
2236
|
+
guard let uniffiObj = try? FfiConverterCallbackInterfaceGovernanceProvider.handleMap.get(handle: uniffiHandle) else {
|
|
2237
|
+
throw UniffiInternalError.unexpectedStaleHandle
|
|
2238
|
+
}
|
|
2239
|
+
return uniffiObj.reset(
|
|
2240
|
+
)
|
|
2241
|
+
}
|
|
2242
|
+
|
|
2243
|
+
|
|
2244
|
+
let writeReturn = { () }
|
|
2245
|
+
uniffiTraitInterfaceCall(
|
|
2246
|
+
callStatus: uniffiCallStatus,
|
|
2247
|
+
makeCall: makeCall,
|
|
2248
|
+
writeReturn: writeReturn
|
|
2249
|
+
)
|
|
2250
|
+
},
|
|
2251
|
+
recordUsage: { (
|
|
2252
|
+
uniffiHandle: UInt64,
|
|
2253
|
+
modelId: RustBuffer,
|
|
2254
|
+
inputTokens: UInt32,
|
|
2255
|
+
outputTokens: UInt32,
|
|
2256
|
+
uniffiOutReturn: UnsafeMutableRawPointer,
|
|
2257
|
+
uniffiCallStatus: UnsafeMutablePointer<RustCallStatus>
|
|
2258
|
+
) in
|
|
2259
|
+
let makeCall = {
|
|
2260
|
+
() throws -> () in
|
|
2261
|
+
guard let uniffiObj = try? FfiConverterCallbackInterfaceGovernanceProvider.handleMap.get(handle: uniffiHandle) else {
|
|
2262
|
+
throw UniffiInternalError.unexpectedStaleHandle
|
|
2263
|
+
}
|
|
2264
|
+
return uniffiObj.recordUsage(
|
|
2265
|
+
modelId: try FfiConverterString.lift(modelId),
|
|
2266
|
+
inputTokens: try FfiConverterUInt32.lift(inputTokens),
|
|
2267
|
+
outputTokens: try FfiConverterUInt32.lift(outputTokens)
|
|
2268
|
+
)
|
|
2269
|
+
}
|
|
2270
|
+
|
|
2271
|
+
|
|
2272
|
+
let writeReturn = { () }
|
|
2273
|
+
uniffiTraitInterfaceCall(
|
|
2274
|
+
callStatus: uniffiCallStatus,
|
|
2275
|
+
makeCall: makeCall,
|
|
2276
|
+
writeReturn: writeReturn
|
|
2277
|
+
)
|
|
2278
|
+
},
|
|
2279
|
+
uniffiFree: { (uniffiHandle: UInt64) -> () in
|
|
2280
|
+
let result = try? FfiConverterCallbackInterfaceGovernanceProvider.handleMap.remove(handle: uniffiHandle)
|
|
2281
|
+
if result == nil {
|
|
2282
|
+
print("Uniffi callback interface GovernanceProvider: handle missing in uniffiFree")
|
|
2283
|
+
}
|
|
2284
|
+
}
|
|
2285
|
+
)
|
|
2286
|
+
}
|
|
2287
|
+
|
|
2288
|
+
private func uniffiCallbackInitGovernanceProvider() {
|
|
2289
|
+
uniffi_native_agent_ffi_fn_init_callback_vtable_governanceprovider(&UniffiCallbackInterfaceGovernanceProvider.vtable)
|
|
2290
|
+
}
|
|
2291
|
+
|
|
2292
|
+
// FfiConverter protocol for callback interfaces
|
|
2293
|
+
#if swift(>=5.8)
|
|
2294
|
+
@_documentation(visibility: private)
|
|
2295
|
+
#endif
|
|
2296
|
+
fileprivate struct FfiConverterCallbackInterfaceGovernanceProvider {
|
|
2297
|
+
fileprivate static var handleMap = UniffiHandleMap<GovernanceProvider>()
|
|
2298
|
+
}
|
|
2299
|
+
|
|
2300
|
+
#if swift(>=5.8)
|
|
2301
|
+
@_documentation(visibility: private)
|
|
2302
|
+
#endif
|
|
2303
|
+
extension FfiConverterCallbackInterfaceGovernanceProvider : FfiConverter {
|
|
2304
|
+
typealias SwiftType = GovernanceProvider
|
|
2305
|
+
typealias FfiType = UInt64
|
|
2306
|
+
|
|
2307
|
+
#if swift(>=5.8)
|
|
2308
|
+
@_documentation(visibility: private)
|
|
2309
|
+
#endif
|
|
2310
|
+
public static func lift(_ handle: UInt64) throws -> SwiftType {
|
|
2311
|
+
try handleMap.get(handle: handle)
|
|
2312
|
+
}
|
|
2313
|
+
|
|
2314
|
+
#if swift(>=5.8)
|
|
2315
|
+
@_documentation(visibility: private)
|
|
2316
|
+
#endif
|
|
2317
|
+
public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> SwiftType {
|
|
2318
|
+
let handle: UInt64 = try readInt(&buf)
|
|
2319
|
+
return try lift(handle)
|
|
2320
|
+
}
|
|
2321
|
+
|
|
2322
|
+
#if swift(>=5.8)
|
|
2323
|
+
@_documentation(visibility: private)
|
|
2324
|
+
#endif
|
|
2325
|
+
public static func lower(_ v: SwiftType) -> UInt64 {
|
|
2326
|
+
return handleMap.insert(obj: v)
|
|
2327
|
+
}
|
|
2328
|
+
|
|
2329
|
+
#if swift(>=5.8)
|
|
2330
|
+
@_documentation(visibility: private)
|
|
2331
|
+
#endif
|
|
2332
|
+
public static func write(_ v: SwiftType, into buf: inout [UInt8]) {
|
|
2333
|
+
writeInt(&buf, lower(v))
|
|
2334
|
+
}
|
|
2335
|
+
}
|
|
2336
|
+
|
|
2337
|
+
|
|
2338
|
+
|
|
2339
|
+
|
|
1998
2340
|
/**
|
|
1999
2341
|
* Callback interface for memory operations (LanceDB or any vector store).
|
|
2000
2342
|
* Implemented by Kotlin/Swift, which bridges to the actual memory backend.
|
|
@@ -2013,13 +2355,7 @@ public protocol MemoryProvider : AnyObject {
|
|
|
2013
2355
|
|
|
2014
2356
|
}
|
|
2015
2357
|
|
|
2016
|
-
|
|
2017
|
-
// to free the callback once it's dropped by Rust.
|
|
2018
|
-
private let IDX_CALLBACK_FREE: Int32 = 0
|
|
2019
|
-
// Callback return codes
|
|
2020
|
-
private let UNIFFI_CALLBACK_SUCCESS: Int32 = 0
|
|
2021
|
-
private let UNIFFI_CALLBACK_ERROR: Int32 = 1
|
|
2022
|
-
private let UNIFFI_CALLBACK_UNEXPECTED_ERROR: Int32 = 2
|
|
2358
|
+
|
|
2023
2359
|
|
|
2024
2360
|
// Put the implementation in a struct so we don't pollute the top-level namespace
|
|
2025
2361
|
fileprivate struct UniffiCallbackInterfaceMemoryProvider {
|
|
@@ -2454,6 +2790,30 @@ fileprivate struct FfiConverterOptionUInt32: FfiConverterRustBuffer {
|
|
|
2454
2790
|
}
|
|
2455
2791
|
}
|
|
2456
2792
|
|
|
2793
|
+
#if swift(>=5.8)
|
|
2794
|
+
@_documentation(visibility: private)
|
|
2795
|
+
#endif
|
|
2796
|
+
fileprivate struct FfiConverterOptionInt64: FfiConverterRustBuffer {
|
|
2797
|
+
typealias SwiftType = Int64?
|
|
2798
|
+
|
|
2799
|
+
public static func write(_ value: SwiftType, into buf: inout [UInt8]) {
|
|
2800
|
+
guard let value = value else {
|
|
2801
|
+
writeInt(&buf, Int8(0))
|
|
2802
|
+
return
|
|
2803
|
+
}
|
|
2804
|
+
writeInt(&buf, Int8(1))
|
|
2805
|
+
FfiConverterInt64.write(value, into: &buf)
|
|
2806
|
+
}
|
|
2807
|
+
|
|
2808
|
+
public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> SwiftType {
|
|
2809
|
+
switch try readInt(&buf) as Int8 {
|
|
2810
|
+
case 0: return nil
|
|
2811
|
+
case 1: return try FfiConverterInt64.read(from: &buf)
|
|
2812
|
+
default: throw UniffiInternalError.unexpectedOptionalTag
|
|
2813
|
+
}
|
|
2814
|
+
}
|
|
2815
|
+
}
|
|
2816
|
+
|
|
2457
2817
|
#if swift(>=5.8)
|
|
2458
2818
|
@_documentation(visibility: private)
|
|
2459
2819
|
#endif
|
|
@@ -2608,7 +2968,7 @@ private var initializationResult: InitializationResult = {
|
|
|
2608
2968
|
if (uniffi_native_agent_ffi_checksum_method_nativeagenthandle_restart_mcp() != 8963) {
|
|
2609
2969
|
return InitializationResult.apiChecksumMismatch
|
|
2610
2970
|
}
|
|
2611
|
-
if (uniffi_native_agent_ffi_checksum_method_nativeagenthandle_resume_session() !=
|
|
2971
|
+
if (uniffi_native_agent_ffi_checksum_method_nativeagenthandle_resume_session() != 1498) {
|
|
2612
2972
|
return InitializationResult.apiChecksumMismatch
|
|
2613
2973
|
}
|
|
2614
2974
|
if (uniffi_native_agent_ffi_checksum_method_nativeagenthandle_run_cron_job() != 11263) {
|
|
@@ -2620,12 +2980,15 @@ private var initializationResult: InitializationResult = {
|
|
|
2620
2980
|
if (uniffi_native_agent_ffi_checksum_method_nativeagenthandle_send_message() != 53296) {
|
|
2621
2981
|
return InitializationResult.apiChecksumMismatch
|
|
2622
2982
|
}
|
|
2623
|
-
if (uniffi_native_agent_ffi_checksum_method_nativeagenthandle_set_auth_key() !=
|
|
2983
|
+
if (uniffi_native_agent_ffi_checksum_method_nativeagenthandle_set_auth_key() != 1639) {
|
|
2624
2984
|
return InitializationResult.apiChecksumMismatch
|
|
2625
2985
|
}
|
|
2626
2986
|
if (uniffi_native_agent_ffi_checksum_method_nativeagenthandle_set_event_callback() != 56165) {
|
|
2627
2987
|
return InitializationResult.apiChecksumMismatch
|
|
2628
2988
|
}
|
|
2989
|
+
if (uniffi_native_agent_ffi_checksum_method_nativeagenthandle_set_governance_provider() != 45093) {
|
|
2990
|
+
return InitializationResult.apiChecksumMismatch
|
|
2991
|
+
}
|
|
2629
2992
|
if (uniffi_native_agent_ffi_checksum_method_nativeagenthandle_set_heartbeat_config() != 33968) {
|
|
2630
2993
|
return InitializationResult.apiChecksumMismatch
|
|
2631
2994
|
}
|
|
@@ -2659,6 +3022,24 @@ private var initializationResult: InitializationResult = {
|
|
|
2659
3022
|
if (uniffi_native_agent_ffi_checksum_constructor_nativeagenthandle_new() != 18383) {
|
|
2660
3023
|
return InitializationResult.apiChecksumMismatch
|
|
2661
3024
|
}
|
|
3025
|
+
if (uniffi_native_agent_ffi_checksum_method_governanceprovider_check_loop() != 64194) {
|
|
3026
|
+
return InitializationResult.apiChecksumMismatch
|
|
3027
|
+
}
|
|
3028
|
+
if (uniffi_native_agent_ffi_checksum_method_governanceprovider_record_outcome() != 15801) {
|
|
3029
|
+
return InitializationResult.apiChecksumMismatch
|
|
3030
|
+
}
|
|
3031
|
+
if (uniffi_native_agent_ffi_checksum_method_governanceprovider_record_audit() != 34049) {
|
|
3032
|
+
return InitializationResult.apiChecksumMismatch
|
|
3033
|
+
}
|
|
3034
|
+
if (uniffi_native_agent_ffi_checksum_method_governanceprovider_check_sink() != 37338) {
|
|
3035
|
+
return InitializationResult.apiChecksumMismatch
|
|
3036
|
+
}
|
|
3037
|
+
if (uniffi_native_agent_ffi_checksum_method_governanceprovider_reset() != 57214) {
|
|
3038
|
+
return InitializationResult.apiChecksumMismatch
|
|
3039
|
+
}
|
|
3040
|
+
if (uniffi_native_agent_ffi_checksum_method_governanceprovider_record_usage() != 907) {
|
|
3041
|
+
return InitializationResult.apiChecksumMismatch
|
|
3042
|
+
}
|
|
2662
3043
|
if (uniffi_native_agent_ffi_checksum_method_memoryprovider_store() != 49136) {
|
|
2663
3044
|
return InitializationResult.apiChecksumMismatch
|
|
2664
3045
|
}
|
|
@@ -2681,6 +3062,7 @@ private var initializationResult: InitializationResult = {
|
|
|
2681
3062
|
return InitializationResult.apiChecksumMismatch
|
|
2682
3063
|
}
|
|
2683
3064
|
|
|
3065
|
+
uniffiCallbackInitGovernanceProvider()
|
|
2684
3066
|
uniffiCallbackInitMemoryProvider()
|
|
2685
3067
|
uniffiCallbackInitNativeEventCallback()
|
|
2686
3068
|
uniffiCallbackInitNativeNotifier()
|