capacitor-native-agent 0.3.0 → 0.3.2

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