capacitor-native-agent 0.3.6 → 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.
@@ -0,0 +1,2594 @@
1
+ // This file was autogenerated by some hot garbage in the `uniffi` crate.
2
+ // Trust me, you don't want to mess with it!
3
+
4
+ // swiftlint:disable all
5
+ import Foundation
6
+
7
+ // Depending on the consumer's build setup, the low-level FFI code
8
+ // might be in a separate module, or it might be compiled inline into
9
+ // this module. This is a bit of light hackery to work with both.
10
+ #if canImport(native_agent_ffiFFI)
11
+ import native_agent_ffiFFI
12
+ #endif
13
+
14
+ fileprivate extension RustBuffer {
15
+ // Allocate a new buffer, copying the contents of a `UInt8` array.
16
+ init(bytes: [UInt8]) {
17
+ let rbuf = bytes.withUnsafeBufferPointer { ptr in
18
+ RustBuffer.from(ptr)
19
+ }
20
+ self.init(capacity: rbuf.capacity, len: rbuf.len, data: rbuf.data)
21
+ }
22
+
23
+ static func empty() -> RustBuffer {
24
+ RustBuffer(capacity: 0, len:0, data: nil)
25
+ }
26
+
27
+ static func from(_ ptr: UnsafeBufferPointer<UInt8>) -> RustBuffer {
28
+ try! rustCall { ffi_native_agent_ffi_rustbuffer_from_bytes(ForeignBytes(bufferPointer: ptr), $0) }
29
+ }
30
+
31
+ // Frees the buffer in place.
32
+ // The buffer must not be used after this is called.
33
+ func deallocate() {
34
+ try! rustCall { ffi_native_agent_ffi_rustbuffer_free(self, $0) }
35
+ }
36
+ }
37
+
38
+ fileprivate extension ForeignBytes {
39
+ init(bufferPointer: UnsafeBufferPointer<UInt8>) {
40
+ self.init(len: Int32(bufferPointer.count), data: bufferPointer.baseAddress)
41
+ }
42
+ }
43
+
44
+ // For every type used in the interface, we provide helper methods for conveniently
45
+ // lifting and lowering that type from C-compatible data, and for reading and writing
46
+ // values of that type in a buffer.
47
+
48
+ // Helper classes/extensions that don't change.
49
+ // Someday, this will be in a library of its own.
50
+
51
+ fileprivate extension Data {
52
+ init(rustBuffer: RustBuffer) {
53
+ self.init(
54
+ bytesNoCopy: rustBuffer.data!,
55
+ count: Int(rustBuffer.len),
56
+ deallocator: .none
57
+ )
58
+ }
59
+ }
60
+
61
+ // Define reader functionality. Normally this would be defined in a class or
62
+ // struct, but we use standalone functions instead in order to make external
63
+ // types work.
64
+ //
65
+ // With external types, one swift source file needs to be able to call the read
66
+ // method on another source file's FfiConverter, but then what visibility
67
+ // should Reader have?
68
+ // - If Reader is fileprivate, then this means the read() must also
69
+ // be fileprivate, which doesn't work with external types.
70
+ // - If Reader is internal/public, we'll get compile errors since both source
71
+ // files will try define the same type.
72
+ //
73
+ // Instead, the read() method and these helper functions input a tuple of data
74
+
75
+ fileprivate func createReader(data: Data) -> (data: Data, offset: Data.Index) {
76
+ (data: data, offset: 0)
77
+ }
78
+
79
+ // Reads an integer at the current offset, in big-endian order, and advances
80
+ // the offset on success. Throws if reading the integer would move the
81
+ // offset past the end of the buffer.
82
+ fileprivate func readInt<T: FixedWidthInteger>(_ reader: inout (data: Data, offset: Data.Index)) throws -> T {
83
+ let range = reader.offset..<reader.offset + MemoryLayout<T>.size
84
+ guard reader.data.count >= range.upperBound else {
85
+ throw UniffiInternalError.bufferOverflow
86
+ }
87
+ if T.self == UInt8.self {
88
+ let value = reader.data[reader.offset]
89
+ reader.offset += 1
90
+ return value as! T
91
+ }
92
+ var value: T = 0
93
+ let _ = withUnsafeMutableBytes(of: &value, { reader.data.copyBytes(to: $0, from: range)})
94
+ reader.offset = range.upperBound
95
+ return value.bigEndian
96
+ }
97
+
98
+ // Reads an arbitrary number of bytes, to be used to read
99
+ // raw bytes, this is useful when lifting strings
100
+ fileprivate func readBytes(_ reader: inout (data: Data, offset: Data.Index), count: Int) throws -> Array<UInt8> {
101
+ let range = reader.offset..<(reader.offset+count)
102
+ guard reader.data.count >= range.upperBound else {
103
+ throw UniffiInternalError.bufferOverflow
104
+ }
105
+ var value = [UInt8](repeating: 0, count: count)
106
+ value.withUnsafeMutableBufferPointer({ buffer in
107
+ reader.data.copyBytes(to: buffer, from: range)
108
+ })
109
+ reader.offset = range.upperBound
110
+ return value
111
+ }
112
+
113
+ // Reads a float at the current offset.
114
+ fileprivate func readFloat(_ reader: inout (data: Data, offset: Data.Index)) throws -> Float {
115
+ return Float(bitPattern: try readInt(&reader))
116
+ }
117
+
118
+ // Reads a float at the current offset.
119
+ fileprivate func readDouble(_ reader: inout (data: Data, offset: Data.Index)) throws -> Double {
120
+ return Double(bitPattern: try readInt(&reader))
121
+ }
122
+
123
+ // Indicates if the offset has reached the end of the buffer.
124
+ fileprivate func hasRemaining(_ reader: (data: Data, offset: Data.Index)) -> Bool {
125
+ return reader.offset < reader.data.count
126
+ }
127
+
128
+ // Define writer functionality. Normally this would be defined in a class or
129
+ // struct, but we use standalone functions instead in order to make external
130
+ // types work. See the above discussion on Readers for details.
131
+
132
+ fileprivate func createWriter() -> [UInt8] {
133
+ return []
134
+ }
135
+
136
+ fileprivate func writeBytes<S>(_ writer: inout [UInt8], _ byteArr: S) where S: Sequence, S.Element == UInt8 {
137
+ writer.append(contentsOf: byteArr)
138
+ }
139
+
140
+ // Writes an integer in big-endian order.
141
+ //
142
+ // Warning: make sure what you are trying to write
143
+ // is in the correct type!
144
+ fileprivate func writeInt<T: FixedWidthInteger>(_ writer: inout [UInt8], _ value: T) {
145
+ var value = value.bigEndian
146
+ withUnsafeBytes(of: &value) { writer.append(contentsOf: $0) }
147
+ }
148
+
149
+ fileprivate func writeFloat(_ writer: inout [UInt8], _ value: Float) {
150
+ writeInt(&writer, value.bitPattern)
151
+ }
152
+
153
+ fileprivate func writeDouble(_ writer: inout [UInt8], _ value: Double) {
154
+ writeInt(&writer, value.bitPattern)
155
+ }
156
+
157
+ // Protocol for types that transfer other types across the FFI. This is
158
+ // analogous to the Rust trait of the same name.
159
+ fileprivate protocol FfiConverter {
160
+ associatedtype FfiType
161
+ associatedtype SwiftType
162
+
163
+ static func lift(_ value: FfiType) throws -> SwiftType
164
+ static func lower(_ value: SwiftType) -> FfiType
165
+ static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> SwiftType
166
+ static func write(_ value: SwiftType, into buf: inout [UInt8])
167
+ }
168
+
169
+ // Types conforming to `Primitive` pass themselves directly over the FFI.
170
+ fileprivate protocol FfiConverterPrimitive: FfiConverter where FfiType == SwiftType { }
171
+
172
+ extension FfiConverterPrimitive {
173
+ #if swift(>=5.8)
174
+ @_documentation(visibility: private)
175
+ #endif
176
+ public static func lift(_ value: FfiType) throws -> SwiftType {
177
+ return value
178
+ }
179
+
180
+ #if swift(>=5.8)
181
+ @_documentation(visibility: private)
182
+ #endif
183
+ public static func lower(_ value: SwiftType) -> FfiType {
184
+ return value
185
+ }
186
+ }
187
+
188
+ // Types conforming to `FfiConverterRustBuffer` lift and lower into a `RustBuffer`.
189
+ // Used for complex types where it's hard to write a custom lift/lower.
190
+ fileprivate protocol FfiConverterRustBuffer: FfiConverter where FfiType == RustBuffer {}
191
+
192
+ extension FfiConverterRustBuffer {
193
+ #if swift(>=5.8)
194
+ @_documentation(visibility: private)
195
+ #endif
196
+ public static func lift(_ buf: RustBuffer) throws -> SwiftType {
197
+ var reader = createReader(data: Data(rustBuffer: buf))
198
+ let value = try read(from: &reader)
199
+ if hasRemaining(reader) {
200
+ throw UniffiInternalError.incompleteData
201
+ }
202
+ buf.deallocate()
203
+ return value
204
+ }
205
+
206
+ #if swift(>=5.8)
207
+ @_documentation(visibility: private)
208
+ #endif
209
+ public static func lower(_ value: SwiftType) -> RustBuffer {
210
+ var writer = createWriter()
211
+ write(value, into: &writer)
212
+ return RustBuffer(bytes: writer)
213
+ }
214
+ }
215
+ // An error type for FFI errors. These errors occur at the UniFFI level, not
216
+ // the library level.
217
+ fileprivate enum UniffiInternalError: LocalizedError {
218
+ case bufferOverflow
219
+ case incompleteData
220
+ case unexpectedOptionalTag
221
+ case unexpectedEnumCase
222
+ case unexpectedNullPointer
223
+ case unexpectedRustCallStatusCode
224
+ case unexpectedRustCallError
225
+ case unexpectedStaleHandle
226
+ case rustPanic(_ message: String)
227
+
228
+ public var errorDescription: String? {
229
+ switch self {
230
+ case .bufferOverflow: return "Reading the requested value would read past the end of the buffer"
231
+ case .incompleteData: return "The buffer still has data after lifting its containing value"
232
+ case .unexpectedOptionalTag: return "Unexpected optional tag; should be 0 or 1"
233
+ case .unexpectedEnumCase: return "Raw enum value doesn't match any cases"
234
+ case .unexpectedNullPointer: return "Raw pointer value was null"
235
+ case .unexpectedRustCallStatusCode: return "Unexpected RustCallStatus code"
236
+ case .unexpectedRustCallError: return "CALL_ERROR but no errorClass specified"
237
+ case .unexpectedStaleHandle: return "The object in the handle map has been dropped already"
238
+ case let .rustPanic(message): return message
239
+ }
240
+ }
241
+ }
242
+
243
+ fileprivate extension NSLock {
244
+ func withLock<T>(f: () throws -> T) rethrows -> T {
245
+ self.lock()
246
+ defer { self.unlock() }
247
+ return try f()
248
+ }
249
+ }
250
+
251
+ fileprivate let CALL_SUCCESS: Int8 = 0
252
+ fileprivate let CALL_ERROR: Int8 = 1
253
+ fileprivate let CALL_UNEXPECTED_ERROR: Int8 = 2
254
+ fileprivate let CALL_CANCELLED: Int8 = 3
255
+
256
+ fileprivate extension RustCallStatus {
257
+ init() {
258
+ self.init(
259
+ code: CALL_SUCCESS,
260
+ errorBuf: RustBuffer.init(
261
+ capacity: 0,
262
+ len: 0,
263
+ data: nil
264
+ )
265
+ )
266
+ }
267
+ }
268
+
269
+ private func rustCall<T>(_ callback: (UnsafeMutablePointer<RustCallStatus>) -> T) throws -> T {
270
+ let neverThrow: ((RustBuffer) throws -> Never)? = nil
271
+ return try makeRustCall(callback, errorHandler: neverThrow)
272
+ }
273
+
274
+ private func rustCallWithError<T, E: Swift.Error>(
275
+ _ errorHandler: @escaping (RustBuffer) throws -> E,
276
+ _ callback: (UnsafeMutablePointer<RustCallStatus>) -> T) throws -> T {
277
+ try makeRustCall(callback, errorHandler: errorHandler)
278
+ }
279
+
280
+ private func makeRustCall<T, E: Swift.Error>(
281
+ _ callback: (UnsafeMutablePointer<RustCallStatus>) -> T,
282
+ errorHandler: ((RustBuffer) throws -> E)?
283
+ ) throws -> T {
284
+ uniffiEnsureInitialized()
285
+ var callStatus = RustCallStatus.init()
286
+ let returnedVal = callback(&callStatus)
287
+ try uniffiCheckCallStatus(callStatus: callStatus, errorHandler: errorHandler)
288
+ return returnedVal
289
+ }
290
+
291
+ private func uniffiCheckCallStatus<E: Swift.Error>(
292
+ callStatus: RustCallStatus,
293
+ errorHandler: ((RustBuffer) throws -> E)?
294
+ ) throws {
295
+ switch callStatus.code {
296
+ case CALL_SUCCESS:
297
+ return
298
+
299
+ case CALL_ERROR:
300
+ if let errorHandler = errorHandler {
301
+ throw try errorHandler(callStatus.errorBuf)
302
+ } else {
303
+ callStatus.errorBuf.deallocate()
304
+ throw UniffiInternalError.unexpectedRustCallError
305
+ }
306
+
307
+ case CALL_UNEXPECTED_ERROR:
308
+ // When the rust code sees a panic, it tries to construct a RustBuffer
309
+ // with the message. But if that code panics, then it just sends back
310
+ // an empty buffer.
311
+ if callStatus.errorBuf.len > 0 {
312
+ throw UniffiInternalError.rustPanic(try FfiConverterString.lift(callStatus.errorBuf))
313
+ } else {
314
+ callStatus.errorBuf.deallocate()
315
+ throw UniffiInternalError.rustPanic("Rust panic")
316
+ }
317
+
318
+ case CALL_CANCELLED:
319
+ fatalError("Cancellation not supported yet")
320
+
321
+ default:
322
+ throw UniffiInternalError.unexpectedRustCallStatusCode
323
+ }
324
+ }
325
+
326
+ private func uniffiTraitInterfaceCall<T>(
327
+ callStatus: UnsafeMutablePointer<RustCallStatus>,
328
+ makeCall: () throws -> T,
329
+ writeReturn: (T) -> ()
330
+ ) {
331
+ do {
332
+ try writeReturn(makeCall())
333
+ } catch let error {
334
+ callStatus.pointee.code = CALL_UNEXPECTED_ERROR
335
+ callStatus.pointee.errorBuf = FfiConverterString.lower(String(describing: error))
336
+ }
337
+ }
338
+
339
+ private func uniffiTraitInterfaceCallWithError<T, E>(
340
+ callStatus: UnsafeMutablePointer<RustCallStatus>,
341
+ makeCall: () throws -> T,
342
+ writeReturn: (T) -> (),
343
+ lowerError: (E) -> RustBuffer
344
+ ) {
345
+ do {
346
+ try writeReturn(makeCall())
347
+ } catch let error as E {
348
+ callStatus.pointee.code = CALL_ERROR
349
+ callStatus.pointee.errorBuf = lowerError(error)
350
+ } catch {
351
+ callStatus.pointee.code = CALL_UNEXPECTED_ERROR
352
+ callStatus.pointee.errorBuf = FfiConverterString.lower(String(describing: error))
353
+ }
354
+ }
355
+ fileprivate class UniffiHandleMap<T> {
356
+ private var map: [UInt64: T] = [:]
357
+ private let lock = NSLock()
358
+ private var currentHandle: UInt64 = 1
359
+
360
+ func insert(obj: T) -> UInt64 {
361
+ lock.withLock {
362
+ let handle = currentHandle
363
+ currentHandle += 1
364
+ map[handle] = obj
365
+ return handle
366
+ }
367
+ }
368
+
369
+ func get(handle: UInt64) throws -> T {
370
+ try lock.withLock {
371
+ guard let obj = map[handle] else {
372
+ throw UniffiInternalError.unexpectedStaleHandle
373
+ }
374
+ return obj
375
+ }
376
+ }
377
+
378
+ @discardableResult
379
+ func remove(handle: UInt64) throws -> T {
380
+ try lock.withLock {
381
+ guard let obj = map.removeValue(forKey: handle) else {
382
+ throw UniffiInternalError.unexpectedStaleHandle
383
+ }
384
+ return obj
385
+ }
386
+ }
387
+
388
+ var count: Int {
389
+ get {
390
+ map.count
391
+ }
392
+ }
393
+ }
394
+
395
+
396
+ // Public interface members begin here.
397
+
398
+
399
+ #if swift(>=5.8)
400
+ @_documentation(visibility: private)
401
+ #endif
402
+ fileprivate struct FfiConverterUInt32: FfiConverterPrimitive {
403
+ typealias FfiType = UInt32
404
+ typealias SwiftType = UInt32
405
+
406
+ public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> UInt32 {
407
+ return try lift(readInt(&buf))
408
+ }
409
+
410
+ public static func write(_ value: SwiftType, into buf: inout [UInt8]) {
411
+ writeInt(&buf, lower(value))
412
+ }
413
+ }
414
+
415
+ #if swift(>=5.8)
416
+ @_documentation(visibility: private)
417
+ #endif
418
+ fileprivate struct FfiConverterInt64: FfiConverterPrimitive {
419
+ typealias FfiType = Int64
420
+ typealias SwiftType = Int64
421
+
422
+ public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> Int64 {
423
+ return try lift(readInt(&buf))
424
+ }
425
+
426
+ public static func write(_ value: Int64, into buf: inout [UInt8]) {
427
+ writeInt(&buf, lower(value))
428
+ }
429
+ }
430
+
431
+ #if swift(>=5.8)
432
+ @_documentation(visibility: private)
433
+ #endif
434
+ fileprivate struct FfiConverterBool : FfiConverter {
435
+ typealias FfiType = Int8
436
+ typealias SwiftType = Bool
437
+
438
+ public static func lift(_ value: Int8) throws -> Bool {
439
+ return value != 0
440
+ }
441
+
442
+ public static func lower(_ value: Bool) -> Int8 {
443
+ return value ? 1 : 0
444
+ }
445
+
446
+ public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> Bool {
447
+ return try lift(readInt(&buf))
448
+ }
449
+
450
+ public static func write(_ value: Bool, into buf: inout [UInt8]) {
451
+ writeInt(&buf, lower(value))
452
+ }
453
+ }
454
+
455
+ #if swift(>=5.8)
456
+ @_documentation(visibility: private)
457
+ #endif
458
+ fileprivate struct FfiConverterString: FfiConverter {
459
+ typealias SwiftType = String
460
+ typealias FfiType = RustBuffer
461
+
462
+ public static func lift(_ value: RustBuffer) throws -> String {
463
+ defer {
464
+ value.deallocate()
465
+ }
466
+ if value.data == nil {
467
+ return String()
468
+ }
469
+ let bytes = UnsafeBufferPointer<UInt8>(start: value.data!, count: Int(value.len))
470
+ return String(bytes: bytes, encoding: String.Encoding.utf8)!
471
+ }
472
+
473
+ public static func lower(_ value: String) -> RustBuffer {
474
+ return value.utf8CString.withUnsafeBufferPointer { ptr in
475
+ // The swift string gives us int8_t, we want uint8_t.
476
+ ptr.withMemoryRebound(to: UInt8.self) { ptr in
477
+ // The swift string gives us a trailing null byte, we don't want it.
478
+ let buf = UnsafeBufferPointer(rebasing: ptr.prefix(upTo: ptr.count - 1))
479
+ return RustBuffer.from(buf)
480
+ }
481
+ }
482
+ }
483
+
484
+ public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> String {
485
+ let len: Int32 = try readInt(&buf)
486
+ return String(bytes: try readBytes(&buf, count: Int(len)), encoding: String.Encoding.utf8)!
487
+ }
488
+
489
+ public static func write(_ value: String, into buf: inout [UInt8]) {
490
+ let len = Int32(value.utf8.count)
491
+ writeInt(&buf, len)
492
+ writeBytes(&buf, value.utf8)
493
+ }
494
+ }
495
+
496
+
497
+
498
+
499
+ /**
500
+ * Long-lived handle — one per app lifecycle.
501
+ */
502
+ public protocol NativeAgentHandleProtocol : AnyObject {
503
+
504
+ /**
505
+ * Abort the current agent turn.
506
+ */
507
+ func abort() throws
508
+
509
+ /**
510
+ * Add a cron job.
511
+ */
512
+ func addCronJob(inputJson: String) throws -> String
513
+
514
+ /**
515
+ * Add a cron skill.
516
+ */
517
+ func addSkill(inputJson: String) throws -> String
518
+
519
+ /**
520
+ * Clear the current in-memory session state so the next sendMessage
521
+ * starts a fresh conversation. The session row in SQLite is preserved
522
+ * so it remains in the session index for later resume/switch.
523
+ */
524
+ func clearSession() throws
525
+
526
+ /**
527
+ * Delete auth for a provider.
528
+ */
529
+ func deleteAuth(provider: String) throws
530
+
531
+ /**
532
+ * End a skill session.
533
+ */
534
+ func endSkill(skillId: String) throws
535
+
536
+ /**
537
+ * Exchange an OAuth authorization code for tokens.
538
+ */
539
+ func exchangeOauthCode(tokenUrl: String, bodyJson: String, contentType: String?) throws -> String
540
+
541
+ /**
542
+ * Follow up on the current conversation.
543
+ */
544
+ func followUp(prompt: String) throws
545
+
546
+ /**
547
+ * Get auth status (masked key).
548
+ */
549
+ func getAuthStatus(provider: String) throws -> AuthStatusResult
550
+
551
+ /**
552
+ * Get auth token for a provider.
553
+ */
554
+ func getAuthToken(provider: String) throws -> AuthTokenResult
555
+
556
+ /**
557
+ * Get heartbeat config.
558
+ */
559
+ func getHeartbeatConfig() throws -> String
560
+
561
+ /**
562
+ * Get available models for a provider.
563
+ */
564
+ func getModels(provider: String) throws -> String
565
+
566
+ /**
567
+ * Get scheduler config.
568
+ */
569
+ func getSchedulerConfig() throws -> String
570
+
571
+ /**
572
+ * Handle a wake event (evaluate due cron jobs).
573
+ */
574
+ func handleWake(source: String) throws
575
+
576
+ /**
577
+ * Invoke a tool directly.
578
+ */
579
+ func invokeTool(toolName: String, argsJson: String) throws -> String
580
+
581
+ /**
582
+ * List all cron jobs.
583
+ */
584
+ func listCronJobs() throws -> String
585
+
586
+ /**
587
+ * List cron run history.
588
+ */
589
+ func listCronRuns(jobId: String?, limit: Int64) throws -> String
590
+
591
+ /**
592
+ * List sessions for an agent.
593
+ */
594
+ func listSessions(agentId: String) throws -> String
595
+
596
+ /**
597
+ * List all cron skills.
598
+ */
599
+ func listSkills() throws -> String
600
+
601
+ /**
602
+ * Load session message history.
603
+ */
604
+ func loadSession(sessionKey: String) throws -> String
605
+
606
+ func persistConfig() throws
607
+
608
+ /**
609
+ * Refresh an OAuth token.
610
+ */
611
+ func refreshToken(provider: String) throws -> AuthTokenResult
612
+
613
+ /**
614
+ * Remove a cron job.
615
+ */
616
+ func removeCronJob(id: String) throws
617
+
618
+ /**
619
+ * Remove a cron skill.
620
+ */
621
+ func removeSkill(id: String) throws
622
+
623
+ /**
624
+ * Respond to a tool approval request.
625
+ */
626
+ func respondToApproval(toolCallId: String, approved: Bool, reason: String?) throws
627
+
628
+ /**
629
+ * Respond to a cron approval request.
630
+ */
631
+ func respondToCronApproval(requestId: String, approved: Bool) throws
632
+
633
+ /**
634
+ * Respond to a pending MCP tool call.
635
+ */
636
+ func respondToMcpTool(toolCallId: String, resultJson: String, isError: Bool) throws
637
+
638
+ /**
639
+ * Restart MCP server with new tools.
640
+ */
641
+ func restartMcp(toolsJson: String) throws -> UInt32
642
+
643
+ /**
644
+ * Resume a session (load messages into agent context).
645
+ */
646
+ func resumeSession(sessionKey: String, agentId: String, messagesJson: String?, provider: String?, model: String?) throws
647
+
648
+ /**
649
+ * Force-trigger a cron job.
650
+ */
651
+ func runCronJob(jobId: String) throws
652
+
653
+ /**
654
+ * Send a message to the agent and start an agent loop turn.
655
+ */
656
+ func sendMessage(params: SendMessageParams) throws -> String
657
+
658
+ /**
659
+ * Set an auth key for a provider.
660
+ */
661
+ func setAuthKey(key: String, provider: String, authType: String) throws
662
+
663
+ /**
664
+ * Set the event callback for receiving agent events.
665
+ */
666
+ func setEventCallback(callback: NativeEventCallback) throws
667
+
668
+ /**
669
+ * Set heartbeat config.
670
+ */
671
+ func setHeartbeatConfig(configJson: String) throws
672
+
673
+ func setMemoryProvider(provider: MemoryProvider) throws
674
+
675
+ func setNotifier(notifier: NativeNotifier) throws
676
+
677
+ /**
678
+ * Set scheduler config.
679
+ */
680
+ func setSchedulerConfig(configJson: String) throws
681
+
682
+ /**
683
+ * Start MCP server with given tools.
684
+ */
685
+ func startMcp(toolsJson: String) throws -> UInt32
686
+
687
+ /**
688
+ * Start a skill session.
689
+ */
690
+ func startSkill(skillId: String, configJson: String, provider: String?) throws -> String
691
+
692
+ /**
693
+ * Steer the running agent with additional context.
694
+ */
695
+ func steer(text: String) throws
696
+
697
+ /**
698
+ * Update a cron job.
699
+ */
700
+ func updateCronJob(id: String, patchJson: String) throws
701
+
702
+ /**
703
+ * Update a cron skill.
704
+ */
705
+ func updateSkill(id: String, patchJson: String) throws
706
+
707
+ }
708
+
709
+ /**
710
+ * Long-lived handle — one per app lifecycle.
711
+ */
712
+ open class NativeAgentHandle:
713
+ NativeAgentHandleProtocol {
714
+ fileprivate let pointer: UnsafeMutableRawPointer!
715
+
716
+ /// Used to instantiate a [FFIObject] without an actual pointer, for fakes in tests, mostly.
717
+ #if swift(>=5.8)
718
+ @_documentation(visibility: private)
719
+ #endif
720
+ public struct NoPointer {
721
+ public init() {}
722
+ }
723
+
724
+ // TODO: We'd like this to be `private` but for Swifty reasons,
725
+ // we can't implement `FfiConverter` without making this `required` and we can't
726
+ // make it `required` without making it `public`.
727
+ required public init(unsafeFromRawPointer pointer: UnsafeMutableRawPointer) {
728
+ self.pointer = pointer
729
+ }
730
+
731
+ // This constructor can be used to instantiate a fake object.
732
+ // - Parameter noPointer: Placeholder value so we can have a constructor separate from the default empty one that may be implemented for classes extending [FFIObject].
733
+ //
734
+ // - Warning:
735
+ // Any object instantiated with this constructor cannot be passed to an actual Rust-backed object. Since there isn't a backing [Pointer] the FFI lower functions will crash.
736
+ #if swift(>=5.8)
737
+ @_documentation(visibility: private)
738
+ #endif
739
+ public init(noPointer: NoPointer) {
740
+ self.pointer = nil
741
+ }
742
+
743
+ #if swift(>=5.8)
744
+ @_documentation(visibility: private)
745
+ #endif
746
+ public func uniffiClonePointer() -> UnsafeMutableRawPointer {
747
+ return try! rustCall { uniffi_native_agent_ffi_fn_clone_nativeagenthandle(self.pointer, $0) }
748
+ }
749
+ /**
750
+ * Create a new native agent handle.
751
+ */
752
+ public convenience init(config: InitConfig)throws {
753
+ let pointer =
754
+ try rustCallWithError(FfiConverterTypeNativeAgentError.lift) {
755
+ uniffi_native_agent_ffi_fn_constructor_nativeagenthandle_new(
756
+ FfiConverterTypeInitConfig.lower(config),$0
757
+ )
758
+ }
759
+ self.init(unsafeFromRawPointer: pointer)
760
+ }
761
+
762
+ deinit {
763
+ guard let pointer = pointer else {
764
+ return
765
+ }
766
+
767
+ try! rustCall { uniffi_native_agent_ffi_fn_free_nativeagenthandle(pointer, $0) }
768
+ }
769
+
770
+
771
+
772
+
773
+ /**
774
+ * Abort the current agent turn.
775
+ */
776
+ open func abort()throws {try rustCallWithError(FfiConverterTypeNativeAgentError.lift) {
777
+ uniffi_native_agent_ffi_fn_method_nativeagenthandle_abort(self.uniffiClonePointer(),$0
778
+ )
779
+ }
780
+ }
781
+
782
+ /**
783
+ * Add a cron job.
784
+ */
785
+ open func addCronJob(inputJson: String)throws -> String {
786
+ return try FfiConverterString.lift(try rustCallWithError(FfiConverterTypeNativeAgentError.lift) {
787
+ uniffi_native_agent_ffi_fn_method_nativeagenthandle_add_cron_job(self.uniffiClonePointer(),
788
+ FfiConverterString.lower(inputJson),$0
789
+ )
790
+ })
791
+ }
792
+
793
+ /**
794
+ * Add a cron skill.
795
+ */
796
+ open func addSkill(inputJson: String)throws -> String {
797
+ return try FfiConverterString.lift(try rustCallWithError(FfiConverterTypeNativeAgentError.lift) {
798
+ uniffi_native_agent_ffi_fn_method_nativeagenthandle_add_skill(self.uniffiClonePointer(),
799
+ FfiConverterString.lower(inputJson),$0
800
+ )
801
+ })
802
+ }
803
+
804
+ /**
805
+ * Clear the current in-memory session state so the next sendMessage
806
+ * starts a fresh conversation. The session row in SQLite is preserved
807
+ * so it remains in the session index for later resume/switch.
808
+ */
809
+ open func clearSession()throws {try rustCallWithError(FfiConverterTypeNativeAgentError.lift) {
810
+ uniffi_native_agent_ffi_fn_method_nativeagenthandle_clear_session(self.uniffiClonePointer(),$0
811
+ )
812
+ }
813
+ }
814
+
815
+ /**
816
+ * Delete auth for a provider.
817
+ */
818
+ open func deleteAuth(provider: String)throws {try rustCallWithError(FfiConverterTypeNativeAgentError.lift) {
819
+ uniffi_native_agent_ffi_fn_method_nativeagenthandle_delete_auth(self.uniffiClonePointer(),
820
+ FfiConverterString.lower(provider),$0
821
+ )
822
+ }
823
+ }
824
+
825
+ /**
826
+ * End a skill session.
827
+ */
828
+ open func endSkill(skillId: String)throws {try rustCallWithError(FfiConverterTypeNativeAgentError.lift) {
829
+ uniffi_native_agent_ffi_fn_method_nativeagenthandle_end_skill(self.uniffiClonePointer(),
830
+ FfiConverterString.lower(skillId),$0
831
+ )
832
+ }
833
+ }
834
+
835
+ /**
836
+ * Exchange an OAuth authorization code for tokens.
837
+ */
838
+ open func exchangeOauthCode(tokenUrl: String, bodyJson: String, contentType: String?)throws -> String {
839
+ return try FfiConverterString.lift(try rustCallWithError(FfiConverterTypeNativeAgentError.lift) {
840
+ uniffi_native_agent_ffi_fn_method_nativeagenthandle_exchange_oauth_code(self.uniffiClonePointer(),
841
+ FfiConverterString.lower(tokenUrl),
842
+ FfiConverterString.lower(bodyJson),
843
+ FfiConverterOptionString.lower(contentType),$0
844
+ )
845
+ })
846
+ }
847
+
848
+ /**
849
+ * Follow up on the current conversation.
850
+ */
851
+ open func followUp(prompt: String)throws {try rustCallWithError(FfiConverterTypeNativeAgentError.lift) {
852
+ uniffi_native_agent_ffi_fn_method_nativeagenthandle_follow_up(self.uniffiClonePointer(),
853
+ FfiConverterString.lower(prompt),$0
854
+ )
855
+ }
856
+ }
857
+
858
+ /**
859
+ * Get auth status (masked key).
860
+ */
861
+ open func getAuthStatus(provider: String)throws -> AuthStatusResult {
862
+ return try FfiConverterTypeAuthStatusResult.lift(try rustCallWithError(FfiConverterTypeNativeAgentError.lift) {
863
+ uniffi_native_agent_ffi_fn_method_nativeagenthandle_get_auth_status(self.uniffiClonePointer(),
864
+ FfiConverterString.lower(provider),$0
865
+ )
866
+ })
867
+ }
868
+
869
+ /**
870
+ * Get auth token for a provider.
871
+ */
872
+ open func getAuthToken(provider: String)throws -> AuthTokenResult {
873
+ return try FfiConverterTypeAuthTokenResult.lift(try rustCallWithError(FfiConverterTypeNativeAgentError.lift) {
874
+ uniffi_native_agent_ffi_fn_method_nativeagenthandle_get_auth_token(self.uniffiClonePointer(),
875
+ FfiConverterString.lower(provider),$0
876
+ )
877
+ })
878
+ }
879
+
880
+ /**
881
+ * Get heartbeat config.
882
+ */
883
+ open func getHeartbeatConfig()throws -> String {
884
+ return try FfiConverterString.lift(try rustCallWithError(FfiConverterTypeNativeAgentError.lift) {
885
+ uniffi_native_agent_ffi_fn_method_nativeagenthandle_get_heartbeat_config(self.uniffiClonePointer(),$0
886
+ )
887
+ })
888
+ }
889
+
890
+ /**
891
+ * Get available models for a provider.
892
+ */
893
+ open func getModels(provider: String)throws -> String {
894
+ return try FfiConverterString.lift(try rustCallWithError(FfiConverterTypeNativeAgentError.lift) {
895
+ uniffi_native_agent_ffi_fn_method_nativeagenthandle_get_models(self.uniffiClonePointer(),
896
+ FfiConverterString.lower(provider),$0
897
+ )
898
+ })
899
+ }
900
+
901
+ /**
902
+ * Get scheduler config.
903
+ */
904
+ open func getSchedulerConfig()throws -> String {
905
+ return try FfiConverterString.lift(try rustCallWithError(FfiConverterTypeNativeAgentError.lift) {
906
+ uniffi_native_agent_ffi_fn_method_nativeagenthandle_get_scheduler_config(self.uniffiClonePointer(),$0
907
+ )
908
+ })
909
+ }
910
+
911
+ /**
912
+ * Handle a wake event (evaluate due cron jobs).
913
+ */
914
+ open func handleWake(source: String)throws {try rustCallWithError(FfiConverterTypeNativeAgentError.lift) {
915
+ uniffi_native_agent_ffi_fn_method_nativeagenthandle_handle_wake(self.uniffiClonePointer(),
916
+ FfiConverterString.lower(source),$0
917
+ )
918
+ }
919
+ }
920
+
921
+ /**
922
+ * Invoke a tool directly.
923
+ */
924
+ open func invokeTool(toolName: String, argsJson: String)throws -> String {
925
+ return try FfiConverterString.lift(try rustCallWithError(FfiConverterTypeNativeAgentError.lift) {
926
+ uniffi_native_agent_ffi_fn_method_nativeagenthandle_invoke_tool(self.uniffiClonePointer(),
927
+ FfiConverterString.lower(toolName),
928
+ FfiConverterString.lower(argsJson),$0
929
+ )
930
+ })
931
+ }
932
+
933
+ /**
934
+ * List all cron jobs.
935
+ */
936
+ open func listCronJobs()throws -> String {
937
+ return try FfiConverterString.lift(try rustCallWithError(FfiConverterTypeNativeAgentError.lift) {
938
+ uniffi_native_agent_ffi_fn_method_nativeagenthandle_list_cron_jobs(self.uniffiClonePointer(),$0
939
+ )
940
+ })
941
+ }
942
+
943
+ /**
944
+ * List cron run history.
945
+ */
946
+ open func listCronRuns(jobId: String?, limit: Int64)throws -> String {
947
+ return try FfiConverterString.lift(try rustCallWithError(FfiConverterTypeNativeAgentError.lift) {
948
+ uniffi_native_agent_ffi_fn_method_nativeagenthandle_list_cron_runs(self.uniffiClonePointer(),
949
+ FfiConverterOptionString.lower(jobId),
950
+ FfiConverterInt64.lower(limit),$0
951
+ )
952
+ })
953
+ }
954
+
955
+ /**
956
+ * List sessions for an agent.
957
+ */
958
+ open func listSessions(agentId: String)throws -> String {
959
+ return try FfiConverterString.lift(try rustCallWithError(FfiConverterTypeNativeAgentError.lift) {
960
+ uniffi_native_agent_ffi_fn_method_nativeagenthandle_list_sessions(self.uniffiClonePointer(),
961
+ FfiConverterString.lower(agentId),$0
962
+ )
963
+ })
964
+ }
965
+
966
+ /**
967
+ * List all cron skills.
968
+ */
969
+ open func listSkills()throws -> String {
970
+ return try FfiConverterString.lift(try rustCallWithError(FfiConverterTypeNativeAgentError.lift) {
971
+ uniffi_native_agent_ffi_fn_method_nativeagenthandle_list_skills(self.uniffiClonePointer(),$0
972
+ )
973
+ })
974
+ }
975
+
976
+ /**
977
+ * Load session message history.
978
+ */
979
+ open func loadSession(sessionKey: String)throws -> String {
980
+ return try FfiConverterString.lift(try rustCallWithError(FfiConverterTypeNativeAgentError.lift) {
981
+ uniffi_native_agent_ffi_fn_method_nativeagenthandle_load_session(self.uniffiClonePointer(),
982
+ FfiConverterString.lower(sessionKey),$0
983
+ )
984
+ })
985
+ }
986
+
987
+ open func persistConfig()throws {try rustCallWithError(FfiConverterTypeNativeAgentError.lift) {
988
+ uniffi_native_agent_ffi_fn_method_nativeagenthandle_persist_config(self.uniffiClonePointer(),$0
989
+ )
990
+ }
991
+ }
992
+
993
+ /**
994
+ * Refresh an OAuth token.
995
+ */
996
+ open func refreshToken(provider: String)throws -> AuthTokenResult {
997
+ return try FfiConverterTypeAuthTokenResult.lift(try rustCallWithError(FfiConverterTypeNativeAgentError.lift) {
998
+ uniffi_native_agent_ffi_fn_method_nativeagenthandle_refresh_token(self.uniffiClonePointer(),
999
+ FfiConverterString.lower(provider),$0
1000
+ )
1001
+ })
1002
+ }
1003
+
1004
+ /**
1005
+ * Remove a cron job.
1006
+ */
1007
+ open func removeCronJob(id: String)throws {try rustCallWithError(FfiConverterTypeNativeAgentError.lift) {
1008
+ uniffi_native_agent_ffi_fn_method_nativeagenthandle_remove_cron_job(self.uniffiClonePointer(),
1009
+ FfiConverterString.lower(id),$0
1010
+ )
1011
+ }
1012
+ }
1013
+
1014
+ /**
1015
+ * Remove a cron skill.
1016
+ */
1017
+ open func removeSkill(id: String)throws {try rustCallWithError(FfiConverterTypeNativeAgentError.lift) {
1018
+ uniffi_native_agent_ffi_fn_method_nativeagenthandle_remove_skill(self.uniffiClonePointer(),
1019
+ FfiConverterString.lower(id),$0
1020
+ )
1021
+ }
1022
+ }
1023
+
1024
+ /**
1025
+ * Respond to a tool approval request.
1026
+ */
1027
+ open func respondToApproval(toolCallId: String, approved: Bool, reason: String?)throws {try rustCallWithError(FfiConverterTypeNativeAgentError.lift) {
1028
+ uniffi_native_agent_ffi_fn_method_nativeagenthandle_respond_to_approval(self.uniffiClonePointer(),
1029
+ FfiConverterString.lower(toolCallId),
1030
+ FfiConverterBool.lower(approved),
1031
+ FfiConverterOptionString.lower(reason),$0
1032
+ )
1033
+ }
1034
+ }
1035
+
1036
+ /**
1037
+ * Respond to a cron approval request.
1038
+ */
1039
+ open func respondToCronApproval(requestId: String, approved: Bool)throws {try rustCallWithError(FfiConverterTypeNativeAgentError.lift) {
1040
+ uniffi_native_agent_ffi_fn_method_nativeagenthandle_respond_to_cron_approval(self.uniffiClonePointer(),
1041
+ FfiConverterString.lower(requestId),
1042
+ FfiConverterBool.lower(approved),$0
1043
+ )
1044
+ }
1045
+ }
1046
+
1047
+ /**
1048
+ * Respond to a pending MCP tool call.
1049
+ */
1050
+ open func respondToMcpTool(toolCallId: String, resultJson: String, isError: Bool)throws {try rustCallWithError(FfiConverterTypeNativeAgentError.lift) {
1051
+ uniffi_native_agent_ffi_fn_method_nativeagenthandle_respond_to_mcp_tool(self.uniffiClonePointer(),
1052
+ FfiConverterString.lower(toolCallId),
1053
+ FfiConverterString.lower(resultJson),
1054
+ FfiConverterBool.lower(isError),$0
1055
+ )
1056
+ }
1057
+ }
1058
+
1059
+ /**
1060
+ * Restart MCP server with new tools.
1061
+ */
1062
+ open func restartMcp(toolsJson: String)throws -> UInt32 {
1063
+ return try FfiConverterUInt32.lift(try rustCallWithError(FfiConverterTypeNativeAgentError.lift) {
1064
+ uniffi_native_agent_ffi_fn_method_nativeagenthandle_restart_mcp(self.uniffiClonePointer(),
1065
+ FfiConverterString.lower(toolsJson),$0
1066
+ )
1067
+ })
1068
+ }
1069
+
1070
+ /**
1071
+ * Resume a session (load messages into agent context).
1072
+ */
1073
+ open func resumeSession(sessionKey: String, agentId: String, messagesJson: String?, provider: String?, model: String?)throws {try rustCallWithError(FfiConverterTypeNativeAgentError.lift) {
1074
+ uniffi_native_agent_ffi_fn_method_nativeagenthandle_resume_session(self.uniffiClonePointer(),
1075
+ FfiConverterString.lower(sessionKey),
1076
+ FfiConverterString.lower(agentId),
1077
+ FfiConverterOptionString.lower(messagesJson),
1078
+ FfiConverterOptionString.lower(provider),
1079
+ FfiConverterOptionString.lower(model),$0
1080
+ )
1081
+ }
1082
+ }
1083
+
1084
+ /**
1085
+ * Force-trigger a cron job.
1086
+ */
1087
+ open func runCronJob(jobId: String)throws {try rustCallWithError(FfiConverterTypeNativeAgentError.lift) {
1088
+ uniffi_native_agent_ffi_fn_method_nativeagenthandle_run_cron_job(self.uniffiClonePointer(),
1089
+ FfiConverterString.lower(jobId),$0
1090
+ )
1091
+ }
1092
+ }
1093
+
1094
+ /**
1095
+ * Send a message to the agent and start an agent loop turn.
1096
+ */
1097
+ open func sendMessage(params: SendMessageParams)throws -> String {
1098
+ return try FfiConverterString.lift(try rustCallWithError(FfiConverterTypeNativeAgentError.lift) {
1099
+ uniffi_native_agent_ffi_fn_method_nativeagenthandle_send_message(self.uniffiClonePointer(),
1100
+ FfiConverterTypeSendMessageParams.lower(params),$0
1101
+ )
1102
+ })
1103
+ }
1104
+
1105
+ /**
1106
+ * Set an auth key for a provider.
1107
+ */
1108
+ open func setAuthKey(key: String, provider: String, authType: String)throws {try rustCallWithError(FfiConverterTypeNativeAgentError.lift) {
1109
+ uniffi_native_agent_ffi_fn_method_nativeagenthandle_set_auth_key(self.uniffiClonePointer(),
1110
+ FfiConverterString.lower(key),
1111
+ FfiConverterString.lower(provider),
1112
+ FfiConverterString.lower(authType),$0
1113
+ )
1114
+ }
1115
+ }
1116
+
1117
+ /**
1118
+ * Set the event callback for receiving agent events.
1119
+ */
1120
+ open func setEventCallback(callback: NativeEventCallback)throws {try rustCallWithError(FfiConverterTypeNativeAgentError.lift) {
1121
+ uniffi_native_agent_ffi_fn_method_nativeagenthandle_set_event_callback(self.uniffiClonePointer(),
1122
+ FfiConverterCallbackInterfaceNativeEventCallback.lower(callback),$0
1123
+ )
1124
+ }
1125
+ }
1126
+
1127
+ /**
1128
+ * Set heartbeat config.
1129
+ */
1130
+ open func setHeartbeatConfig(configJson: String)throws {try rustCallWithError(FfiConverterTypeNativeAgentError.lift) {
1131
+ uniffi_native_agent_ffi_fn_method_nativeagenthandle_set_heartbeat_config(self.uniffiClonePointer(),
1132
+ FfiConverterString.lower(configJson),$0
1133
+ )
1134
+ }
1135
+ }
1136
+
1137
+ open func setMemoryProvider(provider: MemoryProvider)throws {try rustCallWithError(FfiConverterTypeNativeAgentError.lift) {
1138
+ uniffi_native_agent_ffi_fn_method_nativeagenthandle_set_memory_provider(self.uniffiClonePointer(),
1139
+ FfiConverterCallbackInterfaceMemoryProvider.lower(provider),$0
1140
+ )
1141
+ }
1142
+ }
1143
+
1144
+ open func setNotifier(notifier: NativeNotifier)throws {try rustCallWithError(FfiConverterTypeNativeAgentError.lift) {
1145
+ uniffi_native_agent_ffi_fn_method_nativeagenthandle_set_notifier(self.uniffiClonePointer(),
1146
+ FfiConverterCallbackInterfaceNativeNotifier.lower(notifier),$0
1147
+ )
1148
+ }
1149
+ }
1150
+
1151
+ /**
1152
+ * Set scheduler config.
1153
+ */
1154
+ open func setSchedulerConfig(configJson: String)throws {try rustCallWithError(FfiConverterTypeNativeAgentError.lift) {
1155
+ uniffi_native_agent_ffi_fn_method_nativeagenthandle_set_scheduler_config(self.uniffiClonePointer(),
1156
+ FfiConverterString.lower(configJson),$0
1157
+ )
1158
+ }
1159
+ }
1160
+
1161
+ /**
1162
+ * Start MCP server with given tools.
1163
+ */
1164
+ open func startMcp(toolsJson: String)throws -> UInt32 {
1165
+ return try FfiConverterUInt32.lift(try rustCallWithError(FfiConverterTypeNativeAgentError.lift) {
1166
+ uniffi_native_agent_ffi_fn_method_nativeagenthandle_start_mcp(self.uniffiClonePointer(),
1167
+ FfiConverterString.lower(toolsJson),$0
1168
+ )
1169
+ })
1170
+ }
1171
+
1172
+ /**
1173
+ * Start a skill session.
1174
+ */
1175
+ open func startSkill(skillId: String, configJson: String, provider: String?)throws -> String {
1176
+ return try FfiConverterString.lift(try rustCallWithError(FfiConverterTypeNativeAgentError.lift) {
1177
+ uniffi_native_agent_ffi_fn_method_nativeagenthandle_start_skill(self.uniffiClonePointer(),
1178
+ FfiConverterString.lower(skillId),
1179
+ FfiConverterString.lower(configJson),
1180
+ FfiConverterOptionString.lower(provider),$0
1181
+ )
1182
+ })
1183
+ }
1184
+
1185
+ /**
1186
+ * Steer the running agent with additional context.
1187
+ */
1188
+ open func steer(text: String)throws {try rustCallWithError(FfiConverterTypeNativeAgentError.lift) {
1189
+ uniffi_native_agent_ffi_fn_method_nativeagenthandle_steer(self.uniffiClonePointer(),
1190
+ FfiConverterString.lower(text),$0
1191
+ )
1192
+ }
1193
+ }
1194
+
1195
+ /**
1196
+ * Update a cron job.
1197
+ */
1198
+ open func updateCronJob(id: String, patchJson: String)throws {try rustCallWithError(FfiConverterTypeNativeAgentError.lift) {
1199
+ uniffi_native_agent_ffi_fn_method_nativeagenthandle_update_cron_job(self.uniffiClonePointer(),
1200
+ FfiConverterString.lower(id),
1201
+ FfiConverterString.lower(patchJson),$0
1202
+ )
1203
+ }
1204
+ }
1205
+
1206
+ /**
1207
+ * Update a cron skill.
1208
+ */
1209
+ open func updateSkill(id: String, patchJson: String)throws {try rustCallWithError(FfiConverterTypeNativeAgentError.lift) {
1210
+ uniffi_native_agent_ffi_fn_method_nativeagenthandle_update_skill(self.uniffiClonePointer(),
1211
+ FfiConverterString.lower(id),
1212
+ FfiConverterString.lower(patchJson),$0
1213
+ )
1214
+ }
1215
+ }
1216
+
1217
+
1218
+ }
1219
+
1220
+ #if swift(>=5.8)
1221
+ @_documentation(visibility: private)
1222
+ #endif
1223
+ public struct FfiConverterTypeNativeAgentHandle: FfiConverter {
1224
+
1225
+ typealias FfiType = UnsafeMutableRawPointer
1226
+ typealias SwiftType = NativeAgentHandle
1227
+
1228
+ public static func lift(_ pointer: UnsafeMutableRawPointer) throws -> NativeAgentHandle {
1229
+ return NativeAgentHandle(unsafeFromRawPointer: pointer)
1230
+ }
1231
+
1232
+ public static func lower(_ value: NativeAgentHandle) -> UnsafeMutableRawPointer {
1233
+ return value.uniffiClonePointer()
1234
+ }
1235
+
1236
+ public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> NativeAgentHandle {
1237
+ let v: UInt64 = try readInt(&buf)
1238
+ // The Rust code won't compile if a pointer won't fit in a UInt64.
1239
+ // We have to go via `UInt` because that's the thing that's the size of a pointer.
1240
+ let ptr = UnsafeMutableRawPointer(bitPattern: UInt(truncatingIfNeeded: v))
1241
+ if (ptr == nil) {
1242
+ throw UniffiInternalError.unexpectedNullPointer
1243
+ }
1244
+ return try lift(ptr!)
1245
+ }
1246
+
1247
+ public static func write(_ value: NativeAgentHandle, into buf: inout [UInt8]) {
1248
+ // This fiddling is because `Int` is the thing that's the same size as a pointer.
1249
+ // The Rust code won't compile if a pointer won't fit in a `UInt64`.
1250
+ writeInt(&buf, UInt64(bitPattern: Int64(Int(bitPattern: lower(value)))))
1251
+ }
1252
+ }
1253
+
1254
+
1255
+
1256
+
1257
+ #if swift(>=5.8)
1258
+ @_documentation(visibility: private)
1259
+ #endif
1260
+ public func FfiConverterTypeNativeAgentHandle_lift(_ pointer: UnsafeMutableRawPointer) throws -> NativeAgentHandle {
1261
+ return try FfiConverterTypeNativeAgentHandle.lift(pointer)
1262
+ }
1263
+
1264
+ #if swift(>=5.8)
1265
+ @_documentation(visibility: private)
1266
+ #endif
1267
+ public func FfiConverterTypeNativeAgentHandle_lower(_ value: NativeAgentHandle) -> UnsafeMutableRawPointer {
1268
+ return FfiConverterTypeNativeAgentHandle.lower(value)
1269
+ }
1270
+
1271
+
1272
+ /**
1273
+ * Auth status result.
1274
+ */
1275
+ public struct AuthStatusResult {
1276
+ public var hasKey: Bool
1277
+ public var masked: String
1278
+ public var provider: String
1279
+
1280
+ // Default memberwise initializers are never public by default, so we
1281
+ // declare one manually.
1282
+ public init(hasKey: Bool, masked: String, provider: String) {
1283
+ self.hasKey = hasKey
1284
+ self.masked = masked
1285
+ self.provider = provider
1286
+ }
1287
+ }
1288
+
1289
+
1290
+
1291
+ extension AuthStatusResult: Equatable, Hashable {
1292
+ public static func ==(lhs: AuthStatusResult, rhs: AuthStatusResult) -> Bool {
1293
+ if lhs.hasKey != rhs.hasKey {
1294
+ return false
1295
+ }
1296
+ if lhs.masked != rhs.masked {
1297
+ return false
1298
+ }
1299
+ if lhs.provider != rhs.provider {
1300
+ return false
1301
+ }
1302
+ return true
1303
+ }
1304
+
1305
+ public func hash(into hasher: inout Hasher) {
1306
+ hasher.combine(hasKey)
1307
+ hasher.combine(masked)
1308
+ hasher.combine(provider)
1309
+ }
1310
+ }
1311
+
1312
+
1313
+ #if swift(>=5.8)
1314
+ @_documentation(visibility: private)
1315
+ #endif
1316
+ public struct FfiConverterTypeAuthStatusResult: FfiConverterRustBuffer {
1317
+ public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> AuthStatusResult {
1318
+ return
1319
+ try AuthStatusResult(
1320
+ hasKey: FfiConverterBool.read(from: &buf),
1321
+ masked: FfiConverterString.read(from: &buf),
1322
+ provider: FfiConverterString.read(from: &buf)
1323
+ )
1324
+ }
1325
+
1326
+ public static func write(_ value: AuthStatusResult, into buf: inout [UInt8]) {
1327
+ FfiConverterBool.write(value.hasKey, into: &buf)
1328
+ FfiConverterString.write(value.masked, into: &buf)
1329
+ FfiConverterString.write(value.provider, into: &buf)
1330
+ }
1331
+ }
1332
+
1333
+
1334
+ #if swift(>=5.8)
1335
+ @_documentation(visibility: private)
1336
+ #endif
1337
+ public func FfiConverterTypeAuthStatusResult_lift(_ buf: RustBuffer) throws -> AuthStatusResult {
1338
+ return try FfiConverterTypeAuthStatusResult.lift(buf)
1339
+ }
1340
+
1341
+ #if swift(>=5.8)
1342
+ @_documentation(visibility: private)
1343
+ #endif
1344
+ public func FfiConverterTypeAuthStatusResult_lower(_ value: AuthStatusResult) -> RustBuffer {
1345
+ return FfiConverterTypeAuthStatusResult.lower(value)
1346
+ }
1347
+
1348
+
1349
+ /**
1350
+ * Auth token result.
1351
+ */
1352
+ public struct AuthTokenResult {
1353
+ public var apiKey: String?
1354
+ public var isOauth: Bool
1355
+
1356
+ // Default memberwise initializers are never public by default, so we
1357
+ // declare one manually.
1358
+ public init(apiKey: String?, isOauth: Bool) {
1359
+ self.apiKey = apiKey
1360
+ self.isOauth = isOauth
1361
+ }
1362
+ }
1363
+
1364
+
1365
+
1366
+ extension AuthTokenResult: Equatable, Hashable {
1367
+ public static func ==(lhs: AuthTokenResult, rhs: AuthTokenResult) -> Bool {
1368
+ if lhs.apiKey != rhs.apiKey {
1369
+ return false
1370
+ }
1371
+ if lhs.isOauth != rhs.isOauth {
1372
+ return false
1373
+ }
1374
+ return true
1375
+ }
1376
+
1377
+ public func hash(into hasher: inout Hasher) {
1378
+ hasher.combine(apiKey)
1379
+ hasher.combine(isOauth)
1380
+ }
1381
+ }
1382
+
1383
+
1384
+ #if swift(>=5.8)
1385
+ @_documentation(visibility: private)
1386
+ #endif
1387
+ public struct FfiConverterTypeAuthTokenResult: FfiConverterRustBuffer {
1388
+ public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> AuthTokenResult {
1389
+ return
1390
+ try AuthTokenResult(
1391
+ apiKey: FfiConverterOptionString.read(from: &buf),
1392
+ isOauth: FfiConverterBool.read(from: &buf)
1393
+ )
1394
+ }
1395
+
1396
+ public static func write(_ value: AuthTokenResult, into buf: inout [UInt8]) {
1397
+ FfiConverterOptionString.write(value.apiKey, into: &buf)
1398
+ FfiConverterBool.write(value.isOauth, into: &buf)
1399
+ }
1400
+ }
1401
+
1402
+
1403
+ #if swift(>=5.8)
1404
+ @_documentation(visibility: private)
1405
+ #endif
1406
+ public func FfiConverterTypeAuthTokenResult_lift(_ buf: RustBuffer) throws -> AuthTokenResult {
1407
+ return try FfiConverterTypeAuthTokenResult.lift(buf)
1408
+ }
1409
+
1410
+ #if swift(>=5.8)
1411
+ @_documentation(visibility: private)
1412
+ #endif
1413
+ public func FfiConverterTypeAuthTokenResult_lower(_ value: AuthTokenResult) -> RustBuffer {
1414
+ return FfiConverterTypeAuthTokenResult.lower(value)
1415
+ }
1416
+
1417
+
1418
+ /**
1419
+ * Configuration for initializing the native agent handle.
1420
+ */
1421
+ public struct InitConfig {
1422
+ /**
1423
+ * Path to the SQLite database.
1424
+ */
1425
+ public var dbPath: String
1426
+ /**
1427
+ * Path to the workspace root.
1428
+ */
1429
+ public var workspacePath: String
1430
+ /**
1431
+ * Path to auth-profiles.json.
1432
+ */
1433
+ public var authProfilesPath: String
1434
+
1435
+ // Default memberwise initializers are never public by default, so we
1436
+ // declare one manually.
1437
+ public init(
1438
+ /**
1439
+ * Path to the SQLite database.
1440
+ */dbPath: String,
1441
+ /**
1442
+ * Path to the workspace root.
1443
+ */workspacePath: String,
1444
+ /**
1445
+ * Path to auth-profiles.json.
1446
+ */authProfilesPath: String) {
1447
+ self.dbPath = dbPath
1448
+ self.workspacePath = workspacePath
1449
+ self.authProfilesPath = authProfilesPath
1450
+ }
1451
+ }
1452
+
1453
+
1454
+
1455
+ extension InitConfig: Equatable, Hashable {
1456
+ public static func ==(lhs: InitConfig, rhs: InitConfig) -> Bool {
1457
+ if lhs.dbPath != rhs.dbPath {
1458
+ return false
1459
+ }
1460
+ if lhs.workspacePath != rhs.workspacePath {
1461
+ return false
1462
+ }
1463
+ if lhs.authProfilesPath != rhs.authProfilesPath {
1464
+ return false
1465
+ }
1466
+ return true
1467
+ }
1468
+
1469
+ public func hash(into hasher: inout Hasher) {
1470
+ hasher.combine(dbPath)
1471
+ hasher.combine(workspacePath)
1472
+ hasher.combine(authProfilesPath)
1473
+ }
1474
+ }
1475
+
1476
+
1477
+ #if swift(>=5.8)
1478
+ @_documentation(visibility: private)
1479
+ #endif
1480
+ public struct FfiConverterTypeInitConfig: FfiConverterRustBuffer {
1481
+ public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> InitConfig {
1482
+ return
1483
+ try InitConfig(
1484
+ dbPath: FfiConverterString.read(from: &buf),
1485
+ workspacePath: FfiConverterString.read(from: &buf),
1486
+ authProfilesPath: FfiConverterString.read(from: &buf)
1487
+ )
1488
+ }
1489
+
1490
+ public static func write(_ value: InitConfig, into buf: inout [UInt8]) {
1491
+ FfiConverterString.write(value.dbPath, into: &buf)
1492
+ FfiConverterString.write(value.workspacePath, into: &buf)
1493
+ FfiConverterString.write(value.authProfilesPath, into: &buf)
1494
+ }
1495
+ }
1496
+
1497
+
1498
+ #if swift(>=5.8)
1499
+ @_documentation(visibility: private)
1500
+ #endif
1501
+ public func FfiConverterTypeInitConfig_lift(_ buf: RustBuffer) throws -> InitConfig {
1502
+ return try FfiConverterTypeInitConfig.lift(buf)
1503
+ }
1504
+
1505
+ #if swift(>=5.8)
1506
+ @_documentation(visibility: private)
1507
+ #endif
1508
+ public func FfiConverterTypeInitConfig_lower(_ value: InitConfig) -> RustBuffer {
1509
+ return FfiConverterTypeInitConfig.lower(value)
1510
+ }
1511
+
1512
+
1513
+ /**
1514
+ * Buffered event emitted while no foreground callback is attached.
1515
+ */
1516
+ public struct PendingEvent {
1517
+ public var id: Int64
1518
+ public var eventType: String
1519
+ public var payloadJson: String
1520
+ public var createdAt: Int64
1521
+
1522
+ // Default memberwise initializers are never public by default, so we
1523
+ // declare one manually.
1524
+ public init(id: Int64, eventType: String, payloadJson: String, createdAt: Int64) {
1525
+ self.id = id
1526
+ self.eventType = eventType
1527
+ self.payloadJson = payloadJson
1528
+ self.createdAt = createdAt
1529
+ }
1530
+ }
1531
+
1532
+
1533
+
1534
+ extension PendingEvent: Equatable, Hashable {
1535
+ public static func ==(lhs: PendingEvent, rhs: PendingEvent) -> Bool {
1536
+ if lhs.id != rhs.id {
1537
+ return false
1538
+ }
1539
+ if lhs.eventType != rhs.eventType {
1540
+ return false
1541
+ }
1542
+ if lhs.payloadJson != rhs.payloadJson {
1543
+ return false
1544
+ }
1545
+ if lhs.createdAt != rhs.createdAt {
1546
+ return false
1547
+ }
1548
+ return true
1549
+ }
1550
+
1551
+ public func hash(into hasher: inout Hasher) {
1552
+ hasher.combine(id)
1553
+ hasher.combine(eventType)
1554
+ hasher.combine(payloadJson)
1555
+ hasher.combine(createdAt)
1556
+ }
1557
+ }
1558
+
1559
+
1560
+ #if swift(>=5.8)
1561
+ @_documentation(visibility: private)
1562
+ #endif
1563
+ public struct FfiConverterTypePendingEvent: FfiConverterRustBuffer {
1564
+ public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> PendingEvent {
1565
+ return
1566
+ try PendingEvent(
1567
+ id: FfiConverterInt64.read(from: &buf),
1568
+ eventType: FfiConverterString.read(from: &buf),
1569
+ payloadJson: FfiConverterString.read(from: &buf),
1570
+ createdAt: FfiConverterInt64.read(from: &buf)
1571
+ )
1572
+ }
1573
+
1574
+ public static func write(_ value: PendingEvent, into buf: inout [UInt8]) {
1575
+ FfiConverterInt64.write(value.id, into: &buf)
1576
+ FfiConverterString.write(value.eventType, into: &buf)
1577
+ FfiConverterString.write(value.payloadJson, into: &buf)
1578
+ FfiConverterInt64.write(value.createdAt, into: &buf)
1579
+ }
1580
+ }
1581
+
1582
+
1583
+ #if swift(>=5.8)
1584
+ @_documentation(visibility: private)
1585
+ #endif
1586
+ public func FfiConverterTypePendingEvent_lift(_ buf: RustBuffer) throws -> PendingEvent {
1587
+ return try FfiConverterTypePendingEvent.lift(buf)
1588
+ }
1589
+
1590
+ #if swift(>=5.8)
1591
+ @_documentation(visibility: private)
1592
+ #endif
1593
+ public func FfiConverterTypePendingEvent_lower(_ value: PendingEvent) -> RustBuffer {
1594
+ return FfiConverterTypePendingEvent.lower(value)
1595
+ }
1596
+
1597
+
1598
+ /**
1599
+ * Parameters for sending a message.
1600
+ */
1601
+ public struct SendMessageParams {
1602
+ public var prompt: String
1603
+ public var sessionKey: String
1604
+ public var model: String?
1605
+ public var provider: String?
1606
+ public var systemPrompt: String
1607
+ public var maxTurns: UInt32?
1608
+ /**
1609
+ * JSON-encoded list of allowed tool names. Empty = all tools.
1610
+ */
1611
+ public var allowedToolsJson: String?
1612
+
1613
+ // Default memberwise initializers are never public by default, so we
1614
+ // declare one manually.
1615
+ public init(prompt: String, sessionKey: String, model: String?, provider: String?, systemPrompt: String, maxTurns: UInt32?,
1616
+ /**
1617
+ * JSON-encoded list of allowed tool names. Empty = all tools.
1618
+ */allowedToolsJson: String?) {
1619
+ self.prompt = prompt
1620
+ self.sessionKey = sessionKey
1621
+ self.model = model
1622
+ self.provider = provider
1623
+ self.systemPrompt = systemPrompt
1624
+ self.maxTurns = maxTurns
1625
+ self.allowedToolsJson = allowedToolsJson
1626
+ }
1627
+ }
1628
+
1629
+
1630
+
1631
+ extension SendMessageParams: Equatable, Hashable {
1632
+ public static func ==(lhs: SendMessageParams, rhs: SendMessageParams) -> Bool {
1633
+ if lhs.prompt != rhs.prompt {
1634
+ return false
1635
+ }
1636
+ if lhs.sessionKey != rhs.sessionKey {
1637
+ return false
1638
+ }
1639
+ if lhs.model != rhs.model {
1640
+ return false
1641
+ }
1642
+ if lhs.provider != rhs.provider {
1643
+ return false
1644
+ }
1645
+ if lhs.systemPrompt != rhs.systemPrompt {
1646
+ return false
1647
+ }
1648
+ if lhs.maxTurns != rhs.maxTurns {
1649
+ return false
1650
+ }
1651
+ if lhs.allowedToolsJson != rhs.allowedToolsJson {
1652
+ return false
1653
+ }
1654
+ return true
1655
+ }
1656
+
1657
+ public func hash(into hasher: inout Hasher) {
1658
+ hasher.combine(prompt)
1659
+ hasher.combine(sessionKey)
1660
+ hasher.combine(model)
1661
+ hasher.combine(provider)
1662
+ hasher.combine(systemPrompt)
1663
+ hasher.combine(maxTurns)
1664
+ hasher.combine(allowedToolsJson)
1665
+ }
1666
+ }
1667
+
1668
+
1669
+ #if swift(>=5.8)
1670
+ @_documentation(visibility: private)
1671
+ #endif
1672
+ public struct FfiConverterTypeSendMessageParams: FfiConverterRustBuffer {
1673
+ public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> SendMessageParams {
1674
+ return
1675
+ try SendMessageParams(
1676
+ prompt: FfiConverterString.read(from: &buf),
1677
+ sessionKey: FfiConverterString.read(from: &buf),
1678
+ model: FfiConverterOptionString.read(from: &buf),
1679
+ provider: FfiConverterOptionString.read(from: &buf),
1680
+ systemPrompt: FfiConverterString.read(from: &buf),
1681
+ maxTurns: FfiConverterOptionUInt32.read(from: &buf),
1682
+ allowedToolsJson: FfiConverterOptionString.read(from: &buf)
1683
+ )
1684
+ }
1685
+
1686
+ public static func write(_ value: SendMessageParams, into buf: inout [UInt8]) {
1687
+ FfiConverterString.write(value.prompt, into: &buf)
1688
+ FfiConverterString.write(value.sessionKey, into: &buf)
1689
+ FfiConverterOptionString.write(value.model, into: &buf)
1690
+ FfiConverterOptionString.write(value.provider, into: &buf)
1691
+ FfiConverterString.write(value.systemPrompt, into: &buf)
1692
+ FfiConverterOptionUInt32.write(value.maxTurns, into: &buf)
1693
+ FfiConverterOptionString.write(value.allowedToolsJson, into: &buf)
1694
+ }
1695
+ }
1696
+
1697
+
1698
+ #if swift(>=5.8)
1699
+ @_documentation(visibility: private)
1700
+ #endif
1701
+ public func FfiConverterTypeSendMessageParams_lift(_ buf: RustBuffer) throws -> SendMessageParams {
1702
+ return try FfiConverterTypeSendMessageParams.lift(buf)
1703
+ }
1704
+
1705
+ #if swift(>=5.8)
1706
+ @_documentation(visibility: private)
1707
+ #endif
1708
+ public func FfiConverterTypeSendMessageParams_lower(_ value: SendMessageParams) -> RustBuffer {
1709
+ return FfiConverterTypeSendMessageParams.lower(value)
1710
+ }
1711
+
1712
+
1713
+ /**
1714
+ * Token usage from an agent turn.
1715
+ */
1716
+ public struct TokenUsage {
1717
+ public var inputTokens: UInt32
1718
+ public var outputTokens: UInt32
1719
+ public var totalTokens: UInt32
1720
+
1721
+ // Default memberwise initializers are never public by default, so we
1722
+ // declare one manually.
1723
+ public init(inputTokens: UInt32, outputTokens: UInt32, totalTokens: UInt32) {
1724
+ self.inputTokens = inputTokens
1725
+ self.outputTokens = outputTokens
1726
+ self.totalTokens = totalTokens
1727
+ }
1728
+ }
1729
+
1730
+
1731
+
1732
+ extension TokenUsage: Equatable, Hashable {
1733
+ public static func ==(lhs: TokenUsage, rhs: TokenUsage) -> Bool {
1734
+ if lhs.inputTokens != rhs.inputTokens {
1735
+ return false
1736
+ }
1737
+ if lhs.outputTokens != rhs.outputTokens {
1738
+ return false
1739
+ }
1740
+ if lhs.totalTokens != rhs.totalTokens {
1741
+ return false
1742
+ }
1743
+ return true
1744
+ }
1745
+
1746
+ public func hash(into hasher: inout Hasher) {
1747
+ hasher.combine(inputTokens)
1748
+ hasher.combine(outputTokens)
1749
+ hasher.combine(totalTokens)
1750
+ }
1751
+ }
1752
+
1753
+
1754
+ #if swift(>=5.8)
1755
+ @_documentation(visibility: private)
1756
+ #endif
1757
+ public struct FfiConverterTypeTokenUsage: FfiConverterRustBuffer {
1758
+ public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> TokenUsage {
1759
+ return
1760
+ try TokenUsage(
1761
+ inputTokens: FfiConverterUInt32.read(from: &buf),
1762
+ outputTokens: FfiConverterUInt32.read(from: &buf),
1763
+ totalTokens: FfiConverterUInt32.read(from: &buf)
1764
+ )
1765
+ }
1766
+
1767
+ public static func write(_ value: TokenUsage, into buf: inout [UInt8]) {
1768
+ FfiConverterUInt32.write(value.inputTokens, into: &buf)
1769
+ FfiConverterUInt32.write(value.outputTokens, into: &buf)
1770
+ FfiConverterUInt32.write(value.totalTokens, into: &buf)
1771
+ }
1772
+ }
1773
+
1774
+
1775
+ #if swift(>=5.8)
1776
+ @_documentation(visibility: private)
1777
+ #endif
1778
+ public func FfiConverterTypeTokenUsage_lift(_ buf: RustBuffer) throws -> TokenUsage {
1779
+ return try FfiConverterTypeTokenUsage.lift(buf)
1780
+ }
1781
+
1782
+ #if swift(>=5.8)
1783
+ @_documentation(visibility: private)
1784
+ #endif
1785
+ public func FfiConverterTypeTokenUsage_lower(_ value: TokenUsage) -> RustBuffer {
1786
+ return FfiConverterTypeTokenUsage.lower(value)
1787
+ }
1788
+
1789
+
1790
+ /**
1791
+ * Top-level error type exposed via UniFFI.
1792
+ */
1793
+ public enum NativeAgentError {
1794
+
1795
+
1796
+
1797
+ case Agent(msg: String
1798
+ )
1799
+ case Auth(msg: String
1800
+ )
1801
+ case Database(msg: String
1802
+ )
1803
+ case Llm(msg: String
1804
+ )
1805
+ case Tool(msg: String
1806
+ )
1807
+ case Io(msg: String
1808
+ )
1809
+ case Cancelled
1810
+ }
1811
+
1812
+
1813
+ #if swift(>=5.8)
1814
+ @_documentation(visibility: private)
1815
+ #endif
1816
+ public struct FfiConverterTypeNativeAgentError: FfiConverterRustBuffer {
1817
+ typealias SwiftType = NativeAgentError
1818
+
1819
+ public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> NativeAgentError {
1820
+ let variant: Int32 = try readInt(&buf)
1821
+ switch variant {
1822
+
1823
+
1824
+
1825
+
1826
+ case 1: return .Agent(
1827
+ msg: try FfiConverterString.read(from: &buf)
1828
+ )
1829
+ case 2: return .Auth(
1830
+ msg: try FfiConverterString.read(from: &buf)
1831
+ )
1832
+ case 3: return .Database(
1833
+ msg: try FfiConverterString.read(from: &buf)
1834
+ )
1835
+ case 4: return .Llm(
1836
+ msg: try FfiConverterString.read(from: &buf)
1837
+ )
1838
+ case 5: return .Tool(
1839
+ msg: try FfiConverterString.read(from: &buf)
1840
+ )
1841
+ case 6: return .Io(
1842
+ msg: try FfiConverterString.read(from: &buf)
1843
+ )
1844
+ case 7: return .Cancelled
1845
+
1846
+ default: throw UniffiInternalError.unexpectedEnumCase
1847
+ }
1848
+ }
1849
+
1850
+ public static func write(_ value: NativeAgentError, into buf: inout [UInt8]) {
1851
+ switch value {
1852
+
1853
+
1854
+
1855
+
1856
+
1857
+ case let .Agent(msg):
1858
+ writeInt(&buf, Int32(1))
1859
+ FfiConverterString.write(msg, into: &buf)
1860
+
1861
+
1862
+ case let .Auth(msg):
1863
+ writeInt(&buf, Int32(2))
1864
+ FfiConverterString.write(msg, into: &buf)
1865
+
1866
+
1867
+ case let .Database(msg):
1868
+ writeInt(&buf, Int32(3))
1869
+ FfiConverterString.write(msg, into: &buf)
1870
+
1871
+
1872
+ case let .Llm(msg):
1873
+ writeInt(&buf, Int32(4))
1874
+ FfiConverterString.write(msg, into: &buf)
1875
+
1876
+
1877
+ case let .Tool(msg):
1878
+ writeInt(&buf, Int32(5))
1879
+ FfiConverterString.write(msg, into: &buf)
1880
+
1881
+
1882
+ case let .Io(msg):
1883
+ writeInt(&buf, Int32(6))
1884
+ FfiConverterString.write(msg, into: &buf)
1885
+
1886
+
1887
+ case .Cancelled:
1888
+ writeInt(&buf, Int32(7))
1889
+
1890
+ }
1891
+ }
1892
+ }
1893
+
1894
+
1895
+ extension NativeAgentError: Equatable, Hashable {}
1896
+
1897
+ extension NativeAgentError: Foundation.LocalizedError {
1898
+ public var errorDescription: String? {
1899
+ String(reflecting: self)
1900
+ }
1901
+ }
1902
+
1903
+
1904
+
1905
+
1906
+ /**
1907
+ * Callback interface for memory operations (LanceDB or any vector store).
1908
+ * Implemented by Kotlin/Swift, which bridges to the actual memory backend.
1909
+ */
1910
+ public protocol MemoryProvider : AnyObject {
1911
+
1912
+ func store(key: String, text: String, metadataJson: String?) -> String
1913
+
1914
+ func recall(query: String, limit: UInt32) -> String
1915
+
1916
+ func forget(key: String) -> String
1917
+
1918
+ func search(query: String, maxResults: UInt32) -> String
1919
+
1920
+ func list(prefix: String?, limit: UInt32?) -> String
1921
+
1922
+ }
1923
+
1924
+ // Magic number for the Rust proxy to call using the same mechanism as every other method,
1925
+ // to free the callback once it's dropped by Rust.
1926
+ private let IDX_CALLBACK_FREE: Int32 = 0
1927
+ // Callback return codes
1928
+ private let UNIFFI_CALLBACK_SUCCESS: Int32 = 0
1929
+ private let UNIFFI_CALLBACK_ERROR: Int32 = 1
1930
+ private let UNIFFI_CALLBACK_UNEXPECTED_ERROR: Int32 = 2
1931
+
1932
+ // Put the implementation in a struct so we don't pollute the top-level namespace
1933
+ fileprivate struct UniffiCallbackInterfaceMemoryProvider {
1934
+
1935
+ // Create the VTable using a series of closures.
1936
+ // Swift automatically converts these into C callback functions.
1937
+ static var vtable: UniffiVTableCallbackInterfaceMemoryProvider = UniffiVTableCallbackInterfaceMemoryProvider(
1938
+ store: { (
1939
+ uniffiHandle: UInt64,
1940
+ key: RustBuffer,
1941
+ text: RustBuffer,
1942
+ metadataJson: RustBuffer,
1943
+ uniffiOutReturn: UnsafeMutablePointer<RustBuffer>,
1944
+ uniffiCallStatus: UnsafeMutablePointer<RustCallStatus>
1945
+ ) in
1946
+ let makeCall = {
1947
+ () throws -> String in
1948
+ guard let uniffiObj = try? FfiConverterCallbackInterfaceMemoryProvider.handleMap.get(handle: uniffiHandle) else {
1949
+ throw UniffiInternalError.unexpectedStaleHandle
1950
+ }
1951
+ return uniffiObj.store(
1952
+ key: try FfiConverterString.lift(key),
1953
+ text: try FfiConverterString.lift(text),
1954
+ metadataJson: try FfiConverterOptionString.lift(metadataJson)
1955
+ )
1956
+ }
1957
+
1958
+
1959
+ let writeReturn = { uniffiOutReturn.pointee = FfiConverterString.lower($0) }
1960
+ uniffiTraitInterfaceCall(
1961
+ callStatus: uniffiCallStatus,
1962
+ makeCall: makeCall,
1963
+ writeReturn: writeReturn
1964
+ )
1965
+ },
1966
+ recall: { (
1967
+ uniffiHandle: UInt64,
1968
+ query: RustBuffer,
1969
+ limit: UInt32,
1970
+ uniffiOutReturn: UnsafeMutablePointer<RustBuffer>,
1971
+ uniffiCallStatus: UnsafeMutablePointer<RustCallStatus>
1972
+ ) in
1973
+ let makeCall = {
1974
+ () throws -> String in
1975
+ guard let uniffiObj = try? FfiConverterCallbackInterfaceMemoryProvider.handleMap.get(handle: uniffiHandle) else {
1976
+ throw UniffiInternalError.unexpectedStaleHandle
1977
+ }
1978
+ return uniffiObj.recall(
1979
+ query: try FfiConverterString.lift(query),
1980
+ limit: try FfiConverterUInt32.lift(limit)
1981
+ )
1982
+ }
1983
+
1984
+
1985
+ let writeReturn = { uniffiOutReturn.pointee = FfiConverterString.lower($0) }
1986
+ uniffiTraitInterfaceCall(
1987
+ callStatus: uniffiCallStatus,
1988
+ makeCall: makeCall,
1989
+ writeReturn: writeReturn
1990
+ )
1991
+ },
1992
+ forget: { (
1993
+ uniffiHandle: UInt64,
1994
+ key: RustBuffer,
1995
+ uniffiOutReturn: UnsafeMutablePointer<RustBuffer>,
1996
+ uniffiCallStatus: UnsafeMutablePointer<RustCallStatus>
1997
+ ) in
1998
+ let makeCall = {
1999
+ () throws -> String in
2000
+ guard let uniffiObj = try? FfiConverterCallbackInterfaceMemoryProvider.handleMap.get(handle: uniffiHandle) else {
2001
+ throw UniffiInternalError.unexpectedStaleHandle
2002
+ }
2003
+ return uniffiObj.forget(
2004
+ key: try FfiConverterString.lift(key)
2005
+ )
2006
+ }
2007
+
2008
+
2009
+ let writeReturn = { uniffiOutReturn.pointee = FfiConverterString.lower($0) }
2010
+ uniffiTraitInterfaceCall(
2011
+ callStatus: uniffiCallStatus,
2012
+ makeCall: makeCall,
2013
+ writeReturn: writeReturn
2014
+ )
2015
+ },
2016
+ search: { (
2017
+ uniffiHandle: UInt64,
2018
+ query: RustBuffer,
2019
+ maxResults: UInt32,
2020
+ uniffiOutReturn: UnsafeMutablePointer<RustBuffer>,
2021
+ uniffiCallStatus: UnsafeMutablePointer<RustCallStatus>
2022
+ ) in
2023
+ let makeCall = {
2024
+ () throws -> String in
2025
+ guard let uniffiObj = try? FfiConverterCallbackInterfaceMemoryProvider.handleMap.get(handle: uniffiHandle) else {
2026
+ throw UniffiInternalError.unexpectedStaleHandle
2027
+ }
2028
+ return uniffiObj.search(
2029
+ query: try FfiConverterString.lift(query),
2030
+ maxResults: try FfiConverterUInt32.lift(maxResults)
2031
+ )
2032
+ }
2033
+
2034
+
2035
+ let writeReturn = { uniffiOutReturn.pointee = FfiConverterString.lower($0) }
2036
+ uniffiTraitInterfaceCall(
2037
+ callStatus: uniffiCallStatus,
2038
+ makeCall: makeCall,
2039
+ writeReturn: writeReturn
2040
+ )
2041
+ },
2042
+ list: { (
2043
+ uniffiHandle: UInt64,
2044
+ prefix: RustBuffer,
2045
+ limit: RustBuffer,
2046
+ uniffiOutReturn: UnsafeMutablePointer<RustBuffer>,
2047
+ uniffiCallStatus: UnsafeMutablePointer<RustCallStatus>
2048
+ ) in
2049
+ let makeCall = {
2050
+ () throws -> String in
2051
+ guard let uniffiObj = try? FfiConverterCallbackInterfaceMemoryProvider.handleMap.get(handle: uniffiHandle) else {
2052
+ throw UniffiInternalError.unexpectedStaleHandle
2053
+ }
2054
+ return uniffiObj.list(
2055
+ prefix: try FfiConverterOptionString.lift(prefix),
2056
+ limit: try FfiConverterOptionUInt32.lift(limit)
2057
+ )
2058
+ }
2059
+
2060
+
2061
+ let writeReturn = { uniffiOutReturn.pointee = FfiConverterString.lower($0) }
2062
+ uniffiTraitInterfaceCall(
2063
+ callStatus: uniffiCallStatus,
2064
+ makeCall: makeCall,
2065
+ writeReturn: writeReturn
2066
+ )
2067
+ },
2068
+ uniffiFree: { (uniffiHandle: UInt64) -> () in
2069
+ let result = try? FfiConverterCallbackInterfaceMemoryProvider.handleMap.remove(handle: uniffiHandle)
2070
+ if result == nil {
2071
+ print("Uniffi callback interface MemoryProvider: handle missing in uniffiFree")
2072
+ }
2073
+ }
2074
+ )
2075
+ }
2076
+
2077
+ private func uniffiCallbackInitMemoryProvider() {
2078
+ uniffi_native_agent_ffi_fn_init_callback_vtable_memoryprovider(&UniffiCallbackInterfaceMemoryProvider.vtable)
2079
+ }
2080
+
2081
+ // FfiConverter protocol for callback interfaces
2082
+ #if swift(>=5.8)
2083
+ @_documentation(visibility: private)
2084
+ #endif
2085
+ fileprivate struct FfiConverterCallbackInterfaceMemoryProvider {
2086
+ fileprivate static var handleMap = UniffiHandleMap<MemoryProvider>()
2087
+ }
2088
+
2089
+ #if swift(>=5.8)
2090
+ @_documentation(visibility: private)
2091
+ #endif
2092
+ extension FfiConverterCallbackInterfaceMemoryProvider : FfiConverter {
2093
+ typealias SwiftType = MemoryProvider
2094
+ typealias FfiType = UInt64
2095
+
2096
+ #if swift(>=5.8)
2097
+ @_documentation(visibility: private)
2098
+ #endif
2099
+ public static func lift(_ handle: UInt64) throws -> SwiftType {
2100
+ try handleMap.get(handle: handle)
2101
+ }
2102
+
2103
+ #if swift(>=5.8)
2104
+ @_documentation(visibility: private)
2105
+ #endif
2106
+ public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> SwiftType {
2107
+ let handle: UInt64 = try readInt(&buf)
2108
+ return try lift(handle)
2109
+ }
2110
+
2111
+ #if swift(>=5.8)
2112
+ @_documentation(visibility: private)
2113
+ #endif
2114
+ public static func lower(_ v: SwiftType) -> UInt64 {
2115
+ return handleMap.insert(obj: v)
2116
+ }
2117
+
2118
+ #if swift(>=5.8)
2119
+ @_documentation(visibility: private)
2120
+ #endif
2121
+ public static func write(_ v: SwiftType, into buf: inout [UInt8]) {
2122
+ writeInt(&buf, lower(v))
2123
+ }
2124
+ }
2125
+
2126
+
2127
+
2128
+
2129
+ /**
2130
+ * Callback interface for events from the native agent.
2131
+ */
2132
+ public protocol NativeEventCallback : AnyObject {
2133
+
2134
+ /**
2135
+ * Called when the agent emits an event.
2136
+ * `event_type`: text_delta, tool_use, tool_result, agent.completed, agent.error, etc.
2137
+ * `payload_json`: JSON-encoded event data.
2138
+ */
2139
+ func onEvent(eventType: String, payloadJson: String)
2140
+
2141
+ }
2142
+
2143
+
2144
+
2145
+ // Put the implementation in a struct so we don't pollute the top-level namespace
2146
+ fileprivate struct UniffiCallbackInterfaceNativeEventCallback {
2147
+
2148
+ // Create the VTable using a series of closures.
2149
+ // Swift automatically converts these into C callback functions.
2150
+ static var vtable: UniffiVTableCallbackInterfaceNativeEventCallback = UniffiVTableCallbackInterfaceNativeEventCallback(
2151
+ onEvent: { (
2152
+ uniffiHandle: UInt64,
2153
+ eventType: RustBuffer,
2154
+ payloadJson: RustBuffer,
2155
+ uniffiOutReturn: UnsafeMutableRawPointer,
2156
+ uniffiCallStatus: UnsafeMutablePointer<RustCallStatus>
2157
+ ) in
2158
+ let makeCall = {
2159
+ () throws -> () in
2160
+ guard let uniffiObj = try? FfiConverterCallbackInterfaceNativeEventCallback.handleMap.get(handle: uniffiHandle) else {
2161
+ throw UniffiInternalError.unexpectedStaleHandle
2162
+ }
2163
+ return uniffiObj.onEvent(
2164
+ eventType: try FfiConverterString.lift(eventType),
2165
+ payloadJson: try FfiConverterString.lift(payloadJson)
2166
+ )
2167
+ }
2168
+
2169
+
2170
+ let writeReturn = { () }
2171
+ uniffiTraitInterfaceCall(
2172
+ callStatus: uniffiCallStatus,
2173
+ makeCall: makeCall,
2174
+ writeReturn: writeReturn
2175
+ )
2176
+ },
2177
+ uniffiFree: { (uniffiHandle: UInt64) -> () in
2178
+ let result = try? FfiConverterCallbackInterfaceNativeEventCallback.handleMap.remove(handle: uniffiHandle)
2179
+ if result == nil {
2180
+ print("Uniffi callback interface NativeEventCallback: handle missing in uniffiFree")
2181
+ }
2182
+ }
2183
+ )
2184
+ }
2185
+
2186
+ private func uniffiCallbackInitNativeEventCallback() {
2187
+ uniffi_native_agent_ffi_fn_init_callback_vtable_nativeeventcallback(&UniffiCallbackInterfaceNativeEventCallback.vtable)
2188
+ }
2189
+
2190
+ // FfiConverter protocol for callback interfaces
2191
+ #if swift(>=5.8)
2192
+ @_documentation(visibility: private)
2193
+ #endif
2194
+ fileprivate struct FfiConverterCallbackInterfaceNativeEventCallback {
2195
+ fileprivate static var handleMap = UniffiHandleMap<NativeEventCallback>()
2196
+ }
2197
+
2198
+ #if swift(>=5.8)
2199
+ @_documentation(visibility: private)
2200
+ #endif
2201
+ extension FfiConverterCallbackInterfaceNativeEventCallback : FfiConverter {
2202
+ typealias SwiftType = NativeEventCallback
2203
+ typealias FfiType = UInt64
2204
+
2205
+ #if swift(>=5.8)
2206
+ @_documentation(visibility: private)
2207
+ #endif
2208
+ public static func lift(_ handle: UInt64) throws -> SwiftType {
2209
+ try handleMap.get(handle: handle)
2210
+ }
2211
+
2212
+ #if swift(>=5.8)
2213
+ @_documentation(visibility: private)
2214
+ #endif
2215
+ public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> SwiftType {
2216
+ let handle: UInt64 = try readInt(&buf)
2217
+ return try lift(handle)
2218
+ }
2219
+
2220
+ #if swift(>=5.8)
2221
+ @_documentation(visibility: private)
2222
+ #endif
2223
+ public static func lower(_ v: SwiftType) -> UInt64 {
2224
+ return handleMap.insert(obj: v)
2225
+ }
2226
+
2227
+ #if swift(>=5.8)
2228
+ @_documentation(visibility: private)
2229
+ #endif
2230
+ public static func write(_ v: SwiftType, into buf: inout [UInt8]) {
2231
+ writeInt(&buf, lower(v))
2232
+ }
2233
+ }
2234
+
2235
+
2236
+
2237
+
2238
+ /**
2239
+ * Callback interface for platform-native notification delivery.
2240
+ */
2241
+ public protocol NativeNotifier : AnyObject {
2242
+
2243
+ func sendNotification(title: String, body: String, dataJson: String) -> String
2244
+
2245
+ }
2246
+
2247
+
2248
+
2249
+ // Put the implementation in a struct so we don't pollute the top-level namespace
2250
+ fileprivate struct UniffiCallbackInterfaceNativeNotifier {
2251
+
2252
+ // Create the VTable using a series of closures.
2253
+ // Swift automatically converts these into C callback functions.
2254
+ static var vtable: UniffiVTableCallbackInterfaceNativeNotifier = UniffiVTableCallbackInterfaceNativeNotifier(
2255
+ sendNotification: { (
2256
+ uniffiHandle: UInt64,
2257
+ title: RustBuffer,
2258
+ body: RustBuffer,
2259
+ dataJson: RustBuffer,
2260
+ uniffiOutReturn: UnsafeMutablePointer<RustBuffer>,
2261
+ uniffiCallStatus: UnsafeMutablePointer<RustCallStatus>
2262
+ ) in
2263
+ let makeCall = {
2264
+ () throws -> String in
2265
+ guard let uniffiObj = try? FfiConverterCallbackInterfaceNativeNotifier.handleMap.get(handle: uniffiHandle) else {
2266
+ throw UniffiInternalError.unexpectedStaleHandle
2267
+ }
2268
+ return uniffiObj.sendNotification(
2269
+ title: try FfiConverterString.lift(title),
2270
+ body: try FfiConverterString.lift(body),
2271
+ dataJson: try FfiConverterString.lift(dataJson)
2272
+ )
2273
+ }
2274
+
2275
+
2276
+ let writeReturn = { uniffiOutReturn.pointee = FfiConverterString.lower($0) }
2277
+ uniffiTraitInterfaceCall(
2278
+ callStatus: uniffiCallStatus,
2279
+ makeCall: makeCall,
2280
+ writeReturn: writeReturn
2281
+ )
2282
+ },
2283
+ uniffiFree: { (uniffiHandle: UInt64) -> () in
2284
+ let result = try? FfiConverterCallbackInterfaceNativeNotifier.handleMap.remove(handle: uniffiHandle)
2285
+ if result == nil {
2286
+ print("Uniffi callback interface NativeNotifier: handle missing in uniffiFree")
2287
+ }
2288
+ }
2289
+ )
2290
+ }
2291
+
2292
+ private func uniffiCallbackInitNativeNotifier() {
2293
+ uniffi_native_agent_ffi_fn_init_callback_vtable_nativenotifier(&UniffiCallbackInterfaceNativeNotifier.vtable)
2294
+ }
2295
+
2296
+ // FfiConverter protocol for callback interfaces
2297
+ #if swift(>=5.8)
2298
+ @_documentation(visibility: private)
2299
+ #endif
2300
+ fileprivate struct FfiConverterCallbackInterfaceNativeNotifier {
2301
+ fileprivate static var handleMap = UniffiHandleMap<NativeNotifier>()
2302
+ }
2303
+
2304
+ #if swift(>=5.8)
2305
+ @_documentation(visibility: private)
2306
+ #endif
2307
+ extension FfiConverterCallbackInterfaceNativeNotifier : FfiConverter {
2308
+ typealias SwiftType = NativeNotifier
2309
+ typealias FfiType = UInt64
2310
+
2311
+ #if swift(>=5.8)
2312
+ @_documentation(visibility: private)
2313
+ #endif
2314
+ public static func lift(_ handle: UInt64) throws -> SwiftType {
2315
+ try handleMap.get(handle: handle)
2316
+ }
2317
+
2318
+ #if swift(>=5.8)
2319
+ @_documentation(visibility: private)
2320
+ #endif
2321
+ public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> SwiftType {
2322
+ let handle: UInt64 = try readInt(&buf)
2323
+ return try lift(handle)
2324
+ }
2325
+
2326
+ #if swift(>=5.8)
2327
+ @_documentation(visibility: private)
2328
+ #endif
2329
+ public static func lower(_ v: SwiftType) -> UInt64 {
2330
+ return handleMap.insert(obj: v)
2331
+ }
2332
+
2333
+ #if swift(>=5.8)
2334
+ @_documentation(visibility: private)
2335
+ #endif
2336
+ public static func write(_ v: SwiftType, into buf: inout [UInt8]) {
2337
+ writeInt(&buf, lower(v))
2338
+ }
2339
+ }
2340
+
2341
+ #if swift(>=5.8)
2342
+ @_documentation(visibility: private)
2343
+ #endif
2344
+ fileprivate struct FfiConverterOptionUInt32: FfiConverterRustBuffer {
2345
+ typealias SwiftType = UInt32?
2346
+
2347
+ public static func write(_ value: SwiftType, into buf: inout [UInt8]) {
2348
+ guard let value = value else {
2349
+ writeInt(&buf, Int8(0))
2350
+ return
2351
+ }
2352
+ writeInt(&buf, Int8(1))
2353
+ FfiConverterUInt32.write(value, into: &buf)
2354
+ }
2355
+
2356
+ public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> SwiftType {
2357
+ switch try readInt(&buf) as Int8 {
2358
+ case 0: return nil
2359
+ case 1: return try FfiConverterUInt32.read(from: &buf)
2360
+ default: throw UniffiInternalError.unexpectedOptionalTag
2361
+ }
2362
+ }
2363
+ }
2364
+
2365
+ #if swift(>=5.8)
2366
+ @_documentation(visibility: private)
2367
+ #endif
2368
+ fileprivate struct FfiConverterOptionString: FfiConverterRustBuffer {
2369
+ typealias SwiftType = String?
2370
+
2371
+ public static func write(_ value: SwiftType, into buf: inout [UInt8]) {
2372
+ guard let value = value else {
2373
+ writeInt(&buf, Int8(0))
2374
+ return
2375
+ }
2376
+ writeInt(&buf, Int8(1))
2377
+ FfiConverterString.write(value, into: &buf)
2378
+ }
2379
+
2380
+ public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> SwiftType {
2381
+ switch try readInt(&buf) as Int8 {
2382
+ case 0: return nil
2383
+ case 1: return try FfiConverterString.read(from: &buf)
2384
+ default: throw UniffiInternalError.unexpectedOptionalTag
2385
+ }
2386
+ }
2387
+ }
2388
+ public func createHandleFromPersistedConfig(configPath: String)throws -> NativeAgentHandle {
2389
+ return try FfiConverterTypeNativeAgentHandle.lift(try rustCallWithError(FfiConverterTypeNativeAgentError.lift) {
2390
+ uniffi_native_agent_ffi_fn_func_create_handle_from_persisted_config(
2391
+ FfiConverterString.lower(configPath),$0
2392
+ )
2393
+ })
2394
+ }
2395
+ /**
2396
+ * Standalone workspace initialization for cold-start paths.
2397
+ */
2398
+ public func initWorkspace(config: InitConfig)throws {try rustCallWithError(FfiConverterTypeNativeAgentError.lift) {
2399
+ uniffi_native_agent_ffi_fn_func_init_workspace(
2400
+ FfiConverterTypeInitConfig.lower(config),$0
2401
+ )
2402
+ }
2403
+ }
2404
+
2405
+ private enum InitializationResult {
2406
+ case ok
2407
+ case contractVersionMismatch
2408
+ case apiChecksumMismatch
2409
+ }
2410
+ // Use a global variable to perform the versioning checks. Swift ensures that
2411
+ // the code inside is only computed once.
2412
+ private var initializationResult: InitializationResult = {
2413
+ // Get the bindings contract version from our ComponentInterface
2414
+ let bindings_contract_version = 26
2415
+ // Get the scaffolding contract version by calling the into the dylib
2416
+ let scaffolding_contract_version = ffi_native_agent_ffi_uniffi_contract_version()
2417
+ if bindings_contract_version != scaffolding_contract_version {
2418
+ return InitializationResult.contractVersionMismatch
2419
+ }
2420
+ if (uniffi_native_agent_ffi_checksum_func_create_handle_from_persisted_config() != 41643) {
2421
+ return InitializationResult.apiChecksumMismatch
2422
+ }
2423
+ if (uniffi_native_agent_ffi_checksum_func_init_workspace() != 39423) {
2424
+ return InitializationResult.apiChecksumMismatch
2425
+ }
2426
+ if (uniffi_native_agent_ffi_checksum_method_nativeagenthandle_abort() != 58908) {
2427
+ return InitializationResult.apiChecksumMismatch
2428
+ }
2429
+ if (uniffi_native_agent_ffi_checksum_method_nativeagenthandle_add_cron_job() != 52316) {
2430
+ return InitializationResult.apiChecksumMismatch
2431
+ }
2432
+ if (uniffi_native_agent_ffi_checksum_method_nativeagenthandle_add_skill() != 46434) {
2433
+ return InitializationResult.apiChecksumMismatch
2434
+ }
2435
+ if (uniffi_native_agent_ffi_checksum_method_nativeagenthandle_clear_session() != 28186) {
2436
+ return InitializationResult.apiChecksumMismatch
2437
+ }
2438
+ if (uniffi_native_agent_ffi_checksum_method_nativeagenthandle_delete_auth() != 2640) {
2439
+ return InitializationResult.apiChecksumMismatch
2440
+ }
2441
+ if (uniffi_native_agent_ffi_checksum_method_nativeagenthandle_end_skill() != 49984) {
2442
+ return InitializationResult.apiChecksumMismatch
2443
+ }
2444
+ if (uniffi_native_agent_ffi_checksum_method_nativeagenthandle_exchange_oauth_code() != 22859) {
2445
+ return InitializationResult.apiChecksumMismatch
2446
+ }
2447
+ if (uniffi_native_agent_ffi_checksum_method_nativeagenthandle_follow_up() != 816) {
2448
+ return InitializationResult.apiChecksumMismatch
2449
+ }
2450
+ if (uniffi_native_agent_ffi_checksum_method_nativeagenthandle_get_auth_status() != 31550) {
2451
+ return InitializationResult.apiChecksumMismatch
2452
+ }
2453
+ if (uniffi_native_agent_ffi_checksum_method_nativeagenthandle_get_auth_token() != 58380) {
2454
+ return InitializationResult.apiChecksumMismatch
2455
+ }
2456
+ if (uniffi_native_agent_ffi_checksum_method_nativeagenthandle_get_heartbeat_config() != 1627) {
2457
+ return InitializationResult.apiChecksumMismatch
2458
+ }
2459
+ if (uniffi_native_agent_ffi_checksum_method_nativeagenthandle_get_models() != 25637) {
2460
+ return InitializationResult.apiChecksumMismatch
2461
+ }
2462
+ if (uniffi_native_agent_ffi_checksum_method_nativeagenthandle_get_scheduler_config() != 3406) {
2463
+ return InitializationResult.apiChecksumMismatch
2464
+ }
2465
+ if (uniffi_native_agent_ffi_checksum_method_nativeagenthandle_handle_wake() != 29594) {
2466
+ return InitializationResult.apiChecksumMismatch
2467
+ }
2468
+ if (uniffi_native_agent_ffi_checksum_method_nativeagenthandle_invoke_tool() != 13537) {
2469
+ return InitializationResult.apiChecksumMismatch
2470
+ }
2471
+ if (uniffi_native_agent_ffi_checksum_method_nativeagenthandle_list_cron_jobs() != 44432) {
2472
+ return InitializationResult.apiChecksumMismatch
2473
+ }
2474
+ if (uniffi_native_agent_ffi_checksum_method_nativeagenthandle_list_cron_runs() != 27743) {
2475
+ return InitializationResult.apiChecksumMismatch
2476
+ }
2477
+ if (uniffi_native_agent_ffi_checksum_method_nativeagenthandle_list_sessions() != 20894) {
2478
+ return InitializationResult.apiChecksumMismatch
2479
+ }
2480
+ if (uniffi_native_agent_ffi_checksum_method_nativeagenthandle_list_skills() != 14677) {
2481
+ return InitializationResult.apiChecksumMismatch
2482
+ }
2483
+ if (uniffi_native_agent_ffi_checksum_method_nativeagenthandle_load_session() != 39832) {
2484
+ return InitializationResult.apiChecksumMismatch
2485
+ }
2486
+ if (uniffi_native_agent_ffi_checksum_method_nativeagenthandle_persist_config() != 63110) {
2487
+ return InitializationResult.apiChecksumMismatch
2488
+ }
2489
+ if (uniffi_native_agent_ffi_checksum_method_nativeagenthandle_refresh_token() != 13290) {
2490
+ return InitializationResult.apiChecksumMismatch
2491
+ }
2492
+ if (uniffi_native_agent_ffi_checksum_method_nativeagenthandle_remove_cron_job() != 55519) {
2493
+ return InitializationResult.apiChecksumMismatch
2494
+ }
2495
+ if (uniffi_native_agent_ffi_checksum_method_nativeagenthandle_remove_skill() != 49129) {
2496
+ return InitializationResult.apiChecksumMismatch
2497
+ }
2498
+ if (uniffi_native_agent_ffi_checksum_method_nativeagenthandle_respond_to_approval() != 3194) {
2499
+ return InitializationResult.apiChecksumMismatch
2500
+ }
2501
+ if (uniffi_native_agent_ffi_checksum_method_nativeagenthandle_respond_to_cron_approval() != 851) {
2502
+ return InitializationResult.apiChecksumMismatch
2503
+ }
2504
+ if (uniffi_native_agent_ffi_checksum_method_nativeagenthandle_respond_to_mcp_tool() != 10295) {
2505
+ return InitializationResult.apiChecksumMismatch
2506
+ }
2507
+ if (uniffi_native_agent_ffi_checksum_method_nativeagenthandle_restart_mcp() != 8963) {
2508
+ return InitializationResult.apiChecksumMismatch
2509
+ }
2510
+ if (uniffi_native_agent_ffi_checksum_method_nativeagenthandle_resume_session() != 34699) {
2511
+ return InitializationResult.apiChecksumMismatch
2512
+ }
2513
+ if (uniffi_native_agent_ffi_checksum_method_nativeagenthandle_run_cron_job() != 11263) {
2514
+ return InitializationResult.apiChecksumMismatch
2515
+ }
2516
+ if (uniffi_native_agent_ffi_checksum_method_nativeagenthandle_send_message() != 53296) {
2517
+ return InitializationResult.apiChecksumMismatch
2518
+ }
2519
+ if (uniffi_native_agent_ffi_checksum_method_nativeagenthandle_set_auth_key() != 40485) {
2520
+ return InitializationResult.apiChecksumMismatch
2521
+ }
2522
+ if (uniffi_native_agent_ffi_checksum_method_nativeagenthandle_set_event_callback() != 56165) {
2523
+ return InitializationResult.apiChecksumMismatch
2524
+ }
2525
+ if (uniffi_native_agent_ffi_checksum_method_nativeagenthandle_set_heartbeat_config() != 33968) {
2526
+ return InitializationResult.apiChecksumMismatch
2527
+ }
2528
+ if (uniffi_native_agent_ffi_checksum_method_nativeagenthandle_set_memory_provider() != 23171) {
2529
+ return InitializationResult.apiChecksumMismatch
2530
+ }
2531
+ if (uniffi_native_agent_ffi_checksum_method_nativeagenthandle_set_notifier() != 58795) {
2532
+ return InitializationResult.apiChecksumMismatch
2533
+ }
2534
+ if (uniffi_native_agent_ffi_checksum_method_nativeagenthandle_set_scheduler_config() != 18609) {
2535
+ return InitializationResult.apiChecksumMismatch
2536
+ }
2537
+ if (uniffi_native_agent_ffi_checksum_method_nativeagenthandle_start_mcp() != 53972) {
2538
+ return InitializationResult.apiChecksumMismatch
2539
+ }
2540
+ if (uniffi_native_agent_ffi_checksum_method_nativeagenthandle_start_skill() != 7081) {
2541
+ return InitializationResult.apiChecksumMismatch
2542
+ }
2543
+ if (uniffi_native_agent_ffi_checksum_method_nativeagenthandle_steer() != 29790) {
2544
+ return InitializationResult.apiChecksumMismatch
2545
+ }
2546
+ if (uniffi_native_agent_ffi_checksum_method_nativeagenthandle_update_cron_job() != 40127) {
2547
+ return InitializationResult.apiChecksumMismatch
2548
+ }
2549
+ if (uniffi_native_agent_ffi_checksum_method_nativeagenthandle_update_skill() != 42452) {
2550
+ return InitializationResult.apiChecksumMismatch
2551
+ }
2552
+ if (uniffi_native_agent_ffi_checksum_constructor_nativeagenthandle_new() != 18383) {
2553
+ return InitializationResult.apiChecksumMismatch
2554
+ }
2555
+ if (uniffi_native_agent_ffi_checksum_method_memoryprovider_store() != 49136) {
2556
+ return InitializationResult.apiChecksumMismatch
2557
+ }
2558
+ if (uniffi_native_agent_ffi_checksum_method_memoryprovider_recall() != 3170) {
2559
+ return InitializationResult.apiChecksumMismatch
2560
+ }
2561
+ if (uniffi_native_agent_ffi_checksum_method_memoryprovider_forget() != 43231) {
2562
+ return InitializationResult.apiChecksumMismatch
2563
+ }
2564
+ if (uniffi_native_agent_ffi_checksum_method_memoryprovider_search() != 19100) {
2565
+ return InitializationResult.apiChecksumMismatch
2566
+ }
2567
+ if (uniffi_native_agent_ffi_checksum_method_memoryprovider_list() != 46802) {
2568
+ return InitializationResult.apiChecksumMismatch
2569
+ }
2570
+ if (uniffi_native_agent_ffi_checksum_method_nativeeventcallback_on_event() != 29742) {
2571
+ return InitializationResult.apiChecksumMismatch
2572
+ }
2573
+ if (uniffi_native_agent_ffi_checksum_method_nativenotifier_send_notification() != 9573) {
2574
+ return InitializationResult.apiChecksumMismatch
2575
+ }
2576
+
2577
+ uniffiCallbackInitMemoryProvider()
2578
+ uniffiCallbackInitNativeEventCallback()
2579
+ uniffiCallbackInitNativeNotifier()
2580
+ return InitializationResult.ok
2581
+ }()
2582
+
2583
+ private func uniffiEnsureInitialized() {
2584
+ switch initializationResult {
2585
+ case .ok:
2586
+ break
2587
+ case .contractVersionMismatch:
2588
+ fatalError("UniFFI contract version mismatch: try cleaning and rebuilding your project")
2589
+ case .apiChecksumMismatch:
2590
+ fatalError("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
2591
+ }
2592
+ }
2593
+
2594
+ // swiftlint:enable all