capacitor-native-agent 0.1.2 → 0.1.3

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,2064 @@
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 session.
521
+ */
522
+ func clearSession() throws
523
+
524
+ /**
525
+ * Delete auth for a provider.
526
+ */
527
+ func deleteAuth(provider: String) throws
528
+
529
+ /**
530
+ * End a skill session.
531
+ */
532
+ func endSkill(skillId: String) throws
533
+
534
+ /**
535
+ * Follow up on the current conversation.
536
+ */
537
+ func followUp(prompt: String) throws
538
+
539
+ /**
540
+ * Get auth status (masked key).
541
+ */
542
+ func getAuthStatus(provider: String) throws -> AuthStatusResult
543
+
544
+ /**
545
+ * Get auth token for a provider.
546
+ */
547
+ func getAuthToken(provider: String) throws -> AuthTokenResult
548
+
549
+ /**
550
+ * Get heartbeat config.
551
+ */
552
+ func getHeartbeatConfig() throws -> String
553
+
554
+ /**
555
+ * Get available models for a provider.
556
+ */
557
+ func getModels(provider: String) throws -> String
558
+
559
+ /**
560
+ * Get scheduler config.
561
+ */
562
+ func getSchedulerConfig() throws -> String
563
+
564
+ /**
565
+ * Handle a wake event (evaluate due cron jobs).
566
+ */
567
+ func handleWake(source: String) throws
568
+
569
+ /**
570
+ * Invoke a tool directly.
571
+ */
572
+ func invokeTool(toolName: String, argsJson: String) throws -> String
573
+
574
+ /**
575
+ * List all cron jobs.
576
+ */
577
+ func listCronJobs() throws -> String
578
+
579
+ /**
580
+ * List cron run history.
581
+ */
582
+ func listCronRuns(jobId: String?, limit: Int64) throws -> String
583
+
584
+ /**
585
+ * List sessions for an agent.
586
+ */
587
+ func listSessions(agentId: String) throws -> String
588
+
589
+ /**
590
+ * List all cron skills.
591
+ */
592
+ func listSkills() throws -> String
593
+
594
+ /**
595
+ * Load session message history.
596
+ */
597
+ func loadSession(sessionKey: String) throws -> String
598
+
599
+ /**
600
+ * Refresh an OAuth token.
601
+ */
602
+ func refreshToken(provider: String) throws -> AuthTokenResult
603
+
604
+ /**
605
+ * Remove a cron job.
606
+ */
607
+ func removeCronJob(id: String) throws
608
+
609
+ /**
610
+ * Remove a cron skill.
611
+ */
612
+ func removeSkill(id: String) throws
613
+
614
+ /**
615
+ * Respond to a tool approval request.
616
+ */
617
+ func respondToApproval(toolCallId: String, approved: Bool, reason: String?) throws
618
+
619
+ /**
620
+ * Respond to a cron approval request.
621
+ */
622
+ func respondToCronApproval(requestId: String, approved: Bool) throws
623
+
624
+ /**
625
+ * Restart MCP server with new tools.
626
+ */
627
+ func restartMcp(toolsJson: String) throws -> UInt32
628
+
629
+ /**
630
+ * Resume a session (load messages into agent context).
631
+ */
632
+ func resumeSession(sessionKey: String, agentId: String, messagesJson: String?, provider: String?, model: String?) throws
633
+
634
+ /**
635
+ * Force-trigger a cron job.
636
+ */
637
+ func runCronJob(jobId: String) throws
638
+
639
+ /**
640
+ * Send a message to the agent and start an agent loop turn.
641
+ */
642
+ func sendMessage(params: SendMessageParams) throws -> String
643
+
644
+ /**
645
+ * Set an auth key for a provider.
646
+ */
647
+ func setAuthKey(key: String, provider: String, authType: String) throws
648
+
649
+ /**
650
+ * Set the event callback for receiving agent events.
651
+ */
652
+ func setEventCallback(callback: NativeEventCallback) throws
653
+
654
+ /**
655
+ * Set heartbeat config.
656
+ */
657
+ func setHeartbeatConfig(configJson: String) throws
658
+
659
+ /**
660
+ * Set scheduler config.
661
+ */
662
+ func setSchedulerConfig(configJson: String) throws
663
+
664
+ /**
665
+ * Start MCP server with given tools.
666
+ */
667
+ func startMcp(toolsJson: String) throws -> UInt32
668
+
669
+ /**
670
+ * Start a skill session.
671
+ */
672
+ func startSkill(skillId: String, configJson: String, provider: String?) throws -> String
673
+
674
+ /**
675
+ * Steer the running agent with additional context.
676
+ */
677
+ func steer(text: String) throws
678
+
679
+ /**
680
+ * Update a cron job.
681
+ */
682
+ func updateCronJob(id: String, patchJson: String) throws
683
+
684
+ /**
685
+ * Update a cron skill.
686
+ */
687
+ func updateSkill(id: String, patchJson: String) throws
688
+
689
+ }
690
+
691
+ /**
692
+ * Long-lived handle — one per app lifecycle.
693
+ */
694
+ open class NativeAgentHandle:
695
+ NativeAgentHandleProtocol {
696
+ fileprivate let pointer: UnsafeMutableRawPointer!
697
+
698
+ /// Used to instantiate a [FFIObject] without an actual pointer, for fakes in tests, mostly.
699
+ #if swift(>=5.8)
700
+ @_documentation(visibility: private)
701
+ #endif
702
+ public struct NoPointer {
703
+ public init() {}
704
+ }
705
+
706
+ // TODO: We'd like this to be `private` but for Swifty reasons,
707
+ // we can't implement `FfiConverter` without making this `required` and we can't
708
+ // make it `required` without making it `public`.
709
+ required public init(unsafeFromRawPointer pointer: UnsafeMutableRawPointer) {
710
+ self.pointer = pointer
711
+ }
712
+
713
+ // This constructor can be used to instantiate a fake object.
714
+ // - Parameter noPointer: Placeholder value so we can have a constructor separate from the default empty one that may be implemented for classes extending [FFIObject].
715
+ //
716
+ // - Warning:
717
+ // 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.
718
+ #if swift(>=5.8)
719
+ @_documentation(visibility: private)
720
+ #endif
721
+ public init(noPointer: NoPointer) {
722
+ self.pointer = nil
723
+ }
724
+
725
+ #if swift(>=5.8)
726
+ @_documentation(visibility: private)
727
+ #endif
728
+ public func uniffiClonePointer() -> UnsafeMutableRawPointer {
729
+ return try! rustCall { uniffi_native_agent_ffi_fn_clone_nativeagenthandle(self.pointer, $0) }
730
+ }
731
+ /**
732
+ * Create a new native agent handle.
733
+ */
734
+ public convenience init(config: InitConfig)throws {
735
+ let pointer =
736
+ try rustCallWithError(FfiConverterTypeNativeAgentError.lift) {
737
+ uniffi_native_agent_ffi_fn_constructor_nativeagenthandle_new(
738
+ FfiConverterTypeInitConfig.lower(config),$0
739
+ )
740
+ }
741
+ self.init(unsafeFromRawPointer: pointer)
742
+ }
743
+
744
+ deinit {
745
+ guard let pointer = pointer else {
746
+ return
747
+ }
748
+
749
+ try! rustCall { uniffi_native_agent_ffi_fn_free_nativeagenthandle(pointer, $0) }
750
+ }
751
+
752
+
753
+
754
+
755
+ /**
756
+ * Abort the current agent turn.
757
+ */
758
+ open func abort()throws {try rustCallWithError(FfiConverterTypeNativeAgentError.lift) {
759
+ uniffi_native_agent_ffi_fn_method_nativeagenthandle_abort(self.uniffiClonePointer(),$0
760
+ )
761
+ }
762
+ }
763
+
764
+ /**
765
+ * Add a cron job.
766
+ */
767
+ open func addCronJob(inputJson: String)throws -> String {
768
+ return try FfiConverterString.lift(try rustCallWithError(FfiConverterTypeNativeAgentError.lift) {
769
+ uniffi_native_agent_ffi_fn_method_nativeagenthandle_add_cron_job(self.uniffiClonePointer(),
770
+ FfiConverterString.lower(inputJson),$0
771
+ )
772
+ })
773
+ }
774
+
775
+ /**
776
+ * Add a cron skill.
777
+ */
778
+ open func addSkill(inputJson: String)throws -> String {
779
+ return try FfiConverterString.lift(try rustCallWithError(FfiConverterTypeNativeAgentError.lift) {
780
+ uniffi_native_agent_ffi_fn_method_nativeagenthandle_add_skill(self.uniffiClonePointer(),
781
+ FfiConverterString.lower(inputJson),$0
782
+ )
783
+ })
784
+ }
785
+
786
+ /**
787
+ * Clear the current session.
788
+ */
789
+ open func clearSession()throws {try rustCallWithError(FfiConverterTypeNativeAgentError.lift) {
790
+ uniffi_native_agent_ffi_fn_method_nativeagenthandle_clear_session(self.uniffiClonePointer(),$0
791
+ )
792
+ }
793
+ }
794
+
795
+ /**
796
+ * Delete auth for a provider.
797
+ */
798
+ open func deleteAuth(provider: String)throws {try rustCallWithError(FfiConverterTypeNativeAgentError.lift) {
799
+ uniffi_native_agent_ffi_fn_method_nativeagenthandle_delete_auth(self.uniffiClonePointer(),
800
+ FfiConverterString.lower(provider),$0
801
+ )
802
+ }
803
+ }
804
+
805
+ /**
806
+ * End a skill session.
807
+ */
808
+ open func endSkill(skillId: String)throws {try rustCallWithError(FfiConverterTypeNativeAgentError.lift) {
809
+ uniffi_native_agent_ffi_fn_method_nativeagenthandle_end_skill(self.uniffiClonePointer(),
810
+ FfiConverterString.lower(skillId),$0
811
+ )
812
+ }
813
+ }
814
+
815
+ /**
816
+ * Follow up on the current conversation.
817
+ */
818
+ open func followUp(prompt: String)throws {try rustCallWithError(FfiConverterTypeNativeAgentError.lift) {
819
+ uniffi_native_agent_ffi_fn_method_nativeagenthandle_follow_up(self.uniffiClonePointer(),
820
+ FfiConverterString.lower(prompt),$0
821
+ )
822
+ }
823
+ }
824
+
825
+ /**
826
+ * Get auth status (masked key).
827
+ */
828
+ open func getAuthStatus(provider: String)throws -> AuthStatusResult {
829
+ return try FfiConverterTypeAuthStatusResult.lift(try rustCallWithError(FfiConverterTypeNativeAgentError.lift) {
830
+ uniffi_native_agent_ffi_fn_method_nativeagenthandle_get_auth_status(self.uniffiClonePointer(),
831
+ FfiConverterString.lower(provider),$0
832
+ )
833
+ })
834
+ }
835
+
836
+ /**
837
+ * Get auth token for a provider.
838
+ */
839
+ open func getAuthToken(provider: String)throws -> AuthTokenResult {
840
+ return try FfiConverterTypeAuthTokenResult.lift(try rustCallWithError(FfiConverterTypeNativeAgentError.lift) {
841
+ uniffi_native_agent_ffi_fn_method_nativeagenthandle_get_auth_token(self.uniffiClonePointer(),
842
+ FfiConverterString.lower(provider),$0
843
+ )
844
+ })
845
+ }
846
+
847
+ /**
848
+ * Get heartbeat config.
849
+ */
850
+ open func getHeartbeatConfig()throws -> String {
851
+ return try FfiConverterString.lift(try rustCallWithError(FfiConverterTypeNativeAgentError.lift) {
852
+ uniffi_native_agent_ffi_fn_method_nativeagenthandle_get_heartbeat_config(self.uniffiClonePointer(),$0
853
+ )
854
+ })
855
+ }
856
+
857
+ /**
858
+ * Get available models for a provider.
859
+ */
860
+ open func getModels(provider: String)throws -> String {
861
+ return try FfiConverterString.lift(try rustCallWithError(FfiConverterTypeNativeAgentError.lift) {
862
+ uniffi_native_agent_ffi_fn_method_nativeagenthandle_get_models(self.uniffiClonePointer(),
863
+ FfiConverterString.lower(provider),$0
864
+ )
865
+ })
866
+ }
867
+
868
+ /**
869
+ * Get scheduler config.
870
+ */
871
+ open func getSchedulerConfig()throws -> String {
872
+ return try FfiConverterString.lift(try rustCallWithError(FfiConverterTypeNativeAgentError.lift) {
873
+ uniffi_native_agent_ffi_fn_method_nativeagenthandle_get_scheduler_config(self.uniffiClonePointer(),$0
874
+ )
875
+ })
876
+ }
877
+
878
+ /**
879
+ * Handle a wake event (evaluate due cron jobs).
880
+ */
881
+ open func handleWake(source: String)throws {try rustCallWithError(FfiConverterTypeNativeAgentError.lift) {
882
+ uniffi_native_agent_ffi_fn_method_nativeagenthandle_handle_wake(self.uniffiClonePointer(),
883
+ FfiConverterString.lower(source),$0
884
+ )
885
+ }
886
+ }
887
+
888
+ /**
889
+ * Invoke a tool directly.
890
+ */
891
+ open func invokeTool(toolName: String, argsJson: String)throws -> String {
892
+ return try FfiConverterString.lift(try rustCallWithError(FfiConverterTypeNativeAgentError.lift) {
893
+ uniffi_native_agent_ffi_fn_method_nativeagenthandle_invoke_tool(self.uniffiClonePointer(),
894
+ FfiConverterString.lower(toolName),
895
+ FfiConverterString.lower(argsJson),$0
896
+ )
897
+ })
898
+ }
899
+
900
+ /**
901
+ * List all cron jobs.
902
+ */
903
+ open func listCronJobs()throws -> String {
904
+ return try FfiConverterString.lift(try rustCallWithError(FfiConverterTypeNativeAgentError.lift) {
905
+ uniffi_native_agent_ffi_fn_method_nativeagenthandle_list_cron_jobs(self.uniffiClonePointer(),$0
906
+ )
907
+ })
908
+ }
909
+
910
+ /**
911
+ * List cron run history.
912
+ */
913
+ open func listCronRuns(jobId: String?, limit: Int64)throws -> String {
914
+ return try FfiConverterString.lift(try rustCallWithError(FfiConverterTypeNativeAgentError.lift) {
915
+ uniffi_native_agent_ffi_fn_method_nativeagenthandle_list_cron_runs(self.uniffiClonePointer(),
916
+ FfiConverterOptionString.lower(jobId),
917
+ FfiConverterInt64.lower(limit),$0
918
+ )
919
+ })
920
+ }
921
+
922
+ /**
923
+ * List sessions for an agent.
924
+ */
925
+ open func listSessions(agentId: String)throws -> String {
926
+ return try FfiConverterString.lift(try rustCallWithError(FfiConverterTypeNativeAgentError.lift) {
927
+ uniffi_native_agent_ffi_fn_method_nativeagenthandle_list_sessions(self.uniffiClonePointer(),
928
+ FfiConverterString.lower(agentId),$0
929
+ )
930
+ })
931
+ }
932
+
933
+ /**
934
+ * List all cron skills.
935
+ */
936
+ open func listSkills()throws -> String {
937
+ return try FfiConverterString.lift(try rustCallWithError(FfiConverterTypeNativeAgentError.lift) {
938
+ uniffi_native_agent_ffi_fn_method_nativeagenthandle_list_skills(self.uniffiClonePointer(),$0
939
+ )
940
+ })
941
+ }
942
+
943
+ /**
944
+ * Load session message history.
945
+ */
946
+ open func loadSession(sessionKey: String)throws -> String {
947
+ return try FfiConverterString.lift(try rustCallWithError(FfiConverterTypeNativeAgentError.lift) {
948
+ uniffi_native_agent_ffi_fn_method_nativeagenthandle_load_session(self.uniffiClonePointer(),
949
+ FfiConverterString.lower(sessionKey),$0
950
+ )
951
+ })
952
+ }
953
+
954
+ /**
955
+ * Refresh an OAuth token.
956
+ */
957
+ open func refreshToken(provider: String)throws -> AuthTokenResult {
958
+ return try FfiConverterTypeAuthTokenResult.lift(try rustCallWithError(FfiConverterTypeNativeAgentError.lift) {
959
+ uniffi_native_agent_ffi_fn_method_nativeagenthandle_refresh_token(self.uniffiClonePointer(),
960
+ FfiConverterString.lower(provider),$0
961
+ )
962
+ })
963
+ }
964
+
965
+ /**
966
+ * Remove a cron job.
967
+ */
968
+ open func removeCronJob(id: String)throws {try rustCallWithError(FfiConverterTypeNativeAgentError.lift) {
969
+ uniffi_native_agent_ffi_fn_method_nativeagenthandle_remove_cron_job(self.uniffiClonePointer(),
970
+ FfiConverterString.lower(id),$0
971
+ )
972
+ }
973
+ }
974
+
975
+ /**
976
+ * Remove a cron skill.
977
+ */
978
+ open func removeSkill(id: String)throws {try rustCallWithError(FfiConverterTypeNativeAgentError.lift) {
979
+ uniffi_native_agent_ffi_fn_method_nativeagenthandle_remove_skill(self.uniffiClonePointer(),
980
+ FfiConverterString.lower(id),$0
981
+ )
982
+ }
983
+ }
984
+
985
+ /**
986
+ * Respond to a tool approval request.
987
+ */
988
+ open func respondToApproval(toolCallId: String, approved: Bool, reason: String?)throws {try rustCallWithError(FfiConverterTypeNativeAgentError.lift) {
989
+ uniffi_native_agent_ffi_fn_method_nativeagenthandle_respond_to_approval(self.uniffiClonePointer(),
990
+ FfiConverterString.lower(toolCallId),
991
+ FfiConverterBool.lower(approved),
992
+ FfiConverterOptionString.lower(reason),$0
993
+ )
994
+ }
995
+ }
996
+
997
+ /**
998
+ * Respond to a cron approval request.
999
+ */
1000
+ open func respondToCronApproval(requestId: String, approved: Bool)throws {try rustCallWithError(FfiConverterTypeNativeAgentError.lift) {
1001
+ uniffi_native_agent_ffi_fn_method_nativeagenthandle_respond_to_cron_approval(self.uniffiClonePointer(),
1002
+ FfiConverterString.lower(requestId),
1003
+ FfiConverterBool.lower(approved),$0
1004
+ )
1005
+ }
1006
+ }
1007
+
1008
+ /**
1009
+ * Restart MCP server with new tools.
1010
+ */
1011
+ open func restartMcp(toolsJson: String)throws -> UInt32 {
1012
+ return try FfiConverterUInt32.lift(try rustCallWithError(FfiConverterTypeNativeAgentError.lift) {
1013
+ uniffi_native_agent_ffi_fn_method_nativeagenthandle_restart_mcp(self.uniffiClonePointer(),
1014
+ FfiConverterString.lower(toolsJson),$0
1015
+ )
1016
+ })
1017
+ }
1018
+
1019
+ /**
1020
+ * Resume a session (load messages into agent context).
1021
+ */
1022
+ open func resumeSession(sessionKey: String, agentId: String, messagesJson: String?, provider: String?, model: String?)throws {try rustCallWithError(FfiConverterTypeNativeAgentError.lift) {
1023
+ uniffi_native_agent_ffi_fn_method_nativeagenthandle_resume_session(self.uniffiClonePointer(),
1024
+ FfiConverterString.lower(sessionKey),
1025
+ FfiConverterString.lower(agentId),
1026
+ FfiConverterOptionString.lower(messagesJson),
1027
+ FfiConverterOptionString.lower(provider),
1028
+ FfiConverterOptionString.lower(model),$0
1029
+ )
1030
+ }
1031
+ }
1032
+
1033
+ /**
1034
+ * Force-trigger a cron job.
1035
+ */
1036
+ open func runCronJob(jobId: String)throws {try rustCallWithError(FfiConverterTypeNativeAgentError.lift) {
1037
+ uniffi_native_agent_ffi_fn_method_nativeagenthandle_run_cron_job(self.uniffiClonePointer(),
1038
+ FfiConverterString.lower(jobId),$0
1039
+ )
1040
+ }
1041
+ }
1042
+
1043
+ /**
1044
+ * Send a message to the agent and start an agent loop turn.
1045
+ */
1046
+ open func sendMessage(params: SendMessageParams)throws -> String {
1047
+ return try FfiConverterString.lift(try rustCallWithError(FfiConverterTypeNativeAgentError.lift) {
1048
+ uniffi_native_agent_ffi_fn_method_nativeagenthandle_send_message(self.uniffiClonePointer(),
1049
+ FfiConverterTypeSendMessageParams.lower(params),$0
1050
+ )
1051
+ })
1052
+ }
1053
+
1054
+ /**
1055
+ * Set an auth key for a provider.
1056
+ */
1057
+ open func setAuthKey(key: String, provider: String, authType: String)throws {try rustCallWithError(FfiConverterTypeNativeAgentError.lift) {
1058
+ uniffi_native_agent_ffi_fn_method_nativeagenthandle_set_auth_key(self.uniffiClonePointer(),
1059
+ FfiConverterString.lower(key),
1060
+ FfiConverterString.lower(provider),
1061
+ FfiConverterString.lower(authType),$0
1062
+ )
1063
+ }
1064
+ }
1065
+
1066
+ /**
1067
+ * Set the event callback for receiving agent events.
1068
+ */
1069
+ open func setEventCallback(callback: NativeEventCallback)throws {try rustCallWithError(FfiConverterTypeNativeAgentError.lift) {
1070
+ uniffi_native_agent_ffi_fn_method_nativeagenthandle_set_event_callback(self.uniffiClonePointer(),
1071
+ FfiConverterCallbackInterfaceNativeEventCallback.lower(callback),$0
1072
+ )
1073
+ }
1074
+ }
1075
+
1076
+ /**
1077
+ * Set heartbeat config.
1078
+ */
1079
+ open func setHeartbeatConfig(configJson: String)throws {try rustCallWithError(FfiConverterTypeNativeAgentError.lift) {
1080
+ uniffi_native_agent_ffi_fn_method_nativeagenthandle_set_heartbeat_config(self.uniffiClonePointer(),
1081
+ FfiConverterString.lower(configJson),$0
1082
+ )
1083
+ }
1084
+ }
1085
+
1086
+ /**
1087
+ * Set scheduler config.
1088
+ */
1089
+ open func setSchedulerConfig(configJson: String)throws {try rustCallWithError(FfiConverterTypeNativeAgentError.lift) {
1090
+ uniffi_native_agent_ffi_fn_method_nativeagenthandle_set_scheduler_config(self.uniffiClonePointer(),
1091
+ FfiConverterString.lower(configJson),$0
1092
+ )
1093
+ }
1094
+ }
1095
+
1096
+ /**
1097
+ * Start MCP server with given tools.
1098
+ */
1099
+ open func startMcp(toolsJson: String)throws -> UInt32 {
1100
+ return try FfiConverterUInt32.lift(try rustCallWithError(FfiConverterTypeNativeAgentError.lift) {
1101
+ uniffi_native_agent_ffi_fn_method_nativeagenthandle_start_mcp(self.uniffiClonePointer(),
1102
+ FfiConverterString.lower(toolsJson),$0
1103
+ )
1104
+ })
1105
+ }
1106
+
1107
+ /**
1108
+ * Start a skill session.
1109
+ */
1110
+ open func startSkill(skillId: String, configJson: String, provider: String?)throws -> String {
1111
+ return try FfiConverterString.lift(try rustCallWithError(FfiConverterTypeNativeAgentError.lift) {
1112
+ uniffi_native_agent_ffi_fn_method_nativeagenthandle_start_skill(self.uniffiClonePointer(),
1113
+ FfiConverterString.lower(skillId),
1114
+ FfiConverterString.lower(configJson),
1115
+ FfiConverterOptionString.lower(provider),$0
1116
+ )
1117
+ })
1118
+ }
1119
+
1120
+ /**
1121
+ * Steer the running agent with additional context.
1122
+ */
1123
+ open func steer(text: String)throws {try rustCallWithError(FfiConverterTypeNativeAgentError.lift) {
1124
+ uniffi_native_agent_ffi_fn_method_nativeagenthandle_steer(self.uniffiClonePointer(),
1125
+ FfiConverterString.lower(text),$0
1126
+ )
1127
+ }
1128
+ }
1129
+
1130
+ /**
1131
+ * Update a cron job.
1132
+ */
1133
+ open func updateCronJob(id: String, patchJson: String)throws {try rustCallWithError(FfiConverterTypeNativeAgentError.lift) {
1134
+ uniffi_native_agent_ffi_fn_method_nativeagenthandle_update_cron_job(self.uniffiClonePointer(),
1135
+ FfiConverterString.lower(id),
1136
+ FfiConverterString.lower(patchJson),$0
1137
+ )
1138
+ }
1139
+ }
1140
+
1141
+ /**
1142
+ * Update a cron skill.
1143
+ */
1144
+ open func updateSkill(id: String, patchJson: String)throws {try rustCallWithError(FfiConverterTypeNativeAgentError.lift) {
1145
+ uniffi_native_agent_ffi_fn_method_nativeagenthandle_update_skill(self.uniffiClonePointer(),
1146
+ FfiConverterString.lower(id),
1147
+ FfiConverterString.lower(patchJson),$0
1148
+ )
1149
+ }
1150
+ }
1151
+
1152
+
1153
+ }
1154
+
1155
+ #if swift(>=5.8)
1156
+ @_documentation(visibility: private)
1157
+ #endif
1158
+ public struct FfiConverterTypeNativeAgentHandle: FfiConverter {
1159
+
1160
+ typealias FfiType = UnsafeMutableRawPointer
1161
+ typealias SwiftType = NativeAgentHandle
1162
+
1163
+ public static func lift(_ pointer: UnsafeMutableRawPointer) throws -> NativeAgentHandle {
1164
+ return NativeAgentHandle(unsafeFromRawPointer: pointer)
1165
+ }
1166
+
1167
+ public static func lower(_ value: NativeAgentHandle) -> UnsafeMutableRawPointer {
1168
+ return value.uniffiClonePointer()
1169
+ }
1170
+
1171
+ public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> NativeAgentHandle {
1172
+ let v: UInt64 = try readInt(&buf)
1173
+ // The Rust code won't compile if a pointer won't fit in a UInt64.
1174
+ // We have to go via `UInt` because that's the thing that's the size of a pointer.
1175
+ let ptr = UnsafeMutableRawPointer(bitPattern: UInt(truncatingIfNeeded: v))
1176
+ if (ptr == nil) {
1177
+ throw UniffiInternalError.unexpectedNullPointer
1178
+ }
1179
+ return try lift(ptr!)
1180
+ }
1181
+
1182
+ public static func write(_ value: NativeAgentHandle, into buf: inout [UInt8]) {
1183
+ // This fiddling is because `Int` is the thing that's the same size as a pointer.
1184
+ // The Rust code won't compile if a pointer won't fit in a `UInt64`.
1185
+ writeInt(&buf, UInt64(bitPattern: Int64(Int(bitPattern: lower(value)))))
1186
+ }
1187
+ }
1188
+
1189
+
1190
+
1191
+
1192
+ #if swift(>=5.8)
1193
+ @_documentation(visibility: private)
1194
+ #endif
1195
+ public func FfiConverterTypeNativeAgentHandle_lift(_ pointer: UnsafeMutableRawPointer) throws -> NativeAgentHandle {
1196
+ return try FfiConverterTypeNativeAgentHandle.lift(pointer)
1197
+ }
1198
+
1199
+ #if swift(>=5.8)
1200
+ @_documentation(visibility: private)
1201
+ #endif
1202
+ public func FfiConverterTypeNativeAgentHandle_lower(_ value: NativeAgentHandle) -> UnsafeMutableRawPointer {
1203
+ return FfiConverterTypeNativeAgentHandle.lower(value)
1204
+ }
1205
+
1206
+
1207
+ /**
1208
+ * Auth status result.
1209
+ */
1210
+ public struct AuthStatusResult {
1211
+ public var hasKey: Bool
1212
+ public var masked: String
1213
+ public var provider: String
1214
+
1215
+ // Default memberwise initializers are never public by default, so we
1216
+ // declare one manually.
1217
+ public init(hasKey: Bool, masked: String, provider: String) {
1218
+ self.hasKey = hasKey
1219
+ self.masked = masked
1220
+ self.provider = provider
1221
+ }
1222
+ }
1223
+
1224
+
1225
+
1226
+ extension AuthStatusResult: Equatable, Hashable {
1227
+ public static func ==(lhs: AuthStatusResult, rhs: AuthStatusResult) -> Bool {
1228
+ if lhs.hasKey != rhs.hasKey {
1229
+ return false
1230
+ }
1231
+ if lhs.masked != rhs.masked {
1232
+ return false
1233
+ }
1234
+ if lhs.provider != rhs.provider {
1235
+ return false
1236
+ }
1237
+ return true
1238
+ }
1239
+
1240
+ public func hash(into hasher: inout Hasher) {
1241
+ hasher.combine(hasKey)
1242
+ hasher.combine(masked)
1243
+ hasher.combine(provider)
1244
+ }
1245
+ }
1246
+
1247
+
1248
+ #if swift(>=5.8)
1249
+ @_documentation(visibility: private)
1250
+ #endif
1251
+ public struct FfiConverterTypeAuthStatusResult: FfiConverterRustBuffer {
1252
+ public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> AuthStatusResult {
1253
+ return
1254
+ try AuthStatusResult(
1255
+ hasKey: FfiConverterBool.read(from: &buf),
1256
+ masked: FfiConverterString.read(from: &buf),
1257
+ provider: FfiConverterString.read(from: &buf)
1258
+ )
1259
+ }
1260
+
1261
+ public static func write(_ value: AuthStatusResult, into buf: inout [UInt8]) {
1262
+ FfiConverterBool.write(value.hasKey, into: &buf)
1263
+ FfiConverterString.write(value.masked, into: &buf)
1264
+ FfiConverterString.write(value.provider, into: &buf)
1265
+ }
1266
+ }
1267
+
1268
+
1269
+ #if swift(>=5.8)
1270
+ @_documentation(visibility: private)
1271
+ #endif
1272
+ public func FfiConverterTypeAuthStatusResult_lift(_ buf: RustBuffer) throws -> AuthStatusResult {
1273
+ return try FfiConverterTypeAuthStatusResult.lift(buf)
1274
+ }
1275
+
1276
+ #if swift(>=5.8)
1277
+ @_documentation(visibility: private)
1278
+ #endif
1279
+ public func FfiConverterTypeAuthStatusResult_lower(_ value: AuthStatusResult) -> RustBuffer {
1280
+ return FfiConverterTypeAuthStatusResult.lower(value)
1281
+ }
1282
+
1283
+
1284
+ /**
1285
+ * Auth token result.
1286
+ */
1287
+ public struct AuthTokenResult {
1288
+ public var apiKey: String?
1289
+ public var isOauth: Bool
1290
+
1291
+ // Default memberwise initializers are never public by default, so we
1292
+ // declare one manually.
1293
+ public init(apiKey: String?, isOauth: Bool) {
1294
+ self.apiKey = apiKey
1295
+ self.isOauth = isOauth
1296
+ }
1297
+ }
1298
+
1299
+
1300
+
1301
+ extension AuthTokenResult: Equatable, Hashable {
1302
+ public static func ==(lhs: AuthTokenResult, rhs: AuthTokenResult) -> Bool {
1303
+ if lhs.apiKey != rhs.apiKey {
1304
+ return false
1305
+ }
1306
+ if lhs.isOauth != rhs.isOauth {
1307
+ return false
1308
+ }
1309
+ return true
1310
+ }
1311
+
1312
+ public func hash(into hasher: inout Hasher) {
1313
+ hasher.combine(apiKey)
1314
+ hasher.combine(isOauth)
1315
+ }
1316
+ }
1317
+
1318
+
1319
+ #if swift(>=5.8)
1320
+ @_documentation(visibility: private)
1321
+ #endif
1322
+ public struct FfiConverterTypeAuthTokenResult: FfiConverterRustBuffer {
1323
+ public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> AuthTokenResult {
1324
+ return
1325
+ try AuthTokenResult(
1326
+ apiKey: FfiConverterOptionString.read(from: &buf),
1327
+ isOauth: FfiConverterBool.read(from: &buf)
1328
+ )
1329
+ }
1330
+
1331
+ public static func write(_ value: AuthTokenResult, into buf: inout [UInt8]) {
1332
+ FfiConverterOptionString.write(value.apiKey, into: &buf)
1333
+ FfiConverterBool.write(value.isOauth, into: &buf)
1334
+ }
1335
+ }
1336
+
1337
+
1338
+ #if swift(>=5.8)
1339
+ @_documentation(visibility: private)
1340
+ #endif
1341
+ public func FfiConverterTypeAuthTokenResult_lift(_ buf: RustBuffer) throws -> AuthTokenResult {
1342
+ return try FfiConverterTypeAuthTokenResult.lift(buf)
1343
+ }
1344
+
1345
+ #if swift(>=5.8)
1346
+ @_documentation(visibility: private)
1347
+ #endif
1348
+ public func FfiConverterTypeAuthTokenResult_lower(_ value: AuthTokenResult) -> RustBuffer {
1349
+ return FfiConverterTypeAuthTokenResult.lower(value)
1350
+ }
1351
+
1352
+
1353
+ /**
1354
+ * Configuration for initializing the native agent handle.
1355
+ */
1356
+ public struct InitConfig {
1357
+ /**
1358
+ * Path to the SQLite database.
1359
+ */
1360
+ public var dbPath: String
1361
+ /**
1362
+ * Path to the workspace root.
1363
+ */
1364
+ public var workspacePath: String
1365
+ /**
1366
+ * Path to auth-profiles.json.
1367
+ */
1368
+ public var authProfilesPath: String
1369
+
1370
+ // Default memberwise initializers are never public by default, so we
1371
+ // declare one manually.
1372
+ public init(
1373
+ /**
1374
+ * Path to the SQLite database.
1375
+ */dbPath: String,
1376
+ /**
1377
+ * Path to the workspace root.
1378
+ */workspacePath: String,
1379
+ /**
1380
+ * Path to auth-profiles.json.
1381
+ */authProfilesPath: String) {
1382
+ self.dbPath = dbPath
1383
+ self.workspacePath = workspacePath
1384
+ self.authProfilesPath = authProfilesPath
1385
+ }
1386
+ }
1387
+
1388
+
1389
+
1390
+ extension InitConfig: Equatable, Hashable {
1391
+ public static func ==(lhs: InitConfig, rhs: InitConfig) -> Bool {
1392
+ if lhs.dbPath != rhs.dbPath {
1393
+ return false
1394
+ }
1395
+ if lhs.workspacePath != rhs.workspacePath {
1396
+ return false
1397
+ }
1398
+ if lhs.authProfilesPath != rhs.authProfilesPath {
1399
+ return false
1400
+ }
1401
+ return true
1402
+ }
1403
+
1404
+ public func hash(into hasher: inout Hasher) {
1405
+ hasher.combine(dbPath)
1406
+ hasher.combine(workspacePath)
1407
+ hasher.combine(authProfilesPath)
1408
+ }
1409
+ }
1410
+
1411
+
1412
+ #if swift(>=5.8)
1413
+ @_documentation(visibility: private)
1414
+ #endif
1415
+ public struct FfiConverterTypeInitConfig: FfiConverterRustBuffer {
1416
+ public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> InitConfig {
1417
+ return
1418
+ try InitConfig(
1419
+ dbPath: FfiConverterString.read(from: &buf),
1420
+ workspacePath: FfiConverterString.read(from: &buf),
1421
+ authProfilesPath: FfiConverterString.read(from: &buf)
1422
+ )
1423
+ }
1424
+
1425
+ public static func write(_ value: InitConfig, into buf: inout [UInt8]) {
1426
+ FfiConverterString.write(value.dbPath, into: &buf)
1427
+ FfiConverterString.write(value.workspacePath, into: &buf)
1428
+ FfiConverterString.write(value.authProfilesPath, into: &buf)
1429
+ }
1430
+ }
1431
+
1432
+
1433
+ #if swift(>=5.8)
1434
+ @_documentation(visibility: private)
1435
+ #endif
1436
+ public func FfiConverterTypeInitConfig_lift(_ buf: RustBuffer) throws -> InitConfig {
1437
+ return try FfiConverterTypeInitConfig.lift(buf)
1438
+ }
1439
+
1440
+ #if swift(>=5.8)
1441
+ @_documentation(visibility: private)
1442
+ #endif
1443
+ public func FfiConverterTypeInitConfig_lower(_ value: InitConfig) -> RustBuffer {
1444
+ return FfiConverterTypeInitConfig.lower(value)
1445
+ }
1446
+
1447
+
1448
+ /**
1449
+ * Parameters for sending a message.
1450
+ */
1451
+ public struct SendMessageParams {
1452
+ public var prompt: String
1453
+ public var sessionKey: String
1454
+ public var model: String?
1455
+ public var provider: String?
1456
+ public var systemPrompt: String
1457
+ public var maxTurns: UInt32?
1458
+ /**
1459
+ * JSON-encoded list of allowed tool names. Empty = all tools.
1460
+ */
1461
+ public var allowedToolsJson: String?
1462
+
1463
+ // Default memberwise initializers are never public by default, so we
1464
+ // declare one manually.
1465
+ public init(prompt: String, sessionKey: String, model: String?, provider: String?, systemPrompt: String, maxTurns: UInt32?,
1466
+ /**
1467
+ * JSON-encoded list of allowed tool names. Empty = all tools.
1468
+ */allowedToolsJson: String?) {
1469
+ self.prompt = prompt
1470
+ self.sessionKey = sessionKey
1471
+ self.model = model
1472
+ self.provider = provider
1473
+ self.systemPrompt = systemPrompt
1474
+ self.maxTurns = maxTurns
1475
+ self.allowedToolsJson = allowedToolsJson
1476
+ }
1477
+ }
1478
+
1479
+
1480
+
1481
+ extension SendMessageParams: Equatable, Hashable {
1482
+ public static func ==(lhs: SendMessageParams, rhs: SendMessageParams) -> Bool {
1483
+ if lhs.prompt != rhs.prompt {
1484
+ return false
1485
+ }
1486
+ if lhs.sessionKey != rhs.sessionKey {
1487
+ return false
1488
+ }
1489
+ if lhs.model != rhs.model {
1490
+ return false
1491
+ }
1492
+ if lhs.provider != rhs.provider {
1493
+ return false
1494
+ }
1495
+ if lhs.systemPrompt != rhs.systemPrompt {
1496
+ return false
1497
+ }
1498
+ if lhs.maxTurns != rhs.maxTurns {
1499
+ return false
1500
+ }
1501
+ if lhs.allowedToolsJson != rhs.allowedToolsJson {
1502
+ return false
1503
+ }
1504
+ return true
1505
+ }
1506
+
1507
+ public func hash(into hasher: inout Hasher) {
1508
+ hasher.combine(prompt)
1509
+ hasher.combine(sessionKey)
1510
+ hasher.combine(model)
1511
+ hasher.combine(provider)
1512
+ hasher.combine(systemPrompt)
1513
+ hasher.combine(maxTurns)
1514
+ hasher.combine(allowedToolsJson)
1515
+ }
1516
+ }
1517
+
1518
+
1519
+ #if swift(>=5.8)
1520
+ @_documentation(visibility: private)
1521
+ #endif
1522
+ public struct FfiConverterTypeSendMessageParams: FfiConverterRustBuffer {
1523
+ public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> SendMessageParams {
1524
+ return
1525
+ try SendMessageParams(
1526
+ prompt: FfiConverterString.read(from: &buf),
1527
+ sessionKey: FfiConverterString.read(from: &buf),
1528
+ model: FfiConverterOptionString.read(from: &buf),
1529
+ provider: FfiConverterOptionString.read(from: &buf),
1530
+ systemPrompt: FfiConverterString.read(from: &buf),
1531
+ maxTurns: FfiConverterOptionUInt32.read(from: &buf),
1532
+ allowedToolsJson: FfiConverterOptionString.read(from: &buf)
1533
+ )
1534
+ }
1535
+
1536
+ public static func write(_ value: SendMessageParams, into buf: inout [UInt8]) {
1537
+ FfiConverterString.write(value.prompt, into: &buf)
1538
+ FfiConverterString.write(value.sessionKey, into: &buf)
1539
+ FfiConverterOptionString.write(value.model, into: &buf)
1540
+ FfiConverterOptionString.write(value.provider, into: &buf)
1541
+ FfiConverterString.write(value.systemPrompt, into: &buf)
1542
+ FfiConverterOptionUInt32.write(value.maxTurns, into: &buf)
1543
+ FfiConverterOptionString.write(value.allowedToolsJson, into: &buf)
1544
+ }
1545
+ }
1546
+
1547
+
1548
+ #if swift(>=5.8)
1549
+ @_documentation(visibility: private)
1550
+ #endif
1551
+ public func FfiConverterTypeSendMessageParams_lift(_ buf: RustBuffer) throws -> SendMessageParams {
1552
+ return try FfiConverterTypeSendMessageParams.lift(buf)
1553
+ }
1554
+
1555
+ #if swift(>=5.8)
1556
+ @_documentation(visibility: private)
1557
+ #endif
1558
+ public func FfiConverterTypeSendMessageParams_lower(_ value: SendMessageParams) -> RustBuffer {
1559
+ return FfiConverterTypeSendMessageParams.lower(value)
1560
+ }
1561
+
1562
+
1563
+ /**
1564
+ * Token usage from an agent turn.
1565
+ */
1566
+ public struct TokenUsage {
1567
+ public var inputTokens: UInt32
1568
+ public var outputTokens: UInt32
1569
+ public var totalTokens: UInt32
1570
+
1571
+ // Default memberwise initializers are never public by default, so we
1572
+ // declare one manually.
1573
+ public init(inputTokens: UInt32, outputTokens: UInt32, totalTokens: UInt32) {
1574
+ self.inputTokens = inputTokens
1575
+ self.outputTokens = outputTokens
1576
+ self.totalTokens = totalTokens
1577
+ }
1578
+ }
1579
+
1580
+
1581
+
1582
+ extension TokenUsage: Equatable, Hashable {
1583
+ public static func ==(lhs: TokenUsage, rhs: TokenUsage) -> Bool {
1584
+ if lhs.inputTokens != rhs.inputTokens {
1585
+ return false
1586
+ }
1587
+ if lhs.outputTokens != rhs.outputTokens {
1588
+ return false
1589
+ }
1590
+ if lhs.totalTokens != rhs.totalTokens {
1591
+ return false
1592
+ }
1593
+ return true
1594
+ }
1595
+
1596
+ public func hash(into hasher: inout Hasher) {
1597
+ hasher.combine(inputTokens)
1598
+ hasher.combine(outputTokens)
1599
+ hasher.combine(totalTokens)
1600
+ }
1601
+ }
1602
+
1603
+
1604
+ #if swift(>=5.8)
1605
+ @_documentation(visibility: private)
1606
+ #endif
1607
+ public struct FfiConverterTypeTokenUsage: FfiConverterRustBuffer {
1608
+ public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> TokenUsage {
1609
+ return
1610
+ try TokenUsage(
1611
+ inputTokens: FfiConverterUInt32.read(from: &buf),
1612
+ outputTokens: FfiConverterUInt32.read(from: &buf),
1613
+ totalTokens: FfiConverterUInt32.read(from: &buf)
1614
+ )
1615
+ }
1616
+
1617
+ public static func write(_ value: TokenUsage, into buf: inout [UInt8]) {
1618
+ FfiConverterUInt32.write(value.inputTokens, into: &buf)
1619
+ FfiConverterUInt32.write(value.outputTokens, into: &buf)
1620
+ FfiConverterUInt32.write(value.totalTokens, into: &buf)
1621
+ }
1622
+ }
1623
+
1624
+
1625
+ #if swift(>=5.8)
1626
+ @_documentation(visibility: private)
1627
+ #endif
1628
+ public func FfiConverterTypeTokenUsage_lift(_ buf: RustBuffer) throws -> TokenUsage {
1629
+ return try FfiConverterTypeTokenUsage.lift(buf)
1630
+ }
1631
+
1632
+ #if swift(>=5.8)
1633
+ @_documentation(visibility: private)
1634
+ #endif
1635
+ public func FfiConverterTypeTokenUsage_lower(_ value: TokenUsage) -> RustBuffer {
1636
+ return FfiConverterTypeTokenUsage.lower(value)
1637
+ }
1638
+
1639
+
1640
+ /**
1641
+ * Top-level error type exposed via UniFFI.
1642
+ */
1643
+ public enum NativeAgentError {
1644
+
1645
+
1646
+
1647
+ case Agent(msg: String
1648
+ )
1649
+ case Auth(msg: String
1650
+ )
1651
+ case Database(msg: String
1652
+ )
1653
+ case Llm(msg: String
1654
+ )
1655
+ case Tool(msg: String
1656
+ )
1657
+ case Io(msg: String
1658
+ )
1659
+ case Cancelled
1660
+ }
1661
+
1662
+
1663
+ #if swift(>=5.8)
1664
+ @_documentation(visibility: private)
1665
+ #endif
1666
+ public struct FfiConverterTypeNativeAgentError: FfiConverterRustBuffer {
1667
+ typealias SwiftType = NativeAgentError
1668
+
1669
+ public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> NativeAgentError {
1670
+ let variant: Int32 = try readInt(&buf)
1671
+ switch variant {
1672
+
1673
+
1674
+
1675
+
1676
+ case 1: return .Agent(
1677
+ msg: try FfiConverterString.read(from: &buf)
1678
+ )
1679
+ case 2: return .Auth(
1680
+ msg: try FfiConverterString.read(from: &buf)
1681
+ )
1682
+ case 3: return .Database(
1683
+ msg: try FfiConverterString.read(from: &buf)
1684
+ )
1685
+ case 4: return .Llm(
1686
+ msg: try FfiConverterString.read(from: &buf)
1687
+ )
1688
+ case 5: return .Tool(
1689
+ msg: try FfiConverterString.read(from: &buf)
1690
+ )
1691
+ case 6: return .Io(
1692
+ msg: try FfiConverterString.read(from: &buf)
1693
+ )
1694
+ case 7: return .Cancelled
1695
+
1696
+ default: throw UniffiInternalError.unexpectedEnumCase
1697
+ }
1698
+ }
1699
+
1700
+ public static func write(_ value: NativeAgentError, into buf: inout [UInt8]) {
1701
+ switch value {
1702
+
1703
+
1704
+
1705
+
1706
+
1707
+ case let .Agent(msg):
1708
+ writeInt(&buf, Int32(1))
1709
+ FfiConverterString.write(msg, into: &buf)
1710
+
1711
+
1712
+ case let .Auth(msg):
1713
+ writeInt(&buf, Int32(2))
1714
+ FfiConverterString.write(msg, into: &buf)
1715
+
1716
+
1717
+ case let .Database(msg):
1718
+ writeInt(&buf, Int32(3))
1719
+ FfiConverterString.write(msg, into: &buf)
1720
+
1721
+
1722
+ case let .Llm(msg):
1723
+ writeInt(&buf, Int32(4))
1724
+ FfiConverterString.write(msg, into: &buf)
1725
+
1726
+
1727
+ case let .Tool(msg):
1728
+ writeInt(&buf, Int32(5))
1729
+ FfiConverterString.write(msg, into: &buf)
1730
+
1731
+
1732
+ case let .Io(msg):
1733
+ writeInt(&buf, Int32(6))
1734
+ FfiConverterString.write(msg, into: &buf)
1735
+
1736
+
1737
+ case .Cancelled:
1738
+ writeInt(&buf, Int32(7))
1739
+
1740
+ }
1741
+ }
1742
+ }
1743
+
1744
+
1745
+ extension NativeAgentError: Equatable, Hashable {}
1746
+
1747
+ extension NativeAgentError: Foundation.LocalizedError {
1748
+ public var errorDescription: String? {
1749
+ String(reflecting: self)
1750
+ }
1751
+ }
1752
+
1753
+
1754
+
1755
+
1756
+ /**
1757
+ * Callback interface for events from the native agent.
1758
+ */
1759
+ public protocol NativeEventCallback : AnyObject {
1760
+
1761
+ /**
1762
+ * Called when the agent emits an event.
1763
+ * `event_type`: text_delta, tool_use, tool_result, agent.completed, agent.error, etc.
1764
+ * `payload_json`: JSON-encoded event data.
1765
+ */
1766
+ func onEvent(eventType: String, payloadJson: String)
1767
+
1768
+ }
1769
+
1770
+ // Magic number for the Rust proxy to call using the same mechanism as every other method,
1771
+ // to free the callback once it's dropped by Rust.
1772
+ private let IDX_CALLBACK_FREE: Int32 = 0
1773
+ // Callback return codes
1774
+ private let UNIFFI_CALLBACK_SUCCESS: Int32 = 0
1775
+ private let UNIFFI_CALLBACK_ERROR: Int32 = 1
1776
+ private let UNIFFI_CALLBACK_UNEXPECTED_ERROR: Int32 = 2
1777
+
1778
+ // Put the implementation in a struct so we don't pollute the top-level namespace
1779
+ fileprivate struct UniffiCallbackInterfaceNativeEventCallback {
1780
+
1781
+ // Create the VTable using a series of closures.
1782
+ // Swift automatically converts these into C callback functions.
1783
+ static var vtable: UniffiVTableCallbackInterfaceNativeEventCallback = UniffiVTableCallbackInterfaceNativeEventCallback(
1784
+ onEvent: { (
1785
+ uniffiHandle: UInt64,
1786
+ eventType: RustBuffer,
1787
+ payloadJson: RustBuffer,
1788
+ uniffiOutReturn: UnsafeMutableRawPointer,
1789
+ uniffiCallStatus: UnsafeMutablePointer<RustCallStatus>
1790
+ ) in
1791
+ let makeCall = {
1792
+ () throws -> () in
1793
+ guard let uniffiObj = try? FfiConverterCallbackInterfaceNativeEventCallback.handleMap.get(handle: uniffiHandle) else {
1794
+ throw UniffiInternalError.unexpectedStaleHandle
1795
+ }
1796
+ return uniffiObj.onEvent(
1797
+ eventType: try FfiConverterString.lift(eventType),
1798
+ payloadJson: try FfiConverterString.lift(payloadJson)
1799
+ )
1800
+ }
1801
+
1802
+
1803
+ let writeReturn = { () }
1804
+ uniffiTraitInterfaceCall(
1805
+ callStatus: uniffiCallStatus,
1806
+ makeCall: makeCall,
1807
+ writeReturn: writeReturn
1808
+ )
1809
+ },
1810
+ uniffiFree: { (uniffiHandle: UInt64) -> () in
1811
+ let result = try? FfiConverterCallbackInterfaceNativeEventCallback.handleMap.remove(handle: uniffiHandle)
1812
+ if result == nil {
1813
+ print("Uniffi callback interface NativeEventCallback: handle missing in uniffiFree")
1814
+ }
1815
+ }
1816
+ )
1817
+ }
1818
+
1819
+ private func uniffiCallbackInitNativeEventCallback() {
1820
+ uniffi_native_agent_ffi_fn_init_callback_vtable_nativeeventcallback(&UniffiCallbackInterfaceNativeEventCallback.vtable)
1821
+ }
1822
+
1823
+ // FfiConverter protocol for callback interfaces
1824
+ #if swift(>=5.8)
1825
+ @_documentation(visibility: private)
1826
+ #endif
1827
+ fileprivate struct FfiConverterCallbackInterfaceNativeEventCallback {
1828
+ fileprivate static var handleMap = UniffiHandleMap<NativeEventCallback>()
1829
+ }
1830
+
1831
+ #if swift(>=5.8)
1832
+ @_documentation(visibility: private)
1833
+ #endif
1834
+ extension FfiConverterCallbackInterfaceNativeEventCallback : FfiConverter {
1835
+ typealias SwiftType = NativeEventCallback
1836
+ typealias FfiType = UInt64
1837
+
1838
+ #if swift(>=5.8)
1839
+ @_documentation(visibility: private)
1840
+ #endif
1841
+ public static func lift(_ handle: UInt64) throws -> SwiftType {
1842
+ try handleMap.get(handle: handle)
1843
+ }
1844
+
1845
+ #if swift(>=5.8)
1846
+ @_documentation(visibility: private)
1847
+ #endif
1848
+ public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> SwiftType {
1849
+ let handle: UInt64 = try readInt(&buf)
1850
+ return try lift(handle)
1851
+ }
1852
+
1853
+ #if swift(>=5.8)
1854
+ @_documentation(visibility: private)
1855
+ #endif
1856
+ public static func lower(_ v: SwiftType) -> UInt64 {
1857
+ return handleMap.insert(obj: v)
1858
+ }
1859
+
1860
+ #if swift(>=5.8)
1861
+ @_documentation(visibility: private)
1862
+ #endif
1863
+ public static func write(_ v: SwiftType, into buf: inout [UInt8]) {
1864
+ writeInt(&buf, lower(v))
1865
+ }
1866
+ }
1867
+
1868
+ #if swift(>=5.8)
1869
+ @_documentation(visibility: private)
1870
+ #endif
1871
+ fileprivate struct FfiConverterOptionUInt32: FfiConverterRustBuffer {
1872
+ typealias SwiftType = UInt32?
1873
+
1874
+ public static func write(_ value: SwiftType, into buf: inout [UInt8]) {
1875
+ guard let value = value else {
1876
+ writeInt(&buf, Int8(0))
1877
+ return
1878
+ }
1879
+ writeInt(&buf, Int8(1))
1880
+ FfiConverterUInt32.write(value, into: &buf)
1881
+ }
1882
+
1883
+ public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> SwiftType {
1884
+ switch try readInt(&buf) as Int8 {
1885
+ case 0: return nil
1886
+ case 1: return try FfiConverterUInt32.read(from: &buf)
1887
+ default: throw UniffiInternalError.unexpectedOptionalTag
1888
+ }
1889
+ }
1890
+ }
1891
+
1892
+ #if swift(>=5.8)
1893
+ @_documentation(visibility: private)
1894
+ #endif
1895
+ fileprivate struct FfiConverterOptionString: FfiConverterRustBuffer {
1896
+ typealias SwiftType = String?
1897
+
1898
+ public static func write(_ value: SwiftType, into buf: inout [UInt8]) {
1899
+ guard let value = value else {
1900
+ writeInt(&buf, Int8(0))
1901
+ return
1902
+ }
1903
+ writeInt(&buf, Int8(1))
1904
+ FfiConverterString.write(value, into: &buf)
1905
+ }
1906
+
1907
+ public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> SwiftType {
1908
+ switch try readInt(&buf) as Int8 {
1909
+ case 0: return nil
1910
+ case 1: return try FfiConverterString.read(from: &buf)
1911
+ default: throw UniffiInternalError.unexpectedOptionalTag
1912
+ }
1913
+ }
1914
+ }
1915
+
1916
+ private enum InitializationResult {
1917
+ case ok
1918
+ case contractVersionMismatch
1919
+ case apiChecksumMismatch
1920
+ }
1921
+ // Use a global variable to perform the versioning checks. Swift ensures that
1922
+ // the code inside is only computed once.
1923
+ private var initializationResult: InitializationResult = {
1924
+ // Get the bindings contract version from our ComponentInterface
1925
+ let bindings_contract_version = 26
1926
+ // Get the scaffolding contract version by calling the into the dylib
1927
+ let scaffolding_contract_version = ffi_native_agent_ffi_uniffi_contract_version()
1928
+ if bindings_contract_version != scaffolding_contract_version {
1929
+ return InitializationResult.contractVersionMismatch
1930
+ }
1931
+ if (uniffi_native_agent_ffi_checksum_method_nativeagenthandle_abort() != 58908) {
1932
+ return InitializationResult.apiChecksumMismatch
1933
+ }
1934
+ if (uniffi_native_agent_ffi_checksum_method_nativeagenthandle_add_cron_job() != 52316) {
1935
+ return InitializationResult.apiChecksumMismatch
1936
+ }
1937
+ if (uniffi_native_agent_ffi_checksum_method_nativeagenthandle_add_skill() != 46434) {
1938
+ return InitializationResult.apiChecksumMismatch
1939
+ }
1940
+ if (uniffi_native_agent_ffi_checksum_method_nativeagenthandle_clear_session() != 43185) {
1941
+ return InitializationResult.apiChecksumMismatch
1942
+ }
1943
+ if (uniffi_native_agent_ffi_checksum_method_nativeagenthandle_delete_auth() != 2640) {
1944
+ return InitializationResult.apiChecksumMismatch
1945
+ }
1946
+ if (uniffi_native_agent_ffi_checksum_method_nativeagenthandle_end_skill() != 44226) {
1947
+ return InitializationResult.apiChecksumMismatch
1948
+ }
1949
+ if (uniffi_native_agent_ffi_checksum_method_nativeagenthandle_follow_up() != 44936) {
1950
+ return InitializationResult.apiChecksumMismatch
1951
+ }
1952
+ if (uniffi_native_agent_ffi_checksum_method_nativeagenthandle_get_auth_status() != 31550) {
1953
+ return InitializationResult.apiChecksumMismatch
1954
+ }
1955
+ if (uniffi_native_agent_ffi_checksum_method_nativeagenthandle_get_auth_token() != 58380) {
1956
+ return InitializationResult.apiChecksumMismatch
1957
+ }
1958
+ if (uniffi_native_agent_ffi_checksum_method_nativeagenthandle_get_heartbeat_config() != 1627) {
1959
+ return InitializationResult.apiChecksumMismatch
1960
+ }
1961
+ if (uniffi_native_agent_ffi_checksum_method_nativeagenthandle_get_models() != 25637) {
1962
+ return InitializationResult.apiChecksumMismatch
1963
+ }
1964
+ if (uniffi_native_agent_ffi_checksum_method_nativeagenthandle_get_scheduler_config() != 3406) {
1965
+ return InitializationResult.apiChecksumMismatch
1966
+ }
1967
+ if (uniffi_native_agent_ffi_checksum_method_nativeagenthandle_handle_wake() != 29594) {
1968
+ return InitializationResult.apiChecksumMismatch
1969
+ }
1970
+ if (uniffi_native_agent_ffi_checksum_method_nativeagenthandle_invoke_tool() != 13537) {
1971
+ return InitializationResult.apiChecksumMismatch
1972
+ }
1973
+ if (uniffi_native_agent_ffi_checksum_method_nativeagenthandle_list_cron_jobs() != 44432) {
1974
+ return InitializationResult.apiChecksumMismatch
1975
+ }
1976
+ if (uniffi_native_agent_ffi_checksum_method_nativeagenthandle_list_cron_runs() != 27743) {
1977
+ return InitializationResult.apiChecksumMismatch
1978
+ }
1979
+ if (uniffi_native_agent_ffi_checksum_method_nativeagenthandle_list_sessions() != 20894) {
1980
+ return InitializationResult.apiChecksumMismatch
1981
+ }
1982
+ if (uniffi_native_agent_ffi_checksum_method_nativeagenthandle_list_skills() != 14677) {
1983
+ return InitializationResult.apiChecksumMismatch
1984
+ }
1985
+ if (uniffi_native_agent_ffi_checksum_method_nativeagenthandle_load_session() != 39832) {
1986
+ return InitializationResult.apiChecksumMismatch
1987
+ }
1988
+ if (uniffi_native_agent_ffi_checksum_method_nativeagenthandle_refresh_token() != 13290) {
1989
+ return InitializationResult.apiChecksumMismatch
1990
+ }
1991
+ if (uniffi_native_agent_ffi_checksum_method_nativeagenthandle_remove_cron_job() != 55519) {
1992
+ return InitializationResult.apiChecksumMismatch
1993
+ }
1994
+ if (uniffi_native_agent_ffi_checksum_method_nativeagenthandle_remove_skill() != 49129) {
1995
+ return InitializationResult.apiChecksumMismatch
1996
+ }
1997
+ if (uniffi_native_agent_ffi_checksum_method_nativeagenthandle_respond_to_approval() != 64086) {
1998
+ return InitializationResult.apiChecksumMismatch
1999
+ }
2000
+ if (uniffi_native_agent_ffi_checksum_method_nativeagenthandle_respond_to_cron_approval() != 36921) {
2001
+ return InitializationResult.apiChecksumMismatch
2002
+ }
2003
+ if (uniffi_native_agent_ffi_checksum_method_nativeagenthandle_restart_mcp() != 44980) {
2004
+ return InitializationResult.apiChecksumMismatch
2005
+ }
2006
+ if (uniffi_native_agent_ffi_checksum_method_nativeagenthandle_resume_session() != 9992) {
2007
+ return InitializationResult.apiChecksumMismatch
2008
+ }
2009
+ if (uniffi_native_agent_ffi_checksum_method_nativeagenthandle_run_cron_job() != 11263) {
2010
+ return InitializationResult.apiChecksumMismatch
2011
+ }
2012
+ if (uniffi_native_agent_ffi_checksum_method_nativeagenthandle_send_message() != 53296) {
2013
+ return InitializationResult.apiChecksumMismatch
2014
+ }
2015
+ if (uniffi_native_agent_ffi_checksum_method_nativeagenthandle_set_auth_key() != 40485) {
2016
+ return InitializationResult.apiChecksumMismatch
2017
+ }
2018
+ if (uniffi_native_agent_ffi_checksum_method_nativeagenthandle_set_event_callback() != 56165) {
2019
+ return InitializationResult.apiChecksumMismatch
2020
+ }
2021
+ if (uniffi_native_agent_ffi_checksum_method_nativeagenthandle_set_heartbeat_config() != 33968) {
2022
+ return InitializationResult.apiChecksumMismatch
2023
+ }
2024
+ if (uniffi_native_agent_ffi_checksum_method_nativeagenthandle_set_scheduler_config() != 18609) {
2025
+ return InitializationResult.apiChecksumMismatch
2026
+ }
2027
+ if (uniffi_native_agent_ffi_checksum_method_nativeagenthandle_start_mcp() != 5853) {
2028
+ return InitializationResult.apiChecksumMismatch
2029
+ }
2030
+ if (uniffi_native_agent_ffi_checksum_method_nativeagenthandle_start_skill() != 49721) {
2031
+ return InitializationResult.apiChecksumMismatch
2032
+ }
2033
+ if (uniffi_native_agent_ffi_checksum_method_nativeagenthandle_steer() != 3715) {
2034
+ return InitializationResult.apiChecksumMismatch
2035
+ }
2036
+ if (uniffi_native_agent_ffi_checksum_method_nativeagenthandle_update_cron_job() != 40127) {
2037
+ return InitializationResult.apiChecksumMismatch
2038
+ }
2039
+ if (uniffi_native_agent_ffi_checksum_method_nativeagenthandle_update_skill() != 42452) {
2040
+ return InitializationResult.apiChecksumMismatch
2041
+ }
2042
+ if (uniffi_native_agent_ffi_checksum_constructor_nativeagenthandle_new() != 18383) {
2043
+ return InitializationResult.apiChecksumMismatch
2044
+ }
2045
+ if (uniffi_native_agent_ffi_checksum_method_nativeeventcallback_on_event() != 29742) {
2046
+ return InitializationResult.apiChecksumMismatch
2047
+ }
2048
+
2049
+ uniffiCallbackInitNativeEventCallback()
2050
+ return InitializationResult.ok
2051
+ }()
2052
+
2053
+ private func uniffiEnsureInitialized() {
2054
+ switch initializationResult {
2055
+ case .ok:
2056
+ break
2057
+ case .contractVersionMismatch:
2058
+ fatalError("UniFFI contract version mismatch: try cleaning and rebuilding your project")
2059
+ case .apiChecksumMismatch:
2060
+ fatalError("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
2061
+ }
2062
+ }
2063
+
2064
+ // swiftlint:enable all