| 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(ed_agent_ffiFFI) |
| 11 | import ed_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_ed_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_ed_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 | uniffiEnsureEdAgentFfiInitialized() |
| 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 | // Initial value and increment amount for handles. |
| 356 | // These ensure that SWIFT handles always have the lowest bit set |
| 357 | fileprivate let UNIFFI_HANDLEMAP_INITIAL: UInt64 = 1 |
| 358 | fileprivate let UNIFFI_HANDLEMAP_DELTA: UInt64 = 2 |
| 359 | |
| 360 | fileprivate final class UniffiHandleMap<T>: @unchecked Sendable { |
| 361 | // All mutation happens with this lock held, which is why we implement @unchecked Sendable. |
| 362 | private let lock = NSLock() |
| 363 | private var map: [UInt64: T] = [:] |
| 364 | private var currentHandle: UInt64 = UNIFFI_HANDLEMAP_INITIAL |
| 365 | |
| 366 | func insert(obj: T) -> UInt64 { |
| 367 | lock.withLock { |
| 368 | return doInsert(obj) |
| 369 | } |
| 370 | } |
| 371 | |
| 372 | // Low-level insert function, this assumes `lock` is held. |
| 373 | private func doInsert(_ obj: T) -> UInt64 { |
| 374 | let handle = currentHandle |
| 375 | currentHandle += UNIFFI_HANDLEMAP_DELTA |
| 376 | map[handle] = obj |
| 377 | return handle |
| 378 | } |
| 379 | |
| 380 | func get(handle: UInt64) throws -> T { |
| 381 | try lock.withLock { |
| 382 | guard let obj = map[handle] else { |
| 383 | throw UniffiInternalError.unexpectedStaleHandle |
| 384 | } |
| 385 | return obj |
| 386 | } |
| 387 | } |
| 388 | |
| 389 | func clone(handle: UInt64) throws -> UInt64 { |
| 390 | try lock.withLock { |
| 391 | guard let obj = map[handle] else { |
| 392 | throw UniffiInternalError.unexpectedStaleHandle |
| 393 | } |
| 394 | return doInsert(obj) |
| 395 | } |
| 396 | } |
| 397 | |
| 398 | @discardableResult |
| 399 | func remove(handle: UInt64) throws -> T { |
| 400 | try lock.withLock { |
| 401 | guard let obj = map.removeValue(forKey: handle) else { |
| 402 | throw UniffiInternalError.unexpectedStaleHandle |
| 403 | } |
| 404 | return obj |
| 405 | } |
| 406 | } |
| 407 | |
| 408 | var count: Int { |
| 409 | get { |
| 410 | map.count |
| 411 | } |
| 412 | } |
| 413 | } |
| 414 | |
| 415 | |
| 416 | // Public interface members begin here. |
| 417 | // Magic number for the Rust proxy to call using the same mechanism as every other method, |
| 418 | // to free the callback once it's dropped by Rust. |
| 419 | private let IDX_CALLBACK_FREE: Int32 = 0 |
| 420 | // Callback return codes |
| 421 | private let UNIFFI_CALLBACK_SUCCESS: Int32 = 0 |
| 422 | private let UNIFFI_CALLBACK_ERROR: Int32 = 1 |
| 423 | private let UNIFFI_CALLBACK_UNEXPECTED_ERROR: Int32 = 2 |
| 424 | |
| 425 | #if swift(>=5.8) |
| 426 | @_documentation(visibility: private) |
| 427 | #endif |
| 428 | fileprivate struct FfiConverterUInt8: FfiConverterPrimitive { |
| 429 | typealias FfiType = UInt8 |
| 430 | typealias SwiftType = UInt8 |
| 431 | |
| 432 | public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> UInt8 { |
| 433 | return try lift(readInt(&buf)) |
| 434 | } |
| 435 | |
| 436 | public static func write(_ value: UInt8, into buf: inout [UInt8]) { |
| 437 | writeInt(&buf, lower(value)) |
| 438 | } |
| 439 | } |
| 440 | |
| 441 | #if swift(>=5.8) |
| 442 | @_documentation(visibility: private) |
| 443 | #endif |
| 444 | fileprivate struct FfiConverterUInt64: FfiConverterPrimitive { |
| 445 | typealias FfiType = UInt64 |
| 446 | typealias SwiftType = UInt64 |
| 447 | |
| 448 | public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> UInt64 { |
| 449 | return try lift(readInt(&buf)) |
| 450 | } |
| 451 | |
| 452 | public static func write(_ value: SwiftType, into buf: inout [UInt8]) { |
| 453 | writeInt(&buf, lower(value)) |
| 454 | } |
| 455 | } |
| 456 | |
| 457 | #if swift(>=5.8) |
| 458 | @_documentation(visibility: private) |
| 459 | #endif |
| 460 | fileprivate struct FfiConverterFloat: FfiConverterPrimitive { |
| 461 | typealias FfiType = Float |
| 462 | typealias SwiftType = Float |
| 463 | |
| 464 | public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> Float { |
| 465 | return try lift(readFloat(&buf)) |
| 466 | } |
| 467 | |
| 468 | public static func write(_ value: Float, into buf: inout [UInt8]) { |
| 469 | writeFloat(&buf, lower(value)) |
| 470 | } |
| 471 | } |
| 472 | |
| 473 | #if swift(>=5.8) |
| 474 | @_documentation(visibility: private) |
| 475 | #endif |
| 476 | fileprivate struct FfiConverterDouble: FfiConverterPrimitive { |
| 477 | typealias FfiType = Double |
| 478 | typealias SwiftType = Double |
| 479 | |
| 480 | public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> Double { |
| 481 | return try lift(readDouble(&buf)) |
| 482 | } |
| 483 | |
| 484 | public static func write(_ value: Double, into buf: inout [UInt8]) { |
| 485 | writeDouble(&buf, lower(value)) |
| 486 | } |
| 487 | } |
| 488 | |
| 489 | #if swift(>=5.8) |
| 490 | @_documentation(visibility: private) |
| 491 | #endif |
| 492 | fileprivate struct FfiConverterBool : FfiConverter { |
| 493 | typealias FfiType = Int8 |
| 494 | typealias SwiftType = Bool |
| 495 | |
| 496 | public static func lift(_ value: Int8) throws -> Bool { |
| 497 | return value != 0 |
| 498 | } |
| 499 | |
| 500 | public static func lower(_ value: Bool) -> Int8 { |
| 501 | return value ? 1 : 0 |
| 502 | } |
| 503 | |
| 504 | public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> Bool { |
| 505 | return try lift(readInt(&buf)) |
| 506 | } |
| 507 | |
| 508 | public static func write(_ value: Bool, into buf: inout [UInt8]) { |
| 509 | writeInt(&buf, lower(value)) |
| 510 | } |
| 511 | } |
| 512 | |
| 513 | #if swift(>=5.8) |
| 514 | @_documentation(visibility: private) |
| 515 | #endif |
| 516 | fileprivate struct FfiConverterString: FfiConverter { |
| 517 | typealias SwiftType = String |
| 518 | typealias FfiType = RustBuffer |
| 519 | |
| 520 | public static func lift(_ value: RustBuffer) throws -> String { |
| 521 | defer { |
| 522 | value.deallocate() |
| 523 | } |
| 524 | if value.data == nil { |
| 525 | return String() |
| 526 | } |
| 527 | let bytes = UnsafeBufferPointer<UInt8>(start: value.data!, count: Int(value.len)) |
| 528 | return String(bytes: bytes, encoding: String.Encoding.utf8)! |
| 529 | } |
| 530 | |
| 531 | public static func lower(_ value: String) -> RustBuffer { |
| 532 | return value.utf8CString.withUnsafeBufferPointer { ptr in |
| 533 | // The swift string gives us int8_t, we want uint8_t. |
| 534 | ptr.withMemoryRebound(to: UInt8.self) { ptr in |
| 535 | // The swift string gives us a trailing null byte, we don't want it. |
| 536 | let buf = UnsafeBufferPointer(rebasing: ptr.prefix(upTo: ptr.count - 1)) |
| 537 | return RustBuffer.from(buf) |
| 538 | } |
| 539 | } |
| 540 | } |
| 541 | |
| 542 | public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> String { |
| 543 | let len: Int32 = try readInt(&buf) |
| 544 | return String(bytes: try readBytes(&buf, count: Int(len)), encoding: String.Encoding.utf8)! |
| 545 | } |
| 546 | |
| 547 | public static func write(_ value: String, into buf: inout [UInt8]) { |
| 548 | let len = Int32(value.utf8.count) |
| 549 | writeInt(&buf, len) |
| 550 | writeBytes(&buf, value.utf8) |
| 551 | } |
| 552 | } |
| 553 | |
| 554 | |
| 555 | |
| 556 | |
| 557 | public protocol FfiEdAgentProtocol: AnyObject, Sendable { |
| 558 | |
| 559 | func cancel() |
| 560 | |
| 561 | /** |
| 562 | * Stop the `stream_message` in progress. Does nothing when none is. |
| 563 | */ |
| 564 | func cancelStream() |
| 565 | |
| 566 | func clearHistory() async -> UInt64 |
| 567 | |
| 568 | func clearSystemPrompt() async |
| 569 | |
| 570 | /** |
| 571 | * One-shot generation over `messages`. Leaves the conversation untouched. |
| 572 | */ |
| 573 | func generate(messages: [FfiChatMessage], sampling: FfiSamplingConfig?) async throws -> String |
| 574 | |
| 575 | func history() async -> [FfiChatMessage] |
| 576 | |
| 577 | func info() async -> FfiEngineInfo |
| 578 | |
| 579 | func isLoaded() async -> Bool |
| 580 | |
| 581 | func loadAssignedModel(environment: FfiEnvironment, appId: String, appSecret: String, systemPrompt: String?, sampling: FfiSamplingConfig?) async throws -> Double |
| 582 | |
| 583 | func loadDefaultAgentModel(systemPrompt: String?) async throws -> Double |
| 584 | |
| 585 | func loadGgufModel(config: FfiGgufModelConfig, systemPrompt: String?, sampling: FfiSamplingConfig?) async throws -> Double |
| 586 | |
| 587 | func loadUqffModel(config: FfiUqffModelConfig, systemPrompt: String?, sampling: FfiSamplingConfig?) async throws -> Double |
| 588 | |
| 589 | func registerTool(tool: FfiToolDefinition) async throws |
| 590 | |
| 591 | func removeAllTools() async |
| 592 | |
| 593 | /** |
| 594 | * Replace the conversation with `messages`. Needs a loaded model. |
| 595 | */ |
| 596 | func restoreHistory(messages: [FfiChatMessage]) async |
| 597 | |
| 598 | func run(message: String) async throws -> FfiAgentReply |
| 599 | |
| 600 | func send(message: String) async throws -> FfiReply |
| 601 | |
| 602 | func setSampling(sampling: FfiSamplingConfig) async |
| 603 | |
| 604 | func setSystemPrompt(prompt: String) async |
| 605 | |
| 606 | /** |
| 607 | * Stream the reply to `message` into `listener`, for plain chat without tools. |
| 608 | * Returns when the reply is complete, on error, or after `cancel_stream`. |
| 609 | * The turn so far stays in history either way. |
| 610 | */ |
| 611 | func streamMessage(message: String, listener: FfiStreamListener) async throws |
| 612 | |
| 613 | func unload() async -> String? |
| 614 | |
| 615 | func unregisterTool(name: String) async -> Bool |
| 616 | |
| 617 | } |
| 618 | open class FfiEdAgent: FfiEdAgentProtocol, @unchecked Sendable { |
| 619 | fileprivate let handle: UInt64 |
| 620 | |
| 621 | /// Used to instantiate a [FFIObject] without an actual handle, for fakes in tests, mostly. |
| 622 | #if swift(>=5.8) |
| 623 | @_documentation(visibility: private) |
| 624 | #endif |
| 625 | public struct NoHandle { |
| 626 | public init() {} |
| 627 | } |
| 628 | |
| 629 | // TODO: We'd like this to be `private` but for Swifty reasons, |
| 630 | // we can't implement `FfiConverter` without making this `required` and we can't |
| 631 | // make it `required` without making it `public`. |
| 632 | #if swift(>=5.8) |
| 633 | @_documentation(visibility: private) |
| 634 | #endif |
| 635 | required public init(unsafeFromHandle handle: UInt64) { |
| 636 | self.handle = handle |
| 637 | } |
| 638 | |
| 639 | // This constructor can be used to instantiate a fake object. |
| 640 | // - Parameter noHandle: Placeholder value so we can have a constructor separate from the default empty one that may be implemented for classes extending [FFIObject]. |
| 641 | // |
| 642 | // - Warning: |
| 643 | // Any object instantiated with this constructor cannot be passed to an actual Rust-backed object. Since there isn't a backing handle the FFI lower functions will crash. |
| 644 | #if swift(>=5.8) |
| 645 | @_documentation(visibility: private) |
| 646 | #endif |
| 647 | public init(noHandle: NoHandle) { |
| 648 | self.handle = 0 |
| 649 | } |
| 650 | |
| 651 | #if swift(>=5.8) |
| 652 | @_documentation(visibility: private) |
| 653 | #endif |
| 654 | public func uniffiCloneHandle() -> UInt64 { |
| 655 | return try! rustCall { uniffi_ed_agent_ffi_fn_clone_ffiedagent(self.handle, $0) } |
| 656 | } |
| 657 | public convenience init(executor: FfiToolExecutor, approvals: FfiApprovalHandler, events: FfiEventListener, config: FfiAgentConfig?) { |
| 658 | let handle = |
| 659 | try! rustCall() { |
| 660 | uniffi_ed_agent_ffi_fn_constructor_ffiedagent_new( |
| 661 | FfiConverterCallbackInterfaceFfiToolExecutor_lower(executor), |
| 662 | FfiConverterCallbackInterfaceFfiApprovalHandler_lower(approvals), |
| 663 | FfiConverterCallbackInterfaceFfiEventListener_lower(events), |
| 664 | FfiConverterOptionTypeFfiAgentConfig.lower(config),$0 |
| 665 | ) |
| 666 | } |
| 667 | self.init(unsafeFromHandle: handle) |
| 668 | } |
| 669 | |
| 670 | deinit { |
| 671 | if handle == 0 { |
| 672 | // Mock objects have handle=0 don't try to free them |
| 673 | return |
| 674 | } |
| 675 | |
| 676 | try! rustCall { uniffi_ed_agent_ffi_fn_free_ffiedagent(handle, $0) } |
| 677 | } |
| 678 | |
| 679 | |
| 680 | /** |
| 681 | * Like `new`, with an Onde app id so the engine reports usage under it. |
| 682 | */ |
| 683 | public static func newWithAppId(executor: FfiToolExecutor, approvals: FfiApprovalHandler, events: FfiEventListener, config: FfiAgentConfig?, appId: String?) -> FfiEdAgent { |
| 684 | return try! FfiConverterTypeFfiEdAgent_lift(try! rustCall() { |
| 685 | uniffi_ed_agent_ffi_fn_constructor_ffiedagent_new_with_app_id( |
| 686 | FfiConverterCallbackInterfaceFfiToolExecutor_lower(executor), |
| 687 | FfiConverterCallbackInterfaceFfiApprovalHandler_lower(approvals), |
| 688 | FfiConverterCallbackInterfaceFfiEventListener_lower(events), |
| 689 | FfiConverterOptionTypeFfiAgentConfig.lower(config), |
| 690 | FfiConverterOptionString.lower(appId),$0 |
| 691 | ) |
| 692 | }) |
| 693 | } |
| 694 | |
| 695 | |
| 696 | |
| 697 | open func cancel() {try! rustCall() { |
| 698 | uniffi_ed_agent_ffi_fn_method_ffiedagent_cancel( |
| 699 | self.uniffiCloneHandle(),$0 |
| 700 | ) |
| 701 | } |
| 702 | } |
| 703 | |
| 704 | /** |
| 705 | * Stop the `stream_message` in progress. Does nothing when none is. |
| 706 | */ |
| 707 | open func cancelStream() {try! rustCall() { |
| 708 | uniffi_ed_agent_ffi_fn_method_ffiedagent_cancel_stream( |
| 709 | self.uniffiCloneHandle(),$0 |
| 710 | ) |
| 711 | } |
| 712 | } |
| 713 | |
| 714 | open func clearHistory()async -> UInt64 { |
| 715 | return |
| 716 | try! await uniffiRustCallAsync( |
| 717 | rustFutureFunc: { |
| 718 | uniffi_ed_agent_ffi_fn_method_ffiedagent_clear_history( |
| 719 | self.uniffiCloneHandle() |
| 720 | |
| 721 | ) |
| 722 | }, |
| 723 | pollFunc: ffi_ed_agent_ffi_rust_future_poll_u64, |
| 724 | completeFunc: ffi_ed_agent_ffi_rust_future_complete_u64, |
| 725 | freeFunc: ffi_ed_agent_ffi_rust_future_free_u64, |
| 726 | liftFunc: FfiConverterUInt64.lift, |
| 727 | errorHandler: nil |
| 728 | |
| 729 | ) |
| 730 | } |
| 731 | |
| 732 | open func clearSystemPrompt()async { |
| 733 | return |
| 734 | try! await uniffiRustCallAsync( |
| 735 | rustFutureFunc: { |
| 736 | uniffi_ed_agent_ffi_fn_method_ffiedagent_clear_system_prompt( |
| 737 | self.uniffiCloneHandle() |
| 738 | |
| 739 | ) |
| 740 | }, |
| 741 | pollFunc: ffi_ed_agent_ffi_rust_future_poll_void, |
| 742 | completeFunc: ffi_ed_agent_ffi_rust_future_complete_void, |
| 743 | freeFunc: ffi_ed_agent_ffi_rust_future_free_void, |
| 744 | liftFunc: { $0 }, |
| 745 | errorHandler: nil |
| 746 | |
| 747 | ) |
| 748 | } |
| 749 | |
| 750 | /** |
| 751 | * One-shot generation over `messages`. Leaves the conversation untouched. |
| 752 | */ |
| 753 | open func generate(messages: [FfiChatMessage], sampling: FfiSamplingConfig?)async throws -> String { |
| 754 | return |
| 755 | try await uniffiRustCallAsync( |
| 756 | rustFutureFunc: { |
| 757 | uniffi_ed_agent_ffi_fn_method_ffiedagent_generate( |
| 758 | self.uniffiCloneHandle(), |
| 759 | FfiConverterSequenceTypeFfiChatMessage.lower(messages),FfiConverterOptionTypeFfiSamplingConfig.lower(sampling) |
| 760 | ) |
| 761 | }, |
| 762 | pollFunc: ffi_ed_agent_ffi_rust_future_poll_rust_buffer, |
| 763 | completeFunc: ffi_ed_agent_ffi_rust_future_complete_rust_buffer, |
| 764 | freeFunc: ffi_ed_agent_ffi_rust_future_free_rust_buffer, |
| 765 | liftFunc: FfiConverterString.lift, |
| 766 | errorHandler: FfiConverterTypeFfiEdError_lift |
| 767 | ) |
| 768 | } |
| 769 | |
| 770 | open func history()async -> [FfiChatMessage] { |
| 771 | return |
| 772 | try! await uniffiRustCallAsync( |
| 773 | rustFutureFunc: { |
| 774 | uniffi_ed_agent_ffi_fn_method_ffiedagent_history( |
| 775 | self.uniffiCloneHandle() |
| 776 | |
| 777 | ) |
| 778 | }, |
| 779 | pollFunc: ffi_ed_agent_ffi_rust_future_poll_rust_buffer, |
| 780 | completeFunc: ffi_ed_agent_ffi_rust_future_complete_rust_buffer, |
| 781 | freeFunc: ffi_ed_agent_ffi_rust_future_free_rust_buffer, |
| 782 | liftFunc: FfiConverterSequenceTypeFfiChatMessage.lift, |
| 783 | errorHandler: nil |
| 784 | |
| 785 | ) |
| 786 | } |
| 787 | |
| 788 | open func info()async -> FfiEngineInfo { |
| 789 | return |
| 790 | try! await uniffiRustCallAsync( |
| 791 | rustFutureFunc: { |
| 792 | uniffi_ed_agent_ffi_fn_method_ffiedagent_info( |
| 793 | self.uniffiCloneHandle() |
| 794 | |
| 795 | ) |
| 796 | }, |
| 797 | pollFunc: ffi_ed_agent_ffi_rust_future_poll_rust_buffer, |
| 798 | completeFunc: ffi_ed_agent_ffi_rust_future_complete_rust_buffer, |
| 799 | freeFunc: ffi_ed_agent_ffi_rust_future_free_rust_buffer, |
| 800 | liftFunc: FfiConverterTypeFfiEngineInfo_lift, |
| 801 | errorHandler: nil |
| 802 | |
| 803 | ) |
| 804 | } |
| 805 | |
| 806 | open func isLoaded()async -> Bool { |
| 807 | return |
| 808 | try! await uniffiRustCallAsync( |
| 809 | rustFutureFunc: { |
| 810 | uniffi_ed_agent_ffi_fn_method_ffiedagent_is_loaded( |
| 811 | self.uniffiCloneHandle() |
| 812 | |
| 813 | ) |
| 814 | }, |
| 815 | pollFunc: ffi_ed_agent_ffi_rust_future_poll_i8, |
| 816 | completeFunc: ffi_ed_agent_ffi_rust_future_complete_i8, |
| 817 | freeFunc: ffi_ed_agent_ffi_rust_future_free_i8, |
| 818 | liftFunc: FfiConverterBool.lift, |
| 819 | errorHandler: nil |
| 820 | |
| 821 | ) |
| 822 | } |
| 823 | |
| 824 | open func loadAssignedModel(environment: FfiEnvironment, appId: String, appSecret: String, systemPrompt: String?, sampling: FfiSamplingConfig?)async throws -> Double { |
| 825 | return |
| 826 | try await uniffiRustCallAsync( |
| 827 | rustFutureFunc: { |
| 828 | uniffi_ed_agent_ffi_fn_method_ffiedagent_load_assigned_model( |
| 829 | self.uniffiCloneHandle(), |
| 830 | FfiConverterTypeFfiEnvironment_lower(environment),FfiConverterString.lower(appId),FfiConverterString.lower(appSecret),FfiConverterOptionString.lower(systemPrompt),FfiConverterOptionTypeFfiSamplingConfig.lower(sampling) |
| 831 | ) |
| 832 | }, |
| 833 | pollFunc: ffi_ed_agent_ffi_rust_future_poll_f64, |
| 834 | completeFunc: ffi_ed_agent_ffi_rust_future_complete_f64, |
| 835 | freeFunc: ffi_ed_agent_ffi_rust_future_free_f64, |
| 836 | liftFunc: FfiConverterDouble.lift, |
| 837 | errorHandler: FfiConverterTypeFfiEdError_lift |
| 838 | ) |
| 839 | } |
| 840 | |
| 841 | open func loadDefaultAgentModel(systemPrompt: String?)async throws -> Double { |
| 842 | return |
| 843 | try await uniffiRustCallAsync( |
| 844 | rustFutureFunc: { |
| 845 | uniffi_ed_agent_ffi_fn_method_ffiedagent_load_default_agent_model( |
| 846 | self.uniffiCloneHandle(), |
| 847 | FfiConverterOptionString.lower(systemPrompt) |
| 848 | ) |
| 849 | }, |
| 850 | pollFunc: ffi_ed_agent_ffi_rust_future_poll_f64, |
| 851 | completeFunc: ffi_ed_agent_ffi_rust_future_complete_f64, |
| 852 | freeFunc: ffi_ed_agent_ffi_rust_future_free_f64, |
| 853 | liftFunc: FfiConverterDouble.lift, |
| 854 | errorHandler: FfiConverterTypeFfiEdError_lift |
| 855 | ) |
| 856 | } |
| 857 | |
| 858 | open func loadGgufModel(config: FfiGgufModelConfig, systemPrompt: String?, sampling: FfiSamplingConfig?)async throws -> Double { |
| 859 | return |
| 860 | try await uniffiRustCallAsync( |
| 861 | rustFutureFunc: { |
| 862 | uniffi_ed_agent_ffi_fn_method_ffiedagent_load_gguf_model( |
| 863 | self.uniffiCloneHandle(), |
| 864 | FfiConverterTypeFfiGgufModelConfig_lower(config),FfiConverterOptionString.lower(systemPrompt),FfiConverterOptionTypeFfiSamplingConfig.lower(sampling) |
| 865 | ) |
| 866 | }, |
| 867 | pollFunc: ffi_ed_agent_ffi_rust_future_poll_f64, |
| 868 | completeFunc: ffi_ed_agent_ffi_rust_future_complete_f64, |
| 869 | freeFunc: ffi_ed_agent_ffi_rust_future_free_f64, |
| 870 | liftFunc: FfiConverterDouble.lift, |
| 871 | errorHandler: FfiConverterTypeFfiEdError_lift |
| 872 | ) |
| 873 | } |
| 874 | |
| 875 | open func loadUqffModel(config: FfiUqffModelConfig, systemPrompt: String?, sampling: FfiSamplingConfig?)async throws -> Double { |
| 876 | return |
| 877 | try await uniffiRustCallAsync( |
| 878 | rustFutureFunc: { |
| 879 | uniffi_ed_agent_ffi_fn_method_ffiedagent_load_uqff_model( |
| 880 | self.uniffiCloneHandle(), |
| 881 | FfiConverterTypeFfiUqffModelConfig_lower(config),FfiConverterOptionString.lower(systemPrompt),FfiConverterOptionTypeFfiSamplingConfig.lower(sampling) |
| 882 | ) |
| 883 | }, |
| 884 | pollFunc: ffi_ed_agent_ffi_rust_future_poll_f64, |
| 885 | completeFunc: ffi_ed_agent_ffi_rust_future_complete_f64, |
| 886 | freeFunc: ffi_ed_agent_ffi_rust_future_free_f64, |
| 887 | liftFunc: FfiConverterDouble.lift, |
| 888 | errorHandler: FfiConverterTypeFfiEdError_lift |
| 889 | ) |
| 890 | } |
| 891 | |
| 892 | open func registerTool(tool: FfiToolDefinition)async throws { |
| 893 | return |
| 894 | try await uniffiRustCallAsync( |
| 895 | rustFutureFunc: { |
| 896 | uniffi_ed_agent_ffi_fn_method_ffiedagent_register_tool( |
| 897 | self.uniffiCloneHandle(), |
| 898 | FfiConverterTypeFfiToolDefinition_lower(tool) |
| 899 | ) |
| 900 | }, |
| 901 | pollFunc: ffi_ed_agent_ffi_rust_future_poll_void, |
| 902 | completeFunc: ffi_ed_agent_ffi_rust_future_complete_void, |
| 903 | freeFunc: ffi_ed_agent_ffi_rust_future_free_void, |
| 904 | liftFunc: { $0 }, |
| 905 | errorHandler: FfiConverterTypeFfiEdError_lift |
| 906 | ) |
| 907 | } |
| 908 | |
| 909 | open func removeAllTools()async { |
| 910 | return |
| 911 | try! await uniffiRustCallAsync( |
| 912 | rustFutureFunc: { |
| 913 | uniffi_ed_agent_ffi_fn_method_ffiedagent_remove_all_tools( |
| 914 | self.uniffiCloneHandle() |
| 915 | |
| 916 | ) |
| 917 | }, |
| 918 | pollFunc: ffi_ed_agent_ffi_rust_future_poll_void, |
| 919 | completeFunc: ffi_ed_agent_ffi_rust_future_complete_void, |
| 920 | freeFunc: ffi_ed_agent_ffi_rust_future_free_void, |
| 921 | liftFunc: { $0 }, |
| 922 | errorHandler: nil |
| 923 | |
| 924 | ) |
| 925 | } |
| 926 | |
| 927 | /** |
| 928 | * Replace the conversation with `messages`. Needs a loaded model. |
| 929 | */ |
| 930 | open func restoreHistory(messages: [FfiChatMessage])async { |
| 931 | return |
| 932 | try! await uniffiRustCallAsync( |
| 933 | rustFutureFunc: { |
| 934 | uniffi_ed_agent_ffi_fn_method_ffiedagent_restore_history( |
| 935 | self.uniffiCloneHandle(), |
| 936 | FfiConverterSequenceTypeFfiChatMessage.lower(messages) |
| 937 | ) |
| 938 | }, |
| 939 | pollFunc: ffi_ed_agent_ffi_rust_future_poll_void, |
| 940 | completeFunc: ffi_ed_agent_ffi_rust_future_complete_void, |
| 941 | freeFunc: ffi_ed_agent_ffi_rust_future_free_void, |
| 942 | liftFunc: { $0 }, |
| 943 | errorHandler: nil |
| 944 | |
| 945 | ) |
| 946 | } |
| 947 | |
| 948 | open func run(message: String)async throws -> FfiAgentReply { |
| 949 | return |
| 950 | try await uniffiRustCallAsync( |
| 951 | rustFutureFunc: { |
| 952 | uniffi_ed_agent_ffi_fn_method_ffiedagent_run( |
| 953 | self.uniffiCloneHandle(), |
| 954 | FfiConverterString.lower(message) |
| 955 | ) |
| 956 | }, |
| 957 | pollFunc: ffi_ed_agent_ffi_rust_future_poll_rust_buffer, |
| 958 | completeFunc: ffi_ed_agent_ffi_rust_future_complete_rust_buffer, |
| 959 | freeFunc: ffi_ed_agent_ffi_rust_future_free_rust_buffer, |
| 960 | liftFunc: FfiConverterTypeFfiAgentReply_lift, |
| 961 | errorHandler: FfiConverterTypeFfiEdError_lift |
| 962 | ) |
| 963 | } |
| 964 | |
| 965 | open func send(message: String)async throws -> FfiReply { |
| 966 | return |
| 967 | try await uniffiRustCallAsync( |
| 968 | rustFutureFunc: { |
| 969 | uniffi_ed_agent_ffi_fn_method_ffiedagent_send( |
| 970 | self.uniffiCloneHandle(), |
| 971 | FfiConverterString.lower(message) |
| 972 | ) |
| 973 | }, |
| 974 | pollFunc: ffi_ed_agent_ffi_rust_future_poll_rust_buffer, |
| 975 | completeFunc: ffi_ed_agent_ffi_rust_future_complete_rust_buffer, |
| 976 | freeFunc: ffi_ed_agent_ffi_rust_future_free_rust_buffer, |
| 977 | liftFunc: FfiConverterTypeFfiReply_lift, |
| 978 | errorHandler: FfiConverterTypeFfiEdError_lift |
| 979 | ) |
| 980 | } |
| 981 | |
| 982 | open func setSampling(sampling: FfiSamplingConfig)async { |
| 983 | return |
| 984 | try! await uniffiRustCallAsync( |
| 985 | rustFutureFunc: { |
| 986 | uniffi_ed_agent_ffi_fn_method_ffiedagent_set_sampling( |
| 987 | self.uniffiCloneHandle(), |
| 988 | FfiConverterTypeFfiSamplingConfig_lower(sampling) |
| 989 | ) |
| 990 | }, |
| 991 | pollFunc: ffi_ed_agent_ffi_rust_future_poll_void, |
| 992 | completeFunc: ffi_ed_agent_ffi_rust_future_complete_void, |
| 993 | freeFunc: ffi_ed_agent_ffi_rust_future_free_void, |
| 994 | liftFunc: { $0 }, |
| 995 | errorHandler: nil |
| 996 | |
| 997 | ) |
| 998 | } |
| 999 | |
| 1000 | open func setSystemPrompt(prompt: String)async { |
| 1001 | return |
| 1002 | try! await uniffiRustCallAsync( |
| 1003 | rustFutureFunc: { |
| 1004 | uniffi_ed_agent_ffi_fn_method_ffiedagent_set_system_prompt( |
| 1005 | self.uniffiCloneHandle(), |
| 1006 | FfiConverterString.lower(prompt) |
| 1007 | ) |
| 1008 | }, |
| 1009 | pollFunc: ffi_ed_agent_ffi_rust_future_poll_void, |
| 1010 | completeFunc: ffi_ed_agent_ffi_rust_future_complete_void, |
| 1011 | freeFunc: ffi_ed_agent_ffi_rust_future_free_void, |
| 1012 | liftFunc: { $0 }, |
| 1013 | errorHandler: nil |
| 1014 | |
| 1015 | ) |
| 1016 | } |
| 1017 | |
| 1018 | /** |
| 1019 | * Stream the reply to `message` into `listener`, for plain chat without tools. |
| 1020 | * Returns when the reply is complete, on error, or after `cancel_stream`. |
| 1021 | * The turn so far stays in history either way. |
| 1022 | */ |
| 1023 | open func streamMessage(message: String, listener: FfiStreamListener)async throws { |
| 1024 | return |
| 1025 | try await uniffiRustCallAsync( |
| 1026 | rustFutureFunc: { |
| 1027 | uniffi_ed_agent_ffi_fn_method_ffiedagent_stream_message( |
| 1028 | self.uniffiCloneHandle(), |
| 1029 | FfiConverterString.lower(message),FfiConverterCallbackInterfaceFfiStreamListener_lower(listener) |
| 1030 | ) |
| 1031 | }, |
| 1032 | pollFunc: ffi_ed_agent_ffi_rust_future_poll_void, |
| 1033 | completeFunc: ffi_ed_agent_ffi_rust_future_complete_void, |
| 1034 | freeFunc: ffi_ed_agent_ffi_rust_future_free_void, |
| 1035 | liftFunc: { $0 }, |
| 1036 | errorHandler: FfiConverterTypeFfiEdError_lift |
| 1037 | ) |
| 1038 | } |
| 1039 | |
| 1040 | open func unload()async -> String? { |
| 1041 | return |
| 1042 | try! await uniffiRustCallAsync( |
| 1043 | rustFutureFunc: { |
| 1044 | uniffi_ed_agent_ffi_fn_method_ffiedagent_unload( |
| 1045 | self.uniffiCloneHandle() |
| 1046 | |
| 1047 | ) |
| 1048 | }, |
| 1049 | pollFunc: ffi_ed_agent_ffi_rust_future_poll_rust_buffer, |
| 1050 | completeFunc: ffi_ed_agent_ffi_rust_future_complete_rust_buffer, |
| 1051 | freeFunc: ffi_ed_agent_ffi_rust_future_free_rust_buffer, |
| 1052 | liftFunc: FfiConverterOptionString.lift, |
| 1053 | errorHandler: nil |
| 1054 | |
| 1055 | ) |
| 1056 | } |
| 1057 | |
| 1058 | open func unregisterTool(name: String)async -> Bool { |
| 1059 | return |
| 1060 | try! await uniffiRustCallAsync( |
| 1061 | rustFutureFunc: { |
| 1062 | uniffi_ed_agent_ffi_fn_method_ffiedagent_unregister_tool( |
| 1063 | self.uniffiCloneHandle(), |
| 1064 | FfiConverterString.lower(name) |
| 1065 | ) |
| 1066 | }, |
| 1067 | pollFunc: ffi_ed_agent_ffi_rust_future_poll_i8, |
| 1068 | completeFunc: ffi_ed_agent_ffi_rust_future_complete_i8, |
| 1069 | freeFunc: ffi_ed_agent_ffi_rust_future_free_i8, |
| 1070 | liftFunc: FfiConverterBool.lift, |
| 1071 | errorHandler: nil |
| 1072 | |
| 1073 | ) |
| 1074 | } |
| 1075 | |
| 1076 | |
| 1077 | |
| 1078 | } |
| 1079 | |
| 1080 | |
| 1081 | #if swift(>=5.8) |
| 1082 | @_documentation(visibility: private) |
| 1083 | #endif |
| 1084 | public struct FfiConverterTypeFfiEdAgent: FfiConverter { |
| 1085 | typealias FfiType = UInt64 |
| 1086 | typealias SwiftType = FfiEdAgent |
| 1087 | |
| 1088 | public static func lift(_ handle: UInt64) throws -> FfiEdAgent { |
| 1089 | return FfiEdAgent(unsafeFromHandle: handle) |
| 1090 | } |
| 1091 | |
| 1092 | public static func lower(_ value: FfiEdAgent) -> UInt64 { |
| 1093 | return value.uniffiCloneHandle() |
| 1094 | } |
| 1095 | |
| 1096 | public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> FfiEdAgent { |
| 1097 | let handle: UInt64 = try readInt(&buf) |
| 1098 | return try lift(handle) |
| 1099 | } |
| 1100 | |
| 1101 | public static func write(_ value: FfiEdAgent, into buf: inout [UInt8]) { |
| 1102 | writeInt(&buf, lower(value)) |
| 1103 | } |
| 1104 | } |
| 1105 | |
| 1106 | |
| 1107 | #if swift(>=5.8) |
| 1108 | @_documentation(visibility: private) |
| 1109 | #endif |
| 1110 | public func FfiConverterTypeFfiEdAgent_lift(_ handle: UInt64) throws -> FfiEdAgent { |
| 1111 | return try FfiConverterTypeFfiEdAgent.lift(handle) |
| 1112 | } |
| 1113 | |
| 1114 | #if swift(>=5.8) |
| 1115 | @_documentation(visibility: private) |
| 1116 | #endif |
| 1117 | public func FfiConverterTypeFfiEdAgent_lower(_ value: FfiEdAgent) -> UInt64 { |
| 1118 | return FfiConverterTypeFfiEdAgent.lower(value) |
| 1119 | } |
| 1120 | |
| 1121 | |
| 1122 | |
| 1123 | |
| 1124 | public struct FfiAgentConfig: Equatable, Hashable { |
| 1125 | public var maxToolRounds: UInt8 |
| 1126 | public var maxToolOutputChars: UInt64 |
| 1127 | |
| 1128 | // Default memberwise initializers are never public by default, so we |
| 1129 | // declare one manually. |
| 1130 | public init(maxToolRounds: UInt8, maxToolOutputChars: UInt64) { |
| 1131 | self.maxToolRounds = maxToolRounds |
| 1132 | self.maxToolOutputChars = maxToolOutputChars |
| 1133 | } |
| 1134 | |
| 1135 | |
| 1136 | |
| 1137 | |
| 1138 | } |
| 1139 | |
| 1140 | #if compiler(>=6) |
| 1141 | extension FfiAgentConfig: Sendable {} |
| 1142 | #endif |
| 1143 | |
| 1144 | #if swift(>=5.8) |
| 1145 | @_documentation(visibility: private) |
| 1146 | #endif |
| 1147 | public struct FfiConverterTypeFfiAgentConfig: FfiConverterRustBuffer { |
| 1148 | public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> FfiAgentConfig { |
| 1149 | return |
| 1150 | try FfiAgentConfig( |
| 1151 | maxToolRounds: FfiConverterUInt8.read(from: &buf), |
| 1152 | maxToolOutputChars: FfiConverterUInt64.read(from: &buf) |
| 1153 | ) |
| 1154 | } |
| 1155 | |
| 1156 | public static func write(_ value: FfiAgentConfig, into buf: inout [UInt8]) { |
| 1157 | FfiConverterUInt8.write(value.maxToolRounds, into: &buf) |
| 1158 | FfiConverterUInt64.write(value.maxToolOutputChars, into: &buf) |
| 1159 | } |
| 1160 | } |
| 1161 | |
| 1162 | |
| 1163 | #if swift(>=5.8) |
| 1164 | @_documentation(visibility: private) |
| 1165 | #endif |
| 1166 | public func FfiConverterTypeFfiAgentConfig_lift(_ buf: RustBuffer) throws -> FfiAgentConfig { |
| 1167 | return try FfiConverterTypeFfiAgentConfig.lift(buf) |
| 1168 | } |
| 1169 | |
| 1170 | #if swift(>=5.8) |
| 1171 | @_documentation(visibility: private) |
| 1172 | #endif |
| 1173 | public func FfiConverterTypeFfiAgentConfig_lower(_ value: FfiAgentConfig) -> RustBuffer { |
| 1174 | return FfiConverterTypeFfiAgentConfig.lower(value) |
| 1175 | } |
| 1176 | |
| 1177 | |
| 1178 | public struct FfiAgentReply: Equatable, Hashable { |
| 1179 | public var text: String |
| 1180 | public var durationSeconds: Double |
| 1181 | public var duration: String |
| 1182 | public var toolRounds: UInt8 |
| 1183 | |
| 1184 | // Default memberwise initializers are never public by default, so we |
| 1185 | // declare one manually. |
| 1186 | public init(text: String, durationSeconds: Double, duration: String, toolRounds: UInt8) { |
| 1187 | self.text = text |
| 1188 | self.durationSeconds = durationSeconds |
| 1189 | self.duration = duration |
| 1190 | self.toolRounds = toolRounds |
| 1191 | } |
| 1192 | |
| 1193 | |
| 1194 | |
| 1195 | |
| 1196 | } |
| 1197 | |
| 1198 | #if compiler(>=6) |
| 1199 | extension FfiAgentReply: Sendable {} |
| 1200 | #endif |
| 1201 | |
| 1202 | #if swift(>=5.8) |
| 1203 | @_documentation(visibility: private) |
| 1204 | #endif |
| 1205 | public struct FfiConverterTypeFfiAgentReply: FfiConverterRustBuffer { |
| 1206 | public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> FfiAgentReply { |
| 1207 | return |
| 1208 | try FfiAgentReply( |
| 1209 | text: FfiConverterString.read(from: &buf), |
| 1210 | durationSeconds: FfiConverterDouble.read(from: &buf), |
| 1211 | duration: FfiConverterString.read(from: &buf), |
| 1212 | toolRounds: FfiConverterUInt8.read(from: &buf) |
| 1213 | ) |
| 1214 | } |
| 1215 | |
| 1216 | public static func write(_ value: FfiAgentReply, into buf: inout [UInt8]) { |
| 1217 | FfiConverterString.write(value.text, into: &buf) |
| 1218 | FfiConverterDouble.write(value.durationSeconds, into: &buf) |
| 1219 | FfiConverterString.write(value.duration, into: &buf) |
| 1220 | FfiConverterUInt8.write(value.toolRounds, into: &buf) |
| 1221 | } |
| 1222 | } |
| 1223 | |
| 1224 | |
| 1225 | #if swift(>=5.8) |
| 1226 | @_documentation(visibility: private) |
| 1227 | #endif |
| 1228 | public func FfiConverterTypeFfiAgentReply_lift(_ buf: RustBuffer) throws -> FfiAgentReply { |
| 1229 | return try FfiConverterTypeFfiAgentReply.lift(buf) |
| 1230 | } |
| 1231 | |
| 1232 | #if swift(>=5.8) |
| 1233 | @_documentation(visibility: private) |
| 1234 | #endif |
| 1235 | public func FfiConverterTypeFfiAgentReply_lower(_ value: FfiAgentReply) -> RustBuffer { |
| 1236 | return FfiConverterTypeFfiAgentReply.lower(value) |
| 1237 | } |
| 1238 | |
| 1239 | |
| 1240 | /** |
| 1241 | * A tool call waiting on the user, with the risk that made it wait. |
| 1242 | * |
| 1243 | * The risk travels with the call because it is the reason an approval sheet |
| 1244 | * is on screen at all: a host that only received the call would have to look |
| 1245 | * the tool up again to tell the user whether it is about to change anything. |
| 1246 | */ |
| 1247 | public struct FfiApprovalRequest: Equatable, Hashable { |
| 1248 | public var call: FfiToolCall |
| 1249 | public var risk: FfiToolRisk |
| 1250 | |
| 1251 | // Default memberwise initializers are never public by default, so we |
| 1252 | // declare one manually. |
| 1253 | public init(call: FfiToolCall, risk: FfiToolRisk) { |
| 1254 | self.call = call |
| 1255 | self.risk = risk |
| 1256 | } |
| 1257 | |
| 1258 | |
| 1259 | |
| 1260 | |
| 1261 | } |
| 1262 | |
| 1263 | #if compiler(>=6) |
| 1264 | extension FfiApprovalRequest: Sendable {} |
| 1265 | #endif |
| 1266 | |
| 1267 | #if swift(>=5.8) |
| 1268 | @_documentation(visibility: private) |
| 1269 | #endif |
| 1270 | public struct FfiConverterTypeFfiApprovalRequest: FfiConverterRustBuffer { |
| 1271 | public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> FfiApprovalRequest { |
| 1272 | return |
| 1273 | try FfiApprovalRequest( |
| 1274 | call: FfiConverterTypeFfiToolCall.read(from: &buf), |
| 1275 | risk: FfiConverterTypeFfiToolRisk.read(from: &buf) |
| 1276 | ) |
| 1277 | } |
| 1278 | |
| 1279 | public static func write(_ value: FfiApprovalRequest, into buf: inout [UInt8]) { |
| 1280 | FfiConverterTypeFfiToolCall.write(value.call, into: &buf) |
| 1281 | FfiConverterTypeFfiToolRisk.write(value.risk, into: &buf) |
| 1282 | } |
| 1283 | } |
| 1284 | |
| 1285 | |
| 1286 | #if swift(>=5.8) |
| 1287 | @_documentation(visibility: private) |
| 1288 | #endif |
| 1289 | public func FfiConverterTypeFfiApprovalRequest_lift(_ buf: RustBuffer) throws -> FfiApprovalRequest { |
| 1290 | return try FfiConverterTypeFfiApprovalRequest.lift(buf) |
| 1291 | } |
| 1292 | |
| 1293 | #if swift(>=5.8) |
| 1294 | @_documentation(visibility: private) |
| 1295 | #endif |
| 1296 | public func FfiConverterTypeFfiApprovalRequest_lower(_ value: FfiApprovalRequest) -> RustBuffer { |
| 1297 | return FfiConverterTypeFfiApprovalRequest.lower(value) |
| 1298 | } |
| 1299 | |
| 1300 | |
| 1301 | public struct FfiChatMessage: Equatable, Hashable { |
| 1302 | public var role: FfiChatRole |
| 1303 | public var content: String |
| 1304 | |
| 1305 | // Default memberwise initializers are never public by default, so we |
| 1306 | // declare one manually. |
| 1307 | public init(role: FfiChatRole, content: String) { |
| 1308 | self.role = role |
| 1309 | self.content = content |
| 1310 | } |
| 1311 | |
| 1312 | |
| 1313 | |
| 1314 | |
| 1315 | } |
| 1316 | |
| 1317 | #if compiler(>=6) |
| 1318 | extension FfiChatMessage: Sendable {} |
| 1319 | #endif |
| 1320 | |
| 1321 | #if swift(>=5.8) |
| 1322 | @_documentation(visibility: private) |
| 1323 | #endif |
| 1324 | public struct FfiConverterTypeFfiChatMessage: FfiConverterRustBuffer { |
| 1325 | public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> FfiChatMessage { |
| 1326 | return |
| 1327 | try FfiChatMessage( |
| 1328 | role: FfiConverterTypeFfiChatRole.read(from: &buf), |
| 1329 | content: FfiConverterString.read(from: &buf) |
| 1330 | ) |
| 1331 | } |
| 1332 | |
| 1333 | public static func write(_ value: FfiChatMessage, into buf: inout [UInt8]) { |
| 1334 | FfiConverterTypeFfiChatRole.write(value.role, into: &buf) |
| 1335 | FfiConverterString.write(value.content, into: &buf) |
| 1336 | } |
| 1337 | } |
| 1338 | |
| 1339 | |
| 1340 | #if swift(>=5.8) |
| 1341 | @_documentation(visibility: private) |
| 1342 | #endif |
| 1343 | public func FfiConverterTypeFfiChatMessage_lift(_ buf: RustBuffer) throws -> FfiChatMessage { |
| 1344 | return try FfiConverterTypeFfiChatMessage.lift(buf) |
| 1345 | } |
| 1346 | |
| 1347 | #if swift(>=5.8) |
| 1348 | @_documentation(visibility: private) |
| 1349 | #endif |
| 1350 | public func FfiConverterTypeFfiChatMessage_lower(_ value: FfiChatMessage) -> RustBuffer { |
| 1351 | return FfiConverterTypeFfiChatMessage.lower(value) |
| 1352 | } |
| 1353 | |
| 1354 | |
| 1355 | public struct FfiEngineInfo: Equatable, Hashable { |
| 1356 | public var status: FfiEngineStatus |
| 1357 | public var modelName: String? |
| 1358 | public var approxMemory: String? |
| 1359 | public var historyLength: UInt64 |
| 1360 | |
| 1361 | // Default memberwise initializers are never public by default, so we |
| 1362 | // declare one manually. |
| 1363 | public init(status: FfiEngineStatus, modelName: String?, approxMemory: String?, historyLength: UInt64) { |
| 1364 | self.status = status |
| 1365 | self.modelName = modelName |
| 1366 | self.approxMemory = approxMemory |
| 1367 | self.historyLength = historyLength |
| 1368 | } |
| 1369 | |
| 1370 | |
| 1371 | |
| 1372 | |
| 1373 | } |
| 1374 | |
| 1375 | #if compiler(>=6) |
| 1376 | extension FfiEngineInfo: Sendable {} |
| 1377 | #endif |
| 1378 | |
| 1379 | #if swift(>=5.8) |
| 1380 | @_documentation(visibility: private) |
| 1381 | #endif |
| 1382 | public struct FfiConverterTypeFfiEngineInfo: FfiConverterRustBuffer { |
| 1383 | public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> FfiEngineInfo { |
| 1384 | return |
| 1385 | try FfiEngineInfo( |
| 1386 | status: FfiConverterTypeFfiEngineStatus.read(from: &buf), |
| 1387 | modelName: FfiConverterOptionString.read(from: &buf), |
| 1388 | approxMemory: FfiConverterOptionString.read(from: &buf), |
| 1389 | historyLength: FfiConverterUInt64.read(from: &buf) |
| 1390 | ) |
| 1391 | } |
| 1392 | |
| 1393 | public static func write(_ value: FfiEngineInfo, into buf: inout [UInt8]) { |
| 1394 | FfiConverterTypeFfiEngineStatus.write(value.status, into: &buf) |
| 1395 | FfiConverterOptionString.write(value.modelName, into: &buf) |
| 1396 | FfiConverterOptionString.write(value.approxMemory, into: &buf) |
| 1397 | FfiConverterUInt64.write(value.historyLength, into: &buf) |
| 1398 | } |
| 1399 | } |
| 1400 | |
| 1401 | |
| 1402 | #if swift(>=5.8) |
| 1403 | @_documentation(visibility: private) |
| 1404 | #endif |
| 1405 | public func FfiConverterTypeFfiEngineInfo_lift(_ buf: RustBuffer) throws -> FfiEngineInfo { |
| 1406 | return try FfiConverterTypeFfiEngineInfo.lift(buf) |
| 1407 | } |
| 1408 | |
| 1409 | #if swift(>=5.8) |
| 1410 | @_documentation(visibility: private) |
| 1411 | #endif |
| 1412 | public func FfiConverterTypeFfiEngineInfo_lower(_ value: FfiEngineInfo) -> RustBuffer { |
| 1413 | return FfiConverterTypeFfiEngineInfo.lower(value) |
| 1414 | } |
| 1415 | |
| 1416 | |
| 1417 | public struct FfiGgufModelConfig: Equatable, Hashable { |
| 1418 | public var modelId: String |
| 1419 | public var files: [String] |
| 1420 | public var tokModelId: String? |
| 1421 | public var displayName: String |
| 1422 | public var approxMemory: String |
| 1423 | public var chatTemplate: String? |
| 1424 | |
| 1425 | // Default memberwise initializers are never public by default, so we |
| 1426 | // declare one manually. |
| 1427 | public init(modelId: String, files: [String], tokModelId: String?, displayName: String, approxMemory: String, chatTemplate: String?) { |
| 1428 | self.modelId = modelId |
| 1429 | self.files = files |
| 1430 | self.tokModelId = tokModelId |
| 1431 | self.displayName = displayName |
| 1432 | self.approxMemory = approxMemory |
| 1433 | self.chatTemplate = chatTemplate |
| 1434 | } |
| 1435 | |
| 1436 | |
| 1437 | |
| 1438 | |
| 1439 | } |
| 1440 | |
| 1441 | #if compiler(>=6) |
| 1442 | extension FfiGgufModelConfig: Sendable {} |
| 1443 | #endif |
| 1444 | |
| 1445 | #if swift(>=5.8) |
| 1446 | @_documentation(visibility: private) |
| 1447 | #endif |
| 1448 | public struct FfiConverterTypeFfiGgufModelConfig: FfiConverterRustBuffer { |
| 1449 | public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> FfiGgufModelConfig { |
| 1450 | return |
| 1451 | try FfiGgufModelConfig( |
| 1452 | modelId: FfiConverterString.read(from: &buf), |
| 1453 | files: FfiConverterSequenceString.read(from: &buf), |
| 1454 | tokModelId: FfiConverterOptionString.read(from: &buf), |
| 1455 | displayName: FfiConverterString.read(from: &buf), |
| 1456 | approxMemory: FfiConverterString.read(from: &buf), |
| 1457 | chatTemplate: FfiConverterOptionString.read(from: &buf) |
| 1458 | ) |
| 1459 | } |
| 1460 | |
| 1461 | public static func write(_ value: FfiGgufModelConfig, into buf: inout [UInt8]) { |
| 1462 | FfiConverterString.write(value.modelId, into: &buf) |
| 1463 | FfiConverterSequenceString.write(value.files, into: &buf) |
| 1464 | FfiConverterOptionString.write(value.tokModelId, into: &buf) |
| 1465 | FfiConverterString.write(value.displayName, into: &buf) |
| 1466 | FfiConverterString.write(value.approxMemory, into: &buf) |
| 1467 | FfiConverterOptionString.write(value.chatTemplate, into: &buf) |
| 1468 | } |
| 1469 | } |
| 1470 | |
| 1471 | |
| 1472 | #if swift(>=5.8) |
| 1473 | @_documentation(visibility: private) |
| 1474 | #endif |
| 1475 | public func FfiConverterTypeFfiGgufModelConfig_lift(_ buf: RustBuffer) throws -> FfiGgufModelConfig { |
| 1476 | return try FfiConverterTypeFfiGgufModelConfig.lift(buf) |
| 1477 | } |
| 1478 | |
| 1479 | #if swift(>=5.8) |
| 1480 | @_documentation(visibility: private) |
| 1481 | #endif |
| 1482 | public func FfiConverterTypeFfiGgufModelConfig_lower(_ value: FfiGgufModelConfig) -> RustBuffer { |
| 1483 | return FfiConverterTypeFfiGgufModelConfig.lower(value) |
| 1484 | } |
| 1485 | |
| 1486 | |
| 1487 | public struct FfiReply: Equatable, Hashable { |
| 1488 | public var text: String |
| 1489 | public var duration: String |
| 1490 | |
| 1491 | // Default memberwise initializers are never public by default, so we |
| 1492 | // declare one manually. |
| 1493 | public init(text: String, duration: String) { |
| 1494 | self.text = text |
| 1495 | self.duration = duration |
| 1496 | } |
| 1497 | |
| 1498 | |
| 1499 | |
| 1500 | |
| 1501 | } |
| 1502 | |
| 1503 | #if compiler(>=6) |
| 1504 | extension FfiReply: Sendable {} |
| 1505 | #endif |
| 1506 | |
| 1507 | #if swift(>=5.8) |
| 1508 | @_documentation(visibility: private) |
| 1509 | #endif |
| 1510 | public struct FfiConverterTypeFfiReply: FfiConverterRustBuffer { |
| 1511 | public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> FfiReply { |
| 1512 | return |
| 1513 | try FfiReply( |
| 1514 | text: FfiConverterString.read(from: &buf), |
| 1515 | duration: FfiConverterString.read(from: &buf) |
| 1516 | ) |
| 1517 | } |
| 1518 | |
| 1519 | public static func write(_ value: FfiReply, into buf: inout [UInt8]) { |
| 1520 | FfiConverterString.write(value.text, into: &buf) |
| 1521 | FfiConverterString.write(value.duration, into: &buf) |
| 1522 | } |
| 1523 | } |
| 1524 | |
| 1525 | |
| 1526 | #if swift(>=5.8) |
| 1527 | @_documentation(visibility: private) |
| 1528 | #endif |
| 1529 | public func FfiConverterTypeFfiReply_lift(_ buf: RustBuffer) throws -> FfiReply { |
| 1530 | return try FfiConverterTypeFfiReply.lift(buf) |
| 1531 | } |
| 1532 | |
| 1533 | #if swift(>=5.8) |
| 1534 | @_documentation(visibility: private) |
| 1535 | #endif |
| 1536 | public func FfiConverterTypeFfiReply_lower(_ value: FfiReply) -> RustBuffer { |
| 1537 | return FfiConverterTypeFfiReply.lower(value) |
| 1538 | } |
| 1539 | |
| 1540 | |
| 1541 | public struct FfiSamplingConfig: Equatable, Hashable { |
| 1542 | public var temperature: Double? |
| 1543 | public var topP: Double? |
| 1544 | public var topK: UInt64? |
| 1545 | public var minP: Double? |
| 1546 | public var maxTokens: UInt64? |
| 1547 | public var frequencyPenalty: Float? |
| 1548 | public var presencePenalty: Float? |
| 1549 | |
| 1550 | // Default memberwise initializers are never public by default, so we |
| 1551 | // declare one manually. |
| 1552 | public init(temperature: Double?, topP: Double?, topK: UInt64?, minP: Double?, maxTokens: UInt64?, frequencyPenalty: Float?, presencePenalty: Float?) { |
| 1553 | self.temperature = temperature |
| 1554 | self.topP = topP |
| 1555 | self.topK = topK |
| 1556 | self.minP = minP |
| 1557 | self.maxTokens = maxTokens |
| 1558 | self.frequencyPenalty = frequencyPenalty |
| 1559 | self.presencePenalty = presencePenalty |
| 1560 | } |
| 1561 | |
| 1562 | |
| 1563 | |
| 1564 | |
| 1565 | } |
| 1566 | |
| 1567 | #if compiler(>=6) |
| 1568 | extension FfiSamplingConfig: Sendable {} |
| 1569 | #endif |
| 1570 | |
| 1571 | #if swift(>=5.8) |
| 1572 | @_documentation(visibility: private) |
| 1573 | #endif |
| 1574 | public struct FfiConverterTypeFfiSamplingConfig: FfiConverterRustBuffer { |
| 1575 | public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> FfiSamplingConfig { |
| 1576 | return |
| 1577 | try FfiSamplingConfig( |
| 1578 | temperature: FfiConverterOptionDouble.read(from: &buf), |
| 1579 | topP: FfiConverterOptionDouble.read(from: &buf), |
| 1580 | topK: FfiConverterOptionUInt64.read(from: &buf), |
| 1581 | minP: FfiConverterOptionDouble.read(from: &buf), |
| 1582 | maxTokens: FfiConverterOptionUInt64.read(from: &buf), |
| 1583 | frequencyPenalty: FfiConverterOptionFloat.read(from: &buf), |
| 1584 | presencePenalty: FfiConverterOptionFloat.read(from: &buf) |
| 1585 | ) |
| 1586 | } |
| 1587 | |
| 1588 | public static func write(_ value: FfiSamplingConfig, into buf: inout [UInt8]) { |
| 1589 | FfiConverterOptionDouble.write(value.temperature, into: &buf) |
| 1590 | FfiConverterOptionDouble.write(value.topP, into: &buf) |
| 1591 | FfiConverterOptionUInt64.write(value.topK, into: &buf) |
| 1592 | FfiConverterOptionDouble.write(value.minP, into: &buf) |
| 1593 | FfiConverterOptionUInt64.write(value.maxTokens, into: &buf) |
| 1594 | FfiConverterOptionFloat.write(value.frequencyPenalty, into: &buf) |
| 1595 | FfiConverterOptionFloat.write(value.presencePenalty, into: &buf) |
| 1596 | } |
| 1597 | } |
| 1598 | |
| 1599 | |
| 1600 | #if swift(>=5.8) |
| 1601 | @_documentation(visibility: private) |
| 1602 | #endif |
| 1603 | public func FfiConverterTypeFfiSamplingConfig_lift(_ buf: RustBuffer) throws -> FfiSamplingConfig { |
| 1604 | return try FfiConverterTypeFfiSamplingConfig.lift(buf) |
| 1605 | } |
| 1606 | |
| 1607 | #if swift(>=5.8) |
| 1608 | @_documentation(visibility: private) |
| 1609 | #endif |
| 1610 | public func FfiConverterTypeFfiSamplingConfig_lower(_ value: FfiSamplingConfig) -> RustBuffer { |
| 1611 | return FfiConverterTypeFfiSamplingConfig.lower(value) |
| 1612 | } |
| 1613 | |
| 1614 | |
| 1615 | public struct FfiStatusUpdate: Equatable, Hashable { |
| 1616 | public var status: FfiEngineStatus |
| 1617 | public var modelName: String? |
| 1618 | public var error: String? |
| 1619 | |
| 1620 | // Default memberwise initializers are never public by default, so we |
| 1621 | // declare one manually. |
| 1622 | public init(status: FfiEngineStatus, modelName: String?, error: String?) { |
| 1623 | self.status = status |
| 1624 | self.modelName = modelName |
| 1625 | self.error = error |
| 1626 | } |
| 1627 | |
| 1628 | |
| 1629 | |
| 1630 | |
| 1631 | } |
| 1632 | |
| 1633 | #if compiler(>=6) |
| 1634 | extension FfiStatusUpdate: Sendable {} |
| 1635 | #endif |
| 1636 | |
| 1637 | #if swift(>=5.8) |
| 1638 | @_documentation(visibility: private) |
| 1639 | #endif |
| 1640 | public struct FfiConverterTypeFfiStatusUpdate: FfiConverterRustBuffer { |
| 1641 | public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> FfiStatusUpdate { |
| 1642 | return |
| 1643 | try FfiStatusUpdate( |
| 1644 | status: FfiConverterTypeFfiEngineStatus.read(from: &buf), |
| 1645 | modelName: FfiConverterOptionString.read(from: &buf), |
| 1646 | error: FfiConverterOptionString.read(from: &buf) |
| 1647 | ) |
| 1648 | } |
| 1649 | |
| 1650 | public static func write(_ value: FfiStatusUpdate, into buf: inout [UInt8]) { |
| 1651 | FfiConverterTypeFfiEngineStatus.write(value.status, into: &buf) |
| 1652 | FfiConverterOptionString.write(value.modelName, into: &buf) |
| 1653 | FfiConverterOptionString.write(value.error, into: &buf) |
| 1654 | } |
| 1655 | } |
| 1656 | |
| 1657 | |
| 1658 | #if swift(>=5.8) |
| 1659 | @_documentation(visibility: private) |
| 1660 | #endif |
| 1661 | public func FfiConverterTypeFfiStatusUpdate_lift(_ buf: RustBuffer) throws -> FfiStatusUpdate { |
| 1662 | return try FfiConverterTypeFfiStatusUpdate.lift(buf) |
| 1663 | } |
| 1664 | |
| 1665 | #if swift(>=5.8) |
| 1666 | @_documentation(visibility: private) |
| 1667 | #endif |
| 1668 | public func FfiConverterTypeFfiStatusUpdate_lower(_ value: FfiStatusUpdate) -> RustBuffer { |
| 1669 | return FfiConverterTypeFfiStatusUpdate.lower(value) |
| 1670 | } |
| 1671 | |
| 1672 | |
| 1673 | public struct FfiToolCall: Equatable, Hashable { |
| 1674 | public var id: String |
| 1675 | public var name: String |
| 1676 | public var arguments: String |
| 1677 | |
| 1678 | // Default memberwise initializers are never public by default, so we |
| 1679 | // declare one manually. |
| 1680 | public init(id: String, name: String, arguments: String) { |
| 1681 | self.id = id |
| 1682 | self.name = name |
| 1683 | self.arguments = arguments |
| 1684 | } |
| 1685 | |
| 1686 | |
| 1687 | |
| 1688 | |
| 1689 | } |
| 1690 | |
| 1691 | #if compiler(>=6) |
| 1692 | extension FfiToolCall: Sendable {} |
| 1693 | #endif |
| 1694 | |
| 1695 | #if swift(>=5.8) |
| 1696 | @_documentation(visibility: private) |
| 1697 | #endif |
| 1698 | public struct FfiConverterTypeFfiToolCall: FfiConverterRustBuffer { |
| 1699 | public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> FfiToolCall { |
| 1700 | return |
| 1701 | try FfiToolCall( |
| 1702 | id: FfiConverterString.read(from: &buf), |
| 1703 | name: FfiConverterString.read(from: &buf), |
| 1704 | arguments: FfiConverterString.read(from: &buf) |
| 1705 | ) |
| 1706 | } |
| 1707 | |
| 1708 | public static func write(_ value: FfiToolCall, into buf: inout [UInt8]) { |
| 1709 | FfiConverterString.write(value.id, into: &buf) |
| 1710 | FfiConverterString.write(value.name, into: &buf) |
| 1711 | FfiConverterString.write(value.arguments, into: &buf) |
| 1712 | } |
| 1713 | } |
| 1714 | |
| 1715 | |
| 1716 | #if swift(>=5.8) |
| 1717 | @_documentation(visibility: private) |
| 1718 | #endif |
| 1719 | public func FfiConverterTypeFfiToolCall_lift(_ buf: RustBuffer) throws -> FfiToolCall { |
| 1720 | return try FfiConverterTypeFfiToolCall.lift(buf) |
| 1721 | } |
| 1722 | |
| 1723 | #if swift(>=5.8) |
| 1724 | @_documentation(visibility: private) |
| 1725 | #endif |
| 1726 | public func FfiConverterTypeFfiToolCall_lower(_ value: FfiToolCall) -> RustBuffer { |
| 1727 | return FfiConverterTypeFfiToolCall.lower(value) |
| 1728 | } |
| 1729 | |
| 1730 | |
| 1731 | public struct FfiToolDefinition: Equatable, Hashable { |
| 1732 | public var name: String |
| 1733 | public var description: String |
| 1734 | public var parametersSchema: String |
| 1735 | public var risk: FfiToolRisk |
| 1736 | |
| 1737 | // Default memberwise initializers are never public by default, so we |
| 1738 | // declare one manually. |
| 1739 | public init(name: String, description: String, parametersSchema: String, risk: FfiToolRisk) { |
| 1740 | self.name = name |
| 1741 | self.description = description |
| 1742 | self.parametersSchema = parametersSchema |
| 1743 | self.risk = risk |
| 1744 | } |
| 1745 | |
| 1746 | |
| 1747 | |
| 1748 | |
| 1749 | } |
| 1750 | |
| 1751 | #if compiler(>=6) |
| 1752 | extension FfiToolDefinition: Sendable {} |
| 1753 | #endif |
| 1754 | |
| 1755 | #if swift(>=5.8) |
| 1756 | @_documentation(visibility: private) |
| 1757 | #endif |
| 1758 | public struct FfiConverterTypeFfiToolDefinition: FfiConverterRustBuffer { |
| 1759 | public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> FfiToolDefinition { |
| 1760 | return |
| 1761 | try FfiToolDefinition( |
| 1762 | name: FfiConverterString.read(from: &buf), |
| 1763 | description: FfiConverterString.read(from: &buf), |
| 1764 | parametersSchema: FfiConverterString.read(from: &buf), |
| 1765 | risk: FfiConverterTypeFfiToolRisk.read(from: &buf) |
| 1766 | ) |
| 1767 | } |
| 1768 | |
| 1769 | public static func write(_ value: FfiToolDefinition, into buf: inout [UInt8]) { |
| 1770 | FfiConverterString.write(value.name, into: &buf) |
| 1771 | FfiConverterString.write(value.description, into: &buf) |
| 1772 | FfiConverterString.write(value.parametersSchema, into: &buf) |
| 1773 | FfiConverterTypeFfiToolRisk.write(value.risk, into: &buf) |
| 1774 | } |
| 1775 | } |
| 1776 | |
| 1777 | |
| 1778 | #if swift(>=5.8) |
| 1779 | @_documentation(visibility: private) |
| 1780 | #endif |
| 1781 | public func FfiConverterTypeFfiToolDefinition_lift(_ buf: RustBuffer) throws -> FfiToolDefinition { |
| 1782 | return try FfiConverterTypeFfiToolDefinition.lift(buf) |
| 1783 | } |
| 1784 | |
| 1785 | #if swift(>=5.8) |
| 1786 | @_documentation(visibility: private) |
| 1787 | #endif |
| 1788 | public func FfiConverterTypeFfiToolDefinition_lower(_ value: FfiToolDefinition) -> RustBuffer { |
| 1789 | return FfiConverterTypeFfiToolDefinition.lower(value) |
| 1790 | } |
| 1791 | |
| 1792 | |
| 1793 | public struct FfiToolOutput: Equatable, Hashable { |
| 1794 | public var content: String |
| 1795 | public var error: String? |
| 1796 | |
| 1797 | // Default memberwise initializers are never public by default, so we |
| 1798 | // declare one manually. |
| 1799 | public init(content: String, error: String?) { |
| 1800 | self.content = content |
| 1801 | self.error = error |
| 1802 | } |
| 1803 | |
| 1804 | |
| 1805 | |
| 1806 | |
| 1807 | } |
| 1808 | |
| 1809 | #if compiler(>=6) |
| 1810 | extension FfiToolOutput: Sendable {} |
| 1811 | #endif |
| 1812 | |
| 1813 | #if swift(>=5.8) |
| 1814 | @_documentation(visibility: private) |
| 1815 | #endif |
| 1816 | public struct FfiConverterTypeFfiToolOutput: FfiConverterRustBuffer { |
| 1817 | public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> FfiToolOutput { |
| 1818 | return |
| 1819 | try FfiToolOutput( |
| 1820 | content: FfiConverterString.read(from: &buf), |
| 1821 | error: FfiConverterOptionString.read(from: &buf) |
| 1822 | ) |
| 1823 | } |
| 1824 | |
| 1825 | public static func write(_ value: FfiToolOutput, into buf: inout [UInt8]) { |
| 1826 | FfiConverterString.write(value.content, into: &buf) |
| 1827 | FfiConverterOptionString.write(value.error, into: &buf) |
| 1828 | } |
| 1829 | } |
| 1830 | |
| 1831 | |
| 1832 | #if swift(>=5.8) |
| 1833 | @_documentation(visibility: private) |
| 1834 | #endif |
| 1835 | public func FfiConverterTypeFfiToolOutput_lift(_ buf: RustBuffer) throws -> FfiToolOutput { |
| 1836 | return try FfiConverterTypeFfiToolOutput.lift(buf) |
| 1837 | } |
| 1838 | |
| 1839 | #if swift(>=5.8) |
| 1840 | @_documentation(visibility: private) |
| 1841 | #endif |
| 1842 | public func FfiConverterTypeFfiToolOutput_lower(_ value: FfiToolOutput) -> RustBuffer { |
| 1843 | return FfiConverterTypeFfiToolOutput.lower(value) |
| 1844 | } |
| 1845 | |
| 1846 | |
| 1847 | public struct FfiUqffModelConfig: Equatable, Hashable { |
| 1848 | public var modelId: String |
| 1849 | public var files: [String] |
| 1850 | public var displayName: String |
| 1851 | public var approxMemory: String |
| 1852 | public var chatTemplate: String? |
| 1853 | |
| 1854 | // Default memberwise initializers are never public by default, so we |
| 1855 | // declare one manually. |
| 1856 | public init(modelId: String, files: [String], displayName: String, approxMemory: String, chatTemplate: String?) { |
| 1857 | self.modelId = modelId |
| 1858 | self.files = files |
| 1859 | self.displayName = displayName |
| 1860 | self.approxMemory = approxMemory |
| 1861 | self.chatTemplate = chatTemplate |
| 1862 | } |
| 1863 | |
| 1864 | |
| 1865 | |
| 1866 | |
| 1867 | } |
| 1868 | |
| 1869 | #if compiler(>=6) |
| 1870 | extension FfiUqffModelConfig: Sendable {} |
| 1871 | #endif |
| 1872 | |
| 1873 | #if swift(>=5.8) |
| 1874 | @_documentation(visibility: private) |
| 1875 | #endif |
| 1876 | public struct FfiConverterTypeFfiUqffModelConfig: FfiConverterRustBuffer { |
| 1877 | public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> FfiUqffModelConfig { |
| 1878 | return |
| 1879 | try FfiUqffModelConfig( |
| 1880 | modelId: FfiConverterString.read(from: &buf), |
| 1881 | files: FfiConverterSequenceString.read(from: &buf), |
| 1882 | displayName: FfiConverterString.read(from: &buf), |
| 1883 | approxMemory: FfiConverterString.read(from: &buf), |
| 1884 | chatTemplate: FfiConverterOptionString.read(from: &buf) |
| 1885 | ) |
| 1886 | } |
| 1887 | |
| 1888 | public static func write(_ value: FfiUqffModelConfig, into buf: inout [UInt8]) { |
| 1889 | FfiConverterString.write(value.modelId, into: &buf) |
| 1890 | FfiConverterSequenceString.write(value.files, into: &buf) |
| 1891 | FfiConverterString.write(value.displayName, into: &buf) |
| 1892 | FfiConverterString.write(value.approxMemory, into: &buf) |
| 1893 | FfiConverterOptionString.write(value.chatTemplate, into: &buf) |
| 1894 | } |
| 1895 | } |
| 1896 | |
| 1897 | |
| 1898 | #if swift(>=5.8) |
| 1899 | @_documentation(visibility: private) |
| 1900 | #endif |
| 1901 | public func FfiConverterTypeFfiUqffModelConfig_lift(_ buf: RustBuffer) throws -> FfiUqffModelConfig { |
| 1902 | return try FfiConverterTypeFfiUqffModelConfig.lift(buf) |
| 1903 | } |
| 1904 | |
| 1905 | #if swift(>=5.8) |
| 1906 | @_documentation(visibility: private) |
| 1907 | #endif |
| 1908 | public func FfiConverterTypeFfiUqffModelConfig_lower(_ value: FfiUqffModelConfig) -> RustBuffer { |
| 1909 | return FfiConverterTypeFfiUqffModelConfig.lower(value) |
| 1910 | } |
| 1911 | |
| 1912 | // Note that we don't yet support `indirect` for enums. |
| 1913 | // See https://github.com/mozilla/uniffi-rs/issues/396 for further discussion. |
| 1914 | |
| 1915 | public enum FfiApprovalDecision: Equatable, Hashable { |
| 1916 | |
| 1917 | case allowOnce |
| 1918 | case allowForSession |
| 1919 | case deny |
| 1920 | |
| 1921 | |
| 1922 | |
| 1923 | |
| 1924 | |
| 1925 | } |
| 1926 | |
| 1927 | #if compiler(>=6) |
| 1928 | extension FfiApprovalDecision: Sendable {} |
| 1929 | #endif |
| 1930 | |
| 1931 | #if swift(>=5.8) |
| 1932 | @_documentation(visibility: private) |
| 1933 | #endif |
| 1934 | public struct FfiConverterTypeFfiApprovalDecision: FfiConverterRustBuffer { |
| 1935 | typealias SwiftType = FfiApprovalDecision |
| 1936 | |
| 1937 | public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> FfiApprovalDecision { |
| 1938 | let variant: Int32 = try readInt(&buf) |
| 1939 | switch variant { |
| 1940 | |
| 1941 | case 1: return .allowOnce |
| 1942 | |
| 1943 | case 2: return .allowForSession |
| 1944 | |
| 1945 | case 3: return .deny |
| 1946 | |
| 1947 | default: throw UniffiInternalError.unexpectedEnumCase |
| 1948 | } |
| 1949 | } |
| 1950 | |
| 1951 | public static func write(_ value: FfiApprovalDecision, into buf: inout [UInt8]) { |
| 1952 | switch value { |
| 1953 | |
| 1954 | |
| 1955 | case .allowOnce: |
| 1956 | writeInt(&buf, Int32(1)) |
| 1957 | |
| 1958 | |
| 1959 | case .allowForSession: |
| 1960 | writeInt(&buf, Int32(2)) |
| 1961 | |
| 1962 | |
| 1963 | case .deny: |
| 1964 | writeInt(&buf, Int32(3)) |
| 1965 | |
| 1966 | } |
| 1967 | } |
| 1968 | } |
| 1969 | |
| 1970 | |
| 1971 | #if swift(>=5.8) |
| 1972 | @_documentation(visibility: private) |
| 1973 | #endif |
| 1974 | public func FfiConverterTypeFfiApprovalDecision_lift(_ buf: RustBuffer) throws -> FfiApprovalDecision { |
| 1975 | return try FfiConverterTypeFfiApprovalDecision.lift(buf) |
| 1976 | } |
| 1977 | |
| 1978 | #if swift(>=5.8) |
| 1979 | @_documentation(visibility: private) |
| 1980 | #endif |
| 1981 | public func FfiConverterTypeFfiApprovalDecision_lower(_ value: FfiApprovalDecision) -> RustBuffer { |
| 1982 | return FfiConverterTypeFfiApprovalDecision.lower(value) |
| 1983 | } |
| 1984 | |
| 1985 | |
| 1986 | // Note that we don't yet support `indirect` for enums. |
| 1987 | // See https://github.com/mozilla/uniffi-rs/issues/396 for further discussion. |
| 1988 | |
| 1989 | public enum FfiChatRole: Equatable, Hashable { |
| 1990 | |
| 1991 | case system |
| 1992 | case user |
| 1993 | case assistant |
| 1994 | |
| 1995 | |
| 1996 | |
| 1997 | |
| 1998 | |
| 1999 | } |
| 2000 | |
| 2001 | #if compiler(>=6) |
| 2002 | extension FfiChatRole: Sendable {} |
| 2003 | #endif |
| 2004 | |
| 2005 | #if swift(>=5.8) |
| 2006 | @_documentation(visibility: private) |
| 2007 | #endif |
| 2008 | public struct FfiConverterTypeFfiChatRole: FfiConverterRustBuffer { |
| 2009 | typealias SwiftType = FfiChatRole |
| 2010 | |
| 2011 | public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> FfiChatRole { |
| 2012 | let variant: Int32 = try readInt(&buf) |
| 2013 | switch variant { |
| 2014 | |
| 2015 | case 1: return .system |
| 2016 | |
| 2017 | case 2: return .user |
| 2018 | |
| 2019 | case 3: return .assistant |
| 2020 | |
| 2021 | default: throw UniffiInternalError.unexpectedEnumCase |
| 2022 | } |
| 2023 | } |
| 2024 | |
| 2025 | public static func write(_ value: FfiChatRole, into buf: inout [UInt8]) { |
| 2026 | switch value { |
| 2027 | |
| 2028 | |
| 2029 | case .system: |
| 2030 | writeInt(&buf, Int32(1)) |
| 2031 | |
| 2032 | |
| 2033 | case .user: |
| 2034 | writeInt(&buf, Int32(2)) |
| 2035 | |
| 2036 | |
| 2037 | case .assistant: |
| 2038 | writeInt(&buf, Int32(3)) |
| 2039 | |
| 2040 | } |
| 2041 | } |
| 2042 | } |
| 2043 | |
| 2044 | |
| 2045 | #if swift(>=5.8) |
| 2046 | @_documentation(visibility: private) |
| 2047 | #endif |
| 2048 | public func FfiConverterTypeFfiChatRole_lift(_ buf: RustBuffer) throws -> FfiChatRole { |
| 2049 | return try FfiConverterTypeFfiChatRole.lift(buf) |
| 2050 | } |
| 2051 | |
| 2052 | #if swift(>=5.8) |
| 2053 | @_documentation(visibility: private) |
| 2054 | #endif |
| 2055 | public func FfiConverterTypeFfiChatRole_lower(_ value: FfiChatRole) -> RustBuffer { |
| 2056 | return FfiConverterTypeFfiChatRole.lower(value) |
| 2057 | } |
| 2058 | |
| 2059 | |
| 2060 | |
| 2061 | public enum FfiEdError: Swift.Error, Equatable, Hashable, Foundation.LocalizedError { |
| 2062 | |
| 2063 | |
| 2064 | |
| 2065 | case Failure(reason: String |
| 2066 | ) |
| 2067 | |
| 2068 | |
| 2069 | |
| 2070 | |
| 2071 | |
| 2072 | |
| 2073 | public var errorDescription: String? { |
| 2074 | String(reflecting: self) |
| 2075 | } |
| 2076 | |
| 2077 | } |
| 2078 | |
| 2079 | #if compiler(>=6) |
| 2080 | extension FfiEdError: Sendable {} |
| 2081 | #endif |
| 2082 | |
| 2083 | #if swift(>=5.8) |
| 2084 | @_documentation(visibility: private) |
| 2085 | #endif |
| 2086 | public struct FfiConverterTypeFfiEdError: FfiConverterRustBuffer { |
| 2087 | typealias SwiftType = FfiEdError |
| 2088 | |
| 2089 | public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> FfiEdError { |
| 2090 | let variant: Int32 = try readInt(&buf) |
| 2091 | switch variant { |
| 2092 | |
| 2093 | |
| 2094 | |
| 2095 | |
| 2096 | case 1: return .Failure( |
| 2097 | reason: try FfiConverterString.read(from: &buf) |
| 2098 | ) |
| 2099 | |
| 2100 | default: throw UniffiInternalError.unexpectedEnumCase |
| 2101 | } |
| 2102 | } |
| 2103 | |
| 2104 | public static func write(_ value: FfiEdError, into buf: inout [UInt8]) { |
| 2105 | switch value { |
| 2106 | |
| 2107 | |
| 2108 | |
| 2109 | |
| 2110 | |
| 2111 | case let .Failure(reason): |
| 2112 | writeInt(&buf, Int32(1)) |
| 2113 | FfiConverterString.write(reason, into: &buf) |
| 2114 | |
| 2115 | } |
| 2116 | } |
| 2117 | } |
| 2118 | |
| 2119 | |
| 2120 | #if swift(>=5.8) |
| 2121 | @_documentation(visibility: private) |
| 2122 | #endif |
| 2123 | public func FfiConverterTypeFfiEdError_lift(_ buf: RustBuffer) throws -> FfiEdError { |
| 2124 | return try FfiConverterTypeFfiEdError.lift(buf) |
| 2125 | } |
| 2126 | |
| 2127 | #if swift(>=5.8) |
| 2128 | @_documentation(visibility: private) |
| 2129 | #endif |
| 2130 | public func FfiConverterTypeFfiEdError_lower(_ value: FfiEdError) -> RustBuffer { |
| 2131 | return FfiConverterTypeFfiEdError.lower(value) |
| 2132 | } |
| 2133 | |
| 2134 | // Note that we don't yet support `indirect` for enums. |
| 2135 | // See https://github.com/mozilla/uniffi-rs/issues/396 for further discussion. |
| 2136 | |
| 2137 | public enum FfiEngineStatus: Equatable, Hashable { |
| 2138 | |
| 2139 | case unloaded |
| 2140 | case loading |
| 2141 | case ready |
| 2142 | case generating |
| 2143 | case error |
| 2144 | |
| 2145 | |
| 2146 | |
| 2147 | |
| 2148 | |
| 2149 | } |
| 2150 | |
| 2151 | #if compiler(>=6) |
| 2152 | extension FfiEngineStatus: Sendable {} |
| 2153 | #endif |
| 2154 | |
| 2155 | #if swift(>=5.8) |
| 2156 | @_documentation(visibility: private) |
| 2157 | #endif |
| 2158 | public struct FfiConverterTypeFfiEngineStatus: FfiConverterRustBuffer { |
| 2159 | typealias SwiftType = FfiEngineStatus |
| 2160 | |
| 2161 | public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> FfiEngineStatus { |
| 2162 | let variant: Int32 = try readInt(&buf) |
| 2163 | switch variant { |
| 2164 | |
| 2165 | case 1: return .unloaded |
| 2166 | |
| 2167 | case 2: return .loading |
| 2168 | |
| 2169 | case 3: return .ready |
| 2170 | |
| 2171 | case 4: return .generating |
| 2172 | |
| 2173 | case 5: return .error |
| 2174 | |
| 2175 | default: throw UniffiInternalError.unexpectedEnumCase |
| 2176 | } |
| 2177 | } |
| 2178 | |
| 2179 | public static func write(_ value: FfiEngineStatus, into buf: inout [UInt8]) { |
| 2180 | switch value { |
| 2181 | |
| 2182 | |
| 2183 | case .unloaded: |
| 2184 | writeInt(&buf, Int32(1)) |
| 2185 | |
| 2186 | |
| 2187 | case .loading: |
| 2188 | writeInt(&buf, Int32(2)) |
| 2189 | |
| 2190 | |
| 2191 | case .ready: |
| 2192 | writeInt(&buf, Int32(3)) |
| 2193 | |
| 2194 | |
| 2195 | case .generating: |
| 2196 | writeInt(&buf, Int32(4)) |
| 2197 | |
| 2198 | |
| 2199 | case .error: |
| 2200 | writeInt(&buf, Int32(5)) |
| 2201 | |
| 2202 | } |
| 2203 | } |
| 2204 | } |
| 2205 | |
| 2206 | |
| 2207 | #if swift(>=5.8) |
| 2208 | @_documentation(visibility: private) |
| 2209 | #endif |
| 2210 | public func FfiConverterTypeFfiEngineStatus_lift(_ buf: RustBuffer) throws -> FfiEngineStatus { |
| 2211 | return try FfiConverterTypeFfiEngineStatus.lift(buf) |
| 2212 | } |
| 2213 | |
| 2214 | #if swift(>=5.8) |
| 2215 | @_documentation(visibility: private) |
| 2216 | #endif |
| 2217 | public func FfiConverterTypeFfiEngineStatus_lower(_ value: FfiEngineStatus) -> RustBuffer { |
| 2218 | return FfiConverterTypeFfiEngineStatus.lower(value) |
| 2219 | } |
| 2220 | |
| 2221 | |
| 2222 | // Note that we don't yet support `indirect` for enums. |
| 2223 | // See https://github.com/mozilla/uniffi-rs/issues/396 for further discussion. |
| 2224 | |
| 2225 | public enum FfiEnvironment: Equatable, Hashable { |
| 2226 | |
| 2227 | case development |
| 2228 | case production |
| 2229 | |
| 2230 | |
| 2231 | |
| 2232 | |
| 2233 | |
| 2234 | } |
| 2235 | |
| 2236 | #if compiler(>=6) |
| 2237 | extension FfiEnvironment: Sendable {} |
| 2238 | #endif |
| 2239 | |
| 2240 | #if swift(>=5.8) |
| 2241 | @_documentation(visibility: private) |
| 2242 | #endif |
| 2243 | public struct FfiConverterTypeFfiEnvironment: FfiConverterRustBuffer { |
| 2244 | typealias SwiftType = FfiEnvironment |
| 2245 | |
| 2246 | public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> FfiEnvironment { |
| 2247 | let variant: Int32 = try readInt(&buf) |
| 2248 | switch variant { |
| 2249 | |
| 2250 | case 1: return .development |
| 2251 | |
| 2252 | case 2: return .production |
| 2253 | |
| 2254 | default: throw UniffiInternalError.unexpectedEnumCase |
| 2255 | } |
| 2256 | } |
| 2257 | |
| 2258 | public static func write(_ value: FfiEnvironment, into buf: inout [UInt8]) { |
| 2259 | switch value { |
| 2260 | |
| 2261 | |
| 2262 | case .development: |
| 2263 | writeInt(&buf, Int32(1)) |
| 2264 | |
| 2265 | |
| 2266 | case .production: |
| 2267 | writeInt(&buf, Int32(2)) |
| 2268 | |
| 2269 | } |
| 2270 | } |
| 2271 | } |
| 2272 | |
| 2273 | |
| 2274 | #if swift(>=5.8) |
| 2275 | @_documentation(visibility: private) |
| 2276 | #endif |
| 2277 | public func FfiConverterTypeFfiEnvironment_lift(_ buf: RustBuffer) throws -> FfiEnvironment { |
| 2278 | return try FfiConverterTypeFfiEnvironment.lift(buf) |
| 2279 | } |
| 2280 | |
| 2281 | #if swift(>=5.8) |
| 2282 | @_documentation(visibility: private) |
| 2283 | #endif |
| 2284 | public func FfiConverterTypeFfiEnvironment_lower(_ value: FfiEnvironment) -> RustBuffer { |
| 2285 | return FfiConverterTypeFfiEnvironment.lower(value) |
| 2286 | } |
| 2287 | |
| 2288 | |
| 2289 | // Note that we don't yet support `indirect` for enums. |
| 2290 | // See https://github.com/mozilla/uniffi-rs/issues/396 for further discussion. |
| 2291 | |
| 2292 | public enum FfiToolRisk: Equatable, Hashable { |
| 2293 | |
| 2294 | case readOnly |
| 2295 | case mutating |
| 2296 | |
| 2297 | |
| 2298 | |
| 2299 | |
| 2300 | |
| 2301 | } |
| 2302 | |
| 2303 | #if compiler(>=6) |
| 2304 | extension FfiToolRisk: Sendable {} |
| 2305 | #endif |
| 2306 | |
| 2307 | #if swift(>=5.8) |
| 2308 | @_documentation(visibility: private) |
| 2309 | #endif |
| 2310 | public struct FfiConverterTypeFfiToolRisk: FfiConverterRustBuffer { |
| 2311 | typealias SwiftType = FfiToolRisk |
| 2312 | |
| 2313 | public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> FfiToolRisk { |
| 2314 | let variant: Int32 = try readInt(&buf) |
| 2315 | switch variant { |
| 2316 | |
| 2317 | case 1: return .readOnly |
| 2318 | |
| 2319 | case 2: return .mutating |
| 2320 | |
| 2321 | default: throw UniffiInternalError.unexpectedEnumCase |
| 2322 | } |
| 2323 | } |
| 2324 | |
| 2325 | public static func write(_ value: FfiToolRisk, into buf: inout [UInt8]) { |
| 2326 | switch value { |
| 2327 | |
| 2328 | |
| 2329 | case .readOnly: |
| 2330 | writeInt(&buf, Int32(1)) |
| 2331 | |
| 2332 | |
| 2333 | case .mutating: |
| 2334 | writeInt(&buf, Int32(2)) |
| 2335 | |
| 2336 | } |
| 2337 | } |
| 2338 | } |
| 2339 | |
| 2340 | |
| 2341 | #if swift(>=5.8) |
| 2342 | @_documentation(visibility: private) |
| 2343 | #endif |
| 2344 | public func FfiConverterTypeFfiToolRisk_lift(_ buf: RustBuffer) throws -> FfiToolRisk { |
| 2345 | return try FfiConverterTypeFfiToolRisk.lift(buf) |
| 2346 | } |
| 2347 | |
| 2348 | #if swift(>=5.8) |
| 2349 | @_documentation(visibility: private) |
| 2350 | #endif |
| 2351 | public func FfiConverterTypeFfiToolRisk_lower(_ value: FfiToolRisk) -> RustBuffer { |
| 2352 | return FfiConverterTypeFfiToolRisk.lower(value) |
| 2353 | } |
| 2354 | |
| 2355 | |
| 2356 | |
| 2357 | |
| 2358 | |
| 2359 | public protocol FfiApprovalHandler: AnyObject, Sendable { |
| 2360 | |
| 2361 | func approve(request: FfiApprovalRequest) async -> FfiApprovalDecision |
| 2362 | |
| 2363 | } |
| 2364 | |
| 2365 | |
| 2366 | // Put the implementation in a struct so we don't pollute the top-level namespace |
| 2367 | fileprivate struct UniffiCallbackInterfaceFfiApprovalHandler { |
| 2368 | |
| 2369 | // Create the VTable using a series of closures. |
| 2370 | // Swift automatically converts these into C callback functions. |
| 2371 | // |
| 2372 | // This creates 1-element array, since this seems to be the only way to construct a const |
| 2373 | // pointer that we can pass to the Rust code. |
| 2374 | static let vtable: [UniffiVTableCallbackInterfaceFfiApprovalHandler] = [UniffiVTableCallbackInterfaceFfiApprovalHandler( |
| 2375 | uniffiFree: { (uniffiHandle: UInt64) -> () in |
| 2376 | do { |
| 2377 | try FfiConverterCallbackInterfaceFfiApprovalHandler.handleMap.remove(handle: uniffiHandle) |
| 2378 | } catch { |
| 2379 | print("Uniffi callback interface FfiApprovalHandler: handle missing in uniffiFree") |
| 2380 | } |
| 2381 | }, |
| 2382 | uniffiClone: { (uniffiHandle: UInt64) -> UInt64 in |
| 2383 | do { |
| 2384 | return try FfiConverterCallbackInterfaceFfiApprovalHandler.handleMap.clone(handle: uniffiHandle) |
| 2385 | } catch { |
| 2386 | fatalError("Uniffi callback interface FfiApprovalHandler: handle missing in uniffiClone") |
| 2387 | } |
| 2388 | }, |
| 2389 | approve: { ( |
| 2390 | uniffiHandle: UInt64, |
| 2391 | request: RustBuffer, |
| 2392 | uniffiFutureCallback: @escaping UniffiForeignFutureCompleteRustBuffer, |
| 2393 | uniffiCallbackData: UInt64, |
| 2394 | uniffiOutDroppedCallback: UnsafeMutablePointer<UniffiForeignFutureDroppedCallbackStruct> |
| 2395 | ) in |
| 2396 | let makeCall = { |
| 2397 | () async throws -> FfiApprovalDecision in |
| 2398 | guard let uniffiObj = try? FfiConverterCallbackInterfaceFfiApprovalHandler.handleMap.get(handle: uniffiHandle) else { |
| 2399 | throw UniffiInternalError.unexpectedStaleHandle |
| 2400 | } |
| 2401 | return await uniffiObj.approve( |
| 2402 | request: try FfiConverterTypeFfiApprovalRequest_lift(request) |
| 2403 | ) |
| 2404 | } |
| 2405 | |
| 2406 | let uniffiHandleSuccess = { (returnValue: FfiApprovalDecision) in |
| 2407 | uniffiFutureCallback( |
| 2408 | uniffiCallbackData, |
| 2409 | UniffiForeignFutureResultRustBuffer( |
| 2410 | returnValue: FfiConverterTypeFfiApprovalDecision_lower(returnValue), |
| 2411 | callStatus: RustCallStatus() |
| 2412 | ) |
| 2413 | ) |
| 2414 | } |
| 2415 | let uniffiHandleError = { (statusCode, errorBuf) in |
| 2416 | uniffiFutureCallback( |
| 2417 | uniffiCallbackData, |
| 2418 | UniffiForeignFutureResultRustBuffer( |
| 2419 | returnValue: RustBuffer.empty(), |
| 2420 | callStatus: RustCallStatus(code: statusCode, errorBuf: errorBuf) |
| 2421 | ) |
| 2422 | ) |
| 2423 | } |
| 2424 | uniffiTraitInterfaceCallAsync( |
| 2425 | makeCall: makeCall, |
| 2426 | handleSuccess: uniffiHandleSuccess, |
| 2427 | handleError: uniffiHandleError, |
| 2428 | droppedCallback: uniffiOutDroppedCallback |
| 2429 | ) |
| 2430 | } |
| 2431 | )] |
| 2432 | } |
| 2433 | |
| 2434 | private func uniffiCallbackInitFfiApprovalHandler() { |
| 2435 | uniffi_ed_agent_ffi_fn_init_callback_vtable_ffiapprovalhandler(UniffiCallbackInterfaceFfiApprovalHandler.vtable) |
| 2436 | } |
| 2437 | |
| 2438 | // FfiConverter protocol for callback interfaces |
| 2439 | #if swift(>=5.8) |
| 2440 | @_documentation(visibility: private) |
| 2441 | #endif |
| 2442 | fileprivate struct FfiConverterCallbackInterfaceFfiApprovalHandler { |
| 2443 | fileprivate static let handleMap = UniffiHandleMap<FfiApprovalHandler>() |
| 2444 | } |
| 2445 | |
| 2446 | #if swift(>=5.8) |
| 2447 | @_documentation(visibility: private) |
| 2448 | #endif |
| 2449 | extension FfiConverterCallbackInterfaceFfiApprovalHandler : FfiConverter { |
| 2450 | typealias SwiftType = FfiApprovalHandler |
| 2451 | typealias FfiType = UInt64 |
| 2452 | |
| 2453 | #if swift(>=5.8) |
| 2454 | @_documentation(visibility: private) |
| 2455 | #endif |
| 2456 | public static func lift(_ handle: UInt64) throws -> SwiftType { |
| 2457 | try handleMap.get(handle: handle) |
| 2458 | } |
| 2459 | |
| 2460 | #if swift(>=5.8) |
| 2461 | @_documentation(visibility: private) |
| 2462 | #endif |
| 2463 | public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> SwiftType { |
| 2464 | let handle: UInt64 = try readInt(&buf) |
| 2465 | return try lift(handle) |
| 2466 | } |
| 2467 | |
| 2468 | #if swift(>=5.8) |
| 2469 | @_documentation(visibility: private) |
| 2470 | #endif |
| 2471 | public static func lower(_ v: SwiftType) -> UInt64 { |
| 2472 | return handleMap.insert(obj: v) |
| 2473 | } |
| 2474 | |
| 2475 | #if swift(>=5.8) |
| 2476 | @_documentation(visibility: private) |
| 2477 | #endif |
| 2478 | public static func write(_ v: SwiftType, into buf: inout [UInt8]) { |
| 2479 | writeInt(&buf, lower(v)) |
| 2480 | } |
| 2481 | } |
| 2482 | |
| 2483 | |
| 2484 | #if swift(>=5.8) |
| 2485 | @_documentation(visibility: private) |
| 2486 | #endif |
| 2487 | public func FfiConverterCallbackInterfaceFfiApprovalHandler_lift(_ handle: UInt64) throws -> FfiApprovalHandler { |
| 2488 | return try FfiConverterCallbackInterfaceFfiApprovalHandler.lift(handle) |
| 2489 | } |
| 2490 | |
| 2491 | #if swift(>=5.8) |
| 2492 | @_documentation(visibility: private) |
| 2493 | #endif |
| 2494 | public func FfiConverterCallbackInterfaceFfiApprovalHandler_lower(_ v: FfiApprovalHandler) -> UInt64 { |
| 2495 | return FfiConverterCallbackInterfaceFfiApprovalHandler.lower(v) |
| 2496 | } |
| 2497 | |
| 2498 | |
| 2499 | |
| 2500 | |
| 2501 | public protocol FfiEventListener: AnyObject, Sendable { |
| 2502 | |
| 2503 | func statusChanged(update: FfiStatusUpdate) |
| 2504 | |
| 2505 | /** |
| 2506 | * A piece of the reply as it is generated, during `run`. |
| 2507 | */ |
| 2508 | func textDelta(delta: String) |
| 2509 | |
| 2510 | func toolRequested(call: FfiToolCall) |
| 2511 | |
| 2512 | func approvalRequested(request: FfiApprovalRequest) |
| 2513 | |
| 2514 | func toolStarted(call: FfiToolCall) |
| 2515 | |
| 2516 | func toolFinished(toolCallId: String, content: String, isError: Bool) |
| 2517 | |
| 2518 | func agentReplied(reply: FfiAgentReply) |
| 2519 | |
| 2520 | func warning(message: String) |
| 2521 | |
| 2522 | } |
| 2523 | |
| 2524 | |
| 2525 | // Put the implementation in a struct so we don't pollute the top-level namespace |
| 2526 | fileprivate struct UniffiCallbackInterfaceFfiEventListener { |
| 2527 | |
| 2528 | // Create the VTable using a series of closures. |
| 2529 | // Swift automatically converts these into C callback functions. |
| 2530 | // |
| 2531 | // This creates 1-element array, since this seems to be the only way to construct a const |
| 2532 | // pointer that we can pass to the Rust code. |
| 2533 | static let vtable: [UniffiVTableCallbackInterfaceFfiEventListener] = [UniffiVTableCallbackInterfaceFfiEventListener( |
| 2534 | uniffiFree: { (uniffiHandle: UInt64) -> () in |
| 2535 | do { |
| 2536 | try FfiConverterCallbackInterfaceFfiEventListener.handleMap.remove(handle: uniffiHandle) |
| 2537 | } catch { |
| 2538 | print("Uniffi callback interface FfiEventListener: handle missing in uniffiFree") |
| 2539 | } |
| 2540 | }, |
| 2541 | uniffiClone: { (uniffiHandle: UInt64) -> UInt64 in |
| 2542 | do { |
| 2543 | return try FfiConverterCallbackInterfaceFfiEventListener.handleMap.clone(handle: uniffiHandle) |
| 2544 | } catch { |
| 2545 | fatalError("Uniffi callback interface FfiEventListener: handle missing in uniffiClone") |
| 2546 | } |
| 2547 | }, |
| 2548 | statusChanged: { ( |
| 2549 | uniffiHandle: UInt64, |
| 2550 | update: RustBuffer, |
| 2551 | uniffiOutReturn: UnsafeMutableRawPointer, |
| 2552 | uniffiCallStatus: UnsafeMutablePointer<RustCallStatus> |
| 2553 | ) in |
| 2554 | let makeCall = { |
| 2555 | () throws -> () in |
| 2556 | guard let uniffiObj = try? FfiConverterCallbackInterfaceFfiEventListener.handleMap.get(handle: uniffiHandle) else { |
| 2557 | throw UniffiInternalError.unexpectedStaleHandle |
| 2558 | } |
| 2559 | return uniffiObj.statusChanged( |
| 2560 | update: try FfiConverterTypeFfiStatusUpdate_lift(update) |
| 2561 | ) |
| 2562 | } |
| 2563 | |
| 2564 | |
| 2565 | let writeReturn = { () } |
| 2566 | uniffiTraitInterfaceCall( |
| 2567 | callStatus: uniffiCallStatus, |
| 2568 | makeCall: makeCall, |
| 2569 | writeReturn: writeReturn |
| 2570 | ) |
| 2571 | }, |
| 2572 | textDelta: { ( |
| 2573 | uniffiHandle: UInt64, |
| 2574 | delta: RustBuffer, |
| 2575 | uniffiOutReturn: UnsafeMutableRawPointer, |
| 2576 | uniffiCallStatus: UnsafeMutablePointer<RustCallStatus> |
| 2577 | ) in |
| 2578 | let makeCall = { |
| 2579 | () throws -> () in |
| 2580 | guard let uniffiObj = try? FfiConverterCallbackInterfaceFfiEventListener.handleMap.get(handle: uniffiHandle) else { |
| 2581 | throw UniffiInternalError.unexpectedStaleHandle |
| 2582 | } |
| 2583 | return uniffiObj.textDelta( |
| 2584 | delta: try FfiConverterString.lift(delta) |
| 2585 | ) |
| 2586 | } |
| 2587 | |
| 2588 | |
| 2589 | let writeReturn = { () } |
| 2590 | uniffiTraitInterfaceCall( |
| 2591 | callStatus: uniffiCallStatus, |
| 2592 | makeCall: makeCall, |
| 2593 | writeReturn: writeReturn |
| 2594 | ) |
| 2595 | }, |
| 2596 | toolRequested: { ( |
| 2597 | uniffiHandle: UInt64, |
| 2598 | call: RustBuffer, |
| 2599 | uniffiOutReturn: UnsafeMutableRawPointer, |
| 2600 | uniffiCallStatus: UnsafeMutablePointer<RustCallStatus> |
| 2601 | ) in |
| 2602 | let makeCall = { |
| 2603 | () throws -> () in |
| 2604 | guard let uniffiObj = try? FfiConverterCallbackInterfaceFfiEventListener.handleMap.get(handle: uniffiHandle) else { |
| 2605 | throw UniffiInternalError.unexpectedStaleHandle |
| 2606 | } |
| 2607 | return uniffiObj.toolRequested( |
| 2608 | call: try FfiConverterTypeFfiToolCall_lift(call) |
| 2609 | ) |
| 2610 | } |
| 2611 | |
| 2612 | |
| 2613 | let writeReturn = { () } |
| 2614 | uniffiTraitInterfaceCall( |
| 2615 | callStatus: uniffiCallStatus, |
| 2616 | makeCall: makeCall, |
| 2617 | writeReturn: writeReturn |
| 2618 | ) |
| 2619 | }, |
| 2620 | approvalRequested: { ( |
| 2621 | uniffiHandle: UInt64, |
| 2622 | request: RustBuffer, |
| 2623 | uniffiOutReturn: UnsafeMutableRawPointer, |
| 2624 | uniffiCallStatus: UnsafeMutablePointer<RustCallStatus> |
| 2625 | ) in |
| 2626 | let makeCall = { |
| 2627 | () throws -> () in |
| 2628 | guard let uniffiObj = try? FfiConverterCallbackInterfaceFfiEventListener.handleMap.get(handle: uniffiHandle) else { |
| 2629 | throw UniffiInternalError.unexpectedStaleHandle |
| 2630 | } |
| 2631 | return uniffiObj.approvalRequested( |
| 2632 | request: try FfiConverterTypeFfiApprovalRequest_lift(request) |
| 2633 | ) |
| 2634 | } |
| 2635 | |
| 2636 | |
| 2637 | let writeReturn = { () } |
| 2638 | uniffiTraitInterfaceCall( |
| 2639 | callStatus: uniffiCallStatus, |
| 2640 | makeCall: makeCall, |
| 2641 | writeReturn: writeReturn |
| 2642 | ) |
| 2643 | }, |
| 2644 | toolStarted: { ( |
| 2645 | uniffiHandle: UInt64, |
| 2646 | call: RustBuffer, |
| 2647 | uniffiOutReturn: UnsafeMutableRawPointer, |
| 2648 | uniffiCallStatus: UnsafeMutablePointer<RustCallStatus> |
| 2649 | ) in |
| 2650 | let makeCall = { |
| 2651 | () throws -> () in |
| 2652 | guard let uniffiObj = try? FfiConverterCallbackInterfaceFfiEventListener.handleMap.get(handle: uniffiHandle) else { |
| 2653 | throw UniffiInternalError.unexpectedStaleHandle |
| 2654 | } |
| 2655 | return uniffiObj.toolStarted( |
| 2656 | call: try FfiConverterTypeFfiToolCall_lift(call) |
| 2657 | ) |
| 2658 | } |
| 2659 | |
| 2660 | |
| 2661 | let writeReturn = { () } |
| 2662 | uniffiTraitInterfaceCall( |
| 2663 | callStatus: uniffiCallStatus, |
| 2664 | makeCall: makeCall, |
| 2665 | writeReturn: writeReturn |
| 2666 | ) |
| 2667 | }, |
| 2668 | toolFinished: { ( |
| 2669 | uniffiHandle: UInt64, |
| 2670 | toolCallId: RustBuffer, |
| 2671 | content: RustBuffer, |
| 2672 | isError: Int8, |
| 2673 | uniffiOutReturn: UnsafeMutableRawPointer, |
| 2674 | uniffiCallStatus: UnsafeMutablePointer<RustCallStatus> |
| 2675 | ) in |
| 2676 | let makeCall = { |
| 2677 | () throws -> () in |
| 2678 | guard let uniffiObj = try? FfiConverterCallbackInterfaceFfiEventListener.handleMap.get(handle: uniffiHandle) else { |
| 2679 | throw UniffiInternalError.unexpectedStaleHandle |
| 2680 | } |
| 2681 | return uniffiObj.toolFinished( |
| 2682 | toolCallId: try FfiConverterString.lift(toolCallId), |
| 2683 | content: try FfiConverterString.lift(content), |
| 2684 | isError: try FfiConverterBool.lift(isError) |
| 2685 | ) |
| 2686 | } |
| 2687 | |
| 2688 | |
| 2689 | let writeReturn = { () } |
| 2690 | uniffiTraitInterfaceCall( |
| 2691 | callStatus: uniffiCallStatus, |
| 2692 | makeCall: makeCall, |
| 2693 | writeReturn: writeReturn |
| 2694 | ) |
| 2695 | }, |
| 2696 | agentReplied: { ( |
| 2697 | uniffiHandle: UInt64, |
| 2698 | reply: RustBuffer, |
| 2699 | uniffiOutReturn: UnsafeMutableRawPointer, |
| 2700 | uniffiCallStatus: UnsafeMutablePointer<RustCallStatus> |
| 2701 | ) in |
| 2702 | let makeCall = { |
| 2703 | () throws -> () in |
| 2704 | guard let uniffiObj = try? FfiConverterCallbackInterfaceFfiEventListener.handleMap.get(handle: uniffiHandle) else { |
| 2705 | throw UniffiInternalError.unexpectedStaleHandle |
| 2706 | } |
| 2707 | return uniffiObj.agentReplied( |
| 2708 | reply: try FfiConverterTypeFfiAgentReply_lift(reply) |
| 2709 | ) |
| 2710 | } |
| 2711 | |
| 2712 | |
| 2713 | let writeReturn = { () } |
| 2714 | uniffiTraitInterfaceCall( |
| 2715 | callStatus: uniffiCallStatus, |
| 2716 | makeCall: makeCall, |
| 2717 | writeReturn: writeReturn |
| 2718 | ) |
| 2719 | }, |
| 2720 | warning: { ( |
| 2721 | uniffiHandle: UInt64, |
| 2722 | message: RustBuffer, |
| 2723 | uniffiOutReturn: UnsafeMutableRawPointer, |
| 2724 | uniffiCallStatus: UnsafeMutablePointer<RustCallStatus> |
| 2725 | ) in |
| 2726 | let makeCall = { |
| 2727 | () throws -> () in |
| 2728 | guard let uniffiObj = try? FfiConverterCallbackInterfaceFfiEventListener.handleMap.get(handle: uniffiHandle) else { |
| 2729 | throw UniffiInternalError.unexpectedStaleHandle |
| 2730 | } |
| 2731 | return uniffiObj.warning( |
| 2732 | message: try FfiConverterString.lift(message) |
| 2733 | ) |
| 2734 | } |
| 2735 | |
| 2736 | |
| 2737 | let writeReturn = { () } |
| 2738 | uniffiTraitInterfaceCall( |
| 2739 | callStatus: uniffiCallStatus, |
| 2740 | makeCall: makeCall, |
| 2741 | writeReturn: writeReturn |
| 2742 | ) |
| 2743 | } |
| 2744 | )] |
| 2745 | } |
| 2746 | |
| 2747 | private func uniffiCallbackInitFfiEventListener() { |
| 2748 | uniffi_ed_agent_ffi_fn_init_callback_vtable_ffieventlistener(UniffiCallbackInterfaceFfiEventListener.vtable) |
| 2749 | } |
| 2750 | |
| 2751 | // FfiConverter protocol for callback interfaces |
| 2752 | #if swift(>=5.8) |
| 2753 | @_documentation(visibility: private) |
| 2754 | #endif |
| 2755 | fileprivate struct FfiConverterCallbackInterfaceFfiEventListener { |
| 2756 | fileprivate static let handleMap = UniffiHandleMap<FfiEventListener>() |
| 2757 | } |
| 2758 | |
| 2759 | #if swift(>=5.8) |
| 2760 | @_documentation(visibility: private) |
| 2761 | #endif |
| 2762 | extension FfiConverterCallbackInterfaceFfiEventListener : FfiConverter { |
| 2763 | typealias SwiftType = FfiEventListener |
| 2764 | typealias FfiType = UInt64 |
| 2765 | |
| 2766 | #if swift(>=5.8) |
| 2767 | @_documentation(visibility: private) |
| 2768 | #endif |
| 2769 | public static func lift(_ handle: UInt64) throws -> SwiftType { |
| 2770 | try handleMap.get(handle: handle) |
| 2771 | } |
| 2772 | |
| 2773 | #if swift(>=5.8) |
| 2774 | @_documentation(visibility: private) |
| 2775 | #endif |
| 2776 | public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> SwiftType { |
| 2777 | let handle: UInt64 = try readInt(&buf) |
| 2778 | return try lift(handle) |
| 2779 | } |
| 2780 | |
| 2781 | #if swift(>=5.8) |
| 2782 | @_documentation(visibility: private) |
| 2783 | #endif |
| 2784 | public static func lower(_ v: SwiftType) -> UInt64 { |
| 2785 | return handleMap.insert(obj: v) |
| 2786 | } |
| 2787 | |
| 2788 | #if swift(>=5.8) |
| 2789 | @_documentation(visibility: private) |
| 2790 | #endif |
| 2791 | public static func write(_ v: SwiftType, into buf: inout [UInt8]) { |
| 2792 | writeInt(&buf, lower(v)) |
| 2793 | } |
| 2794 | } |
| 2795 | |
| 2796 | |
| 2797 | #if swift(>=5.8) |
| 2798 | @_documentation(visibility: private) |
| 2799 | #endif |
| 2800 | public func FfiConverterCallbackInterfaceFfiEventListener_lift(_ handle: UInt64) throws -> FfiEventListener { |
| 2801 | return try FfiConverterCallbackInterfaceFfiEventListener.lift(handle) |
| 2802 | } |
| 2803 | |
| 2804 | #if swift(>=5.8) |
| 2805 | @_documentation(visibility: private) |
| 2806 | #endif |
| 2807 | public func FfiConverterCallbackInterfaceFfiEventListener_lower(_ v: FfiEventListener) -> UInt64 { |
| 2808 | return FfiConverterCallbackInterfaceFfiEventListener.lower(v) |
| 2809 | } |
| 2810 | |
| 2811 | |
| 2812 | |
| 2813 | |
| 2814 | /** |
| 2815 | * Receives a streamed reply from `stream_message`. |
| 2816 | */ |
| 2817 | public protocol FfiStreamListener: AnyObject, Sendable { |
| 2818 | |
| 2819 | func onDelta(delta: String) |
| 2820 | |
| 2821 | } |
| 2822 | |
| 2823 | |
| 2824 | // Put the implementation in a struct so we don't pollute the top-level namespace |
| 2825 | fileprivate struct UniffiCallbackInterfaceFfiStreamListener { |
| 2826 | |
| 2827 | // Create the VTable using a series of closures. |
| 2828 | // Swift automatically converts these into C callback functions. |
| 2829 | // |
| 2830 | // This creates 1-element array, since this seems to be the only way to construct a const |
| 2831 | // pointer that we can pass to the Rust code. |
| 2832 | static let vtable: [UniffiVTableCallbackInterfaceFfiStreamListener] = [UniffiVTableCallbackInterfaceFfiStreamListener( |
| 2833 | uniffiFree: { (uniffiHandle: UInt64) -> () in |
| 2834 | do { |
| 2835 | try FfiConverterCallbackInterfaceFfiStreamListener.handleMap.remove(handle: uniffiHandle) |
| 2836 | } catch { |
| 2837 | print("Uniffi callback interface FfiStreamListener: handle missing in uniffiFree") |
| 2838 | } |
| 2839 | }, |
| 2840 | uniffiClone: { (uniffiHandle: UInt64) -> UInt64 in |
| 2841 | do { |
| 2842 | return try FfiConverterCallbackInterfaceFfiStreamListener.handleMap.clone(handle: uniffiHandle) |
| 2843 | } catch { |
| 2844 | fatalError("Uniffi callback interface FfiStreamListener: handle missing in uniffiClone") |
| 2845 | } |
| 2846 | }, |
| 2847 | onDelta: { ( |
| 2848 | uniffiHandle: UInt64, |
| 2849 | delta: RustBuffer, |
| 2850 | uniffiOutReturn: UnsafeMutableRawPointer, |
| 2851 | uniffiCallStatus: UnsafeMutablePointer<RustCallStatus> |
| 2852 | ) in |
| 2853 | let makeCall = { |
| 2854 | () throws -> () in |
| 2855 | guard let uniffiObj = try? FfiConverterCallbackInterfaceFfiStreamListener.handleMap.get(handle: uniffiHandle) else { |
| 2856 | throw UniffiInternalError.unexpectedStaleHandle |
| 2857 | } |
| 2858 | return uniffiObj.onDelta( |
| 2859 | delta: try FfiConverterString.lift(delta) |
| 2860 | ) |
| 2861 | } |
| 2862 | |
| 2863 | |
| 2864 | let writeReturn = { () } |
| 2865 | uniffiTraitInterfaceCall( |
| 2866 | callStatus: uniffiCallStatus, |
| 2867 | makeCall: makeCall, |
| 2868 | writeReturn: writeReturn |
| 2869 | ) |
| 2870 | } |
| 2871 | )] |
| 2872 | } |
| 2873 | |
| 2874 | private func uniffiCallbackInitFfiStreamListener() { |
| 2875 | uniffi_ed_agent_ffi_fn_init_callback_vtable_ffistreamlistener(UniffiCallbackInterfaceFfiStreamListener.vtable) |
| 2876 | } |
| 2877 | |
| 2878 | // FfiConverter protocol for callback interfaces |
| 2879 | #if swift(>=5.8) |
| 2880 | @_documentation(visibility: private) |
| 2881 | #endif |
| 2882 | fileprivate struct FfiConverterCallbackInterfaceFfiStreamListener { |
| 2883 | fileprivate static let handleMap = UniffiHandleMap<FfiStreamListener>() |
| 2884 | } |
| 2885 | |
| 2886 | #if swift(>=5.8) |
| 2887 | @_documentation(visibility: private) |
| 2888 | #endif |
| 2889 | extension FfiConverterCallbackInterfaceFfiStreamListener : FfiConverter { |
| 2890 | typealias SwiftType = FfiStreamListener |
| 2891 | typealias FfiType = UInt64 |
| 2892 | |
| 2893 | #if swift(>=5.8) |
| 2894 | @_documentation(visibility: private) |
| 2895 | #endif |
| 2896 | public static func lift(_ handle: UInt64) throws -> SwiftType { |
| 2897 | try handleMap.get(handle: handle) |
| 2898 | } |
| 2899 | |
| 2900 | #if swift(>=5.8) |
| 2901 | @_documentation(visibility: private) |
| 2902 | #endif |
| 2903 | public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> SwiftType { |
| 2904 | let handle: UInt64 = try readInt(&buf) |
| 2905 | return try lift(handle) |
| 2906 | } |
| 2907 | |
| 2908 | #if swift(>=5.8) |
| 2909 | @_documentation(visibility: private) |
| 2910 | #endif |
| 2911 | public static func lower(_ v: SwiftType) -> UInt64 { |
| 2912 | return handleMap.insert(obj: v) |
| 2913 | } |
| 2914 | |
| 2915 | #if swift(>=5.8) |
| 2916 | @_documentation(visibility: private) |
| 2917 | #endif |
| 2918 | public static func write(_ v: SwiftType, into buf: inout [UInt8]) { |
| 2919 | writeInt(&buf, lower(v)) |
| 2920 | } |
| 2921 | } |
| 2922 | |
| 2923 | |
| 2924 | #if swift(>=5.8) |
| 2925 | @_documentation(visibility: private) |
| 2926 | #endif |
| 2927 | public func FfiConverterCallbackInterfaceFfiStreamListener_lift(_ handle: UInt64) throws -> FfiStreamListener { |
| 2928 | return try FfiConverterCallbackInterfaceFfiStreamListener.lift(handle) |
| 2929 | } |
| 2930 | |
| 2931 | #if swift(>=5.8) |
| 2932 | @_documentation(visibility: private) |
| 2933 | #endif |
| 2934 | public func FfiConverterCallbackInterfaceFfiStreamListener_lower(_ v: FfiStreamListener) -> UInt64 { |
| 2935 | return FfiConverterCallbackInterfaceFfiStreamListener.lower(v) |
| 2936 | } |
| 2937 | |
| 2938 | |
| 2939 | |
| 2940 | |
| 2941 | public protocol FfiToolExecutor: AnyObject, Sendable { |
| 2942 | |
| 2943 | func execute(toolName: String, arguments: String) async -> FfiToolOutput |
| 2944 | |
| 2945 | } |
| 2946 | |
| 2947 | |
| 2948 | // Put the implementation in a struct so we don't pollute the top-level namespace |
| 2949 | fileprivate struct UniffiCallbackInterfaceFfiToolExecutor { |
| 2950 | |
| 2951 | // Create the VTable using a series of closures. |
| 2952 | // Swift automatically converts these into C callback functions. |
| 2953 | // |
| 2954 | // This creates 1-element array, since this seems to be the only way to construct a const |
| 2955 | // pointer that we can pass to the Rust code. |
| 2956 | static let vtable: [UniffiVTableCallbackInterfaceFfiToolExecutor] = [UniffiVTableCallbackInterfaceFfiToolExecutor( |
| 2957 | uniffiFree: { (uniffiHandle: UInt64) -> () in |
| 2958 | do { |
| 2959 | try FfiConverterCallbackInterfaceFfiToolExecutor.handleMap.remove(handle: uniffiHandle) |
| 2960 | } catch { |
| 2961 | print("Uniffi callback interface FfiToolExecutor: handle missing in uniffiFree") |
| 2962 | } |
| 2963 | }, |
| 2964 | uniffiClone: { (uniffiHandle: UInt64) -> UInt64 in |
| 2965 | do { |
| 2966 | return try FfiConverterCallbackInterfaceFfiToolExecutor.handleMap.clone(handle: uniffiHandle) |
| 2967 | } catch { |
| 2968 | fatalError("Uniffi callback interface FfiToolExecutor: handle missing in uniffiClone") |
| 2969 | } |
| 2970 | }, |
| 2971 | execute: { ( |
| 2972 | uniffiHandle: UInt64, |
| 2973 | toolName: RustBuffer, |
| 2974 | arguments: RustBuffer, |
| 2975 | uniffiFutureCallback: @escaping UniffiForeignFutureCompleteRustBuffer, |
| 2976 | uniffiCallbackData: UInt64, |
| 2977 | uniffiOutDroppedCallback: UnsafeMutablePointer<UniffiForeignFutureDroppedCallbackStruct> |
| 2978 | ) in |
| 2979 | let makeCall = { |
| 2980 | () async throws -> FfiToolOutput in |
| 2981 | guard let uniffiObj = try? FfiConverterCallbackInterfaceFfiToolExecutor.handleMap.get(handle: uniffiHandle) else { |
| 2982 | throw UniffiInternalError.unexpectedStaleHandle |
| 2983 | } |
| 2984 | return await uniffiObj.execute( |
| 2985 | toolName: try FfiConverterString.lift(toolName), |
| 2986 | arguments: try FfiConverterString.lift(arguments) |
| 2987 | ) |
| 2988 | } |
| 2989 | |
| 2990 | let uniffiHandleSuccess = { (returnValue: FfiToolOutput) in |
| 2991 | uniffiFutureCallback( |
| 2992 | uniffiCallbackData, |
| 2993 | UniffiForeignFutureResultRustBuffer( |
| 2994 | returnValue: FfiConverterTypeFfiToolOutput_lower(returnValue), |
| 2995 | callStatus: RustCallStatus() |
| 2996 | ) |
| 2997 | ) |
| 2998 | } |
| 2999 | let uniffiHandleError = { (statusCode, errorBuf) in |
| 3000 | uniffiFutureCallback( |
| 3001 | uniffiCallbackData, |
| 3002 | UniffiForeignFutureResultRustBuffer( |
| 3003 | returnValue: RustBuffer.empty(), |
| 3004 | callStatus: RustCallStatus(code: statusCode, errorBuf: errorBuf) |
| 3005 | ) |
| 3006 | ) |
| 3007 | } |
| 3008 | uniffiTraitInterfaceCallAsync( |
| 3009 | makeCall: makeCall, |
| 3010 | handleSuccess: uniffiHandleSuccess, |
| 3011 | handleError: uniffiHandleError, |
| 3012 | droppedCallback: uniffiOutDroppedCallback |
| 3013 | ) |
| 3014 | } |
| 3015 | )] |
| 3016 | } |
| 3017 | |
| 3018 | private func uniffiCallbackInitFfiToolExecutor() { |
| 3019 | uniffi_ed_agent_ffi_fn_init_callback_vtable_ffitoolexecutor(UniffiCallbackInterfaceFfiToolExecutor.vtable) |
| 3020 | } |
| 3021 | |
| 3022 | // FfiConverter protocol for callback interfaces |
| 3023 | #if swift(>=5.8) |
| 3024 | @_documentation(visibility: private) |
| 3025 | #endif |
| 3026 | fileprivate struct FfiConverterCallbackInterfaceFfiToolExecutor { |
| 3027 | fileprivate static let handleMap = UniffiHandleMap<FfiToolExecutor>() |
| 3028 | } |
| 3029 | |
| 3030 | #if swift(>=5.8) |
| 3031 | @_documentation(visibility: private) |
| 3032 | #endif |
| 3033 | extension FfiConverterCallbackInterfaceFfiToolExecutor : FfiConverter { |
| 3034 | typealias SwiftType = FfiToolExecutor |
| 3035 | typealias FfiType = UInt64 |
| 3036 | |
| 3037 | #if swift(>=5.8) |
| 3038 | @_documentation(visibility: private) |
| 3039 | #endif |
| 3040 | public static func lift(_ handle: UInt64) throws -> SwiftType { |
| 3041 | try handleMap.get(handle: handle) |
| 3042 | } |
| 3043 | |
| 3044 | #if swift(>=5.8) |
| 3045 | @_documentation(visibility: private) |
| 3046 | #endif |
| 3047 | public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> SwiftType { |
| 3048 | let handle: UInt64 = try readInt(&buf) |
| 3049 | return try lift(handle) |
| 3050 | } |
| 3051 | |
| 3052 | #if swift(>=5.8) |
| 3053 | @_documentation(visibility: private) |
| 3054 | #endif |
| 3055 | public static func lower(_ v: SwiftType) -> UInt64 { |
| 3056 | return handleMap.insert(obj: v) |
| 3057 | } |
| 3058 | |
| 3059 | #if swift(>=5.8) |
| 3060 | @_documentation(visibility: private) |
| 3061 | #endif |
| 3062 | public static func write(_ v: SwiftType, into buf: inout [UInt8]) { |
| 3063 | writeInt(&buf, lower(v)) |
| 3064 | } |
| 3065 | } |
| 3066 | |
| 3067 | |
| 3068 | #if swift(>=5.8) |
| 3069 | @_documentation(visibility: private) |
| 3070 | #endif |
| 3071 | public func FfiConverterCallbackInterfaceFfiToolExecutor_lift(_ handle: UInt64) throws -> FfiToolExecutor { |
| 3072 | return try FfiConverterCallbackInterfaceFfiToolExecutor.lift(handle) |
| 3073 | } |
| 3074 | |
| 3075 | #if swift(>=5.8) |
| 3076 | @_documentation(visibility: private) |
| 3077 | #endif |
| 3078 | public func FfiConverterCallbackInterfaceFfiToolExecutor_lower(_ v: FfiToolExecutor) -> UInt64 { |
| 3079 | return FfiConverterCallbackInterfaceFfiToolExecutor.lower(v) |
| 3080 | } |
| 3081 | |
| 3082 | #if swift(>=5.8) |
| 3083 | @_documentation(visibility: private) |
| 3084 | #endif |
| 3085 | fileprivate struct FfiConverterOptionUInt64: FfiConverterRustBuffer { |
| 3086 | typealias SwiftType = UInt64? |
| 3087 | |
| 3088 | public static func write(_ value: SwiftType, into buf: inout [UInt8]) { |
| 3089 | guard let value = value else { |
| 3090 | writeInt(&buf, Int8(0)) |
| 3091 | return |
| 3092 | } |
| 3093 | writeInt(&buf, Int8(1)) |
| 3094 | FfiConverterUInt64.write(value, into: &buf) |
| 3095 | } |
| 3096 | |
| 3097 | public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> SwiftType { |
| 3098 | switch try readInt(&buf) as Int8 { |
| 3099 | case 0: return nil |
| 3100 | case 1: return try FfiConverterUInt64.read(from: &buf) |
| 3101 | default: throw UniffiInternalError.unexpectedOptionalTag |
| 3102 | } |
| 3103 | } |
| 3104 | } |
| 3105 | |
| 3106 | #if swift(>=5.8) |
| 3107 | @_documentation(visibility: private) |
| 3108 | #endif |
| 3109 | fileprivate struct FfiConverterOptionFloat: FfiConverterRustBuffer { |
| 3110 | typealias SwiftType = Float? |
| 3111 | |
| 3112 | public static func write(_ value: SwiftType, into buf: inout [UInt8]) { |
| 3113 | guard let value = value else { |
| 3114 | writeInt(&buf, Int8(0)) |
| 3115 | return |
| 3116 | } |
| 3117 | writeInt(&buf, Int8(1)) |
| 3118 | FfiConverterFloat.write(value, into: &buf) |
| 3119 | } |
| 3120 | |
| 3121 | public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> SwiftType { |
| 3122 | switch try readInt(&buf) as Int8 { |
| 3123 | case 0: return nil |
| 3124 | case 1: return try FfiConverterFloat.read(from: &buf) |
| 3125 | default: throw UniffiInternalError.unexpectedOptionalTag |
| 3126 | } |
| 3127 | } |
| 3128 | } |
| 3129 | |
| 3130 | #if swift(>=5.8) |
| 3131 | @_documentation(visibility: private) |
| 3132 | #endif |
| 3133 | fileprivate struct FfiConverterOptionDouble: FfiConverterRustBuffer { |
| 3134 | typealias SwiftType = Double? |
| 3135 | |
| 3136 | public static func write(_ value: SwiftType, into buf: inout [UInt8]) { |
| 3137 | guard let value = value else { |
| 3138 | writeInt(&buf, Int8(0)) |
| 3139 | return |
| 3140 | } |
| 3141 | writeInt(&buf, Int8(1)) |
| 3142 | FfiConverterDouble.write(value, into: &buf) |
| 3143 | } |
| 3144 | |
| 3145 | public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> SwiftType { |
| 3146 | switch try readInt(&buf) as Int8 { |
| 3147 | case 0: return nil |
| 3148 | case 1: return try FfiConverterDouble.read(from: &buf) |
| 3149 | default: throw UniffiInternalError.unexpectedOptionalTag |
| 3150 | } |
| 3151 | } |
| 3152 | } |
| 3153 | |
| 3154 | #if swift(>=5.8) |
| 3155 | @_documentation(visibility: private) |
| 3156 | #endif |
| 3157 | fileprivate struct FfiConverterOptionString: FfiConverterRustBuffer { |
| 3158 | typealias SwiftType = String? |
| 3159 | |
| 3160 | public static func write(_ value: SwiftType, into buf: inout [UInt8]) { |
| 3161 | guard let value = value else { |
| 3162 | writeInt(&buf, Int8(0)) |
| 3163 | return |
| 3164 | } |
| 3165 | writeInt(&buf, Int8(1)) |
| 3166 | FfiConverterString.write(value, into: &buf) |
| 3167 | } |
| 3168 | |
| 3169 | public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> SwiftType { |
| 3170 | switch try readInt(&buf) as Int8 { |
| 3171 | case 0: return nil |
| 3172 | case 1: return try FfiConverterString.read(from: &buf) |
| 3173 | default: throw UniffiInternalError.unexpectedOptionalTag |
| 3174 | } |
| 3175 | } |
| 3176 | } |
| 3177 | |
| 3178 | #if swift(>=5.8) |
| 3179 | @_documentation(visibility: private) |
| 3180 | #endif |
| 3181 | fileprivate struct FfiConverterOptionTypeFfiAgentConfig: FfiConverterRustBuffer { |
| 3182 | typealias SwiftType = FfiAgentConfig? |
| 3183 | |
| 3184 | public static func write(_ value: SwiftType, into buf: inout [UInt8]) { |
| 3185 | guard let value = value else { |
| 3186 | writeInt(&buf, Int8(0)) |
| 3187 | return |
| 3188 | } |
| 3189 | writeInt(&buf, Int8(1)) |
| 3190 | FfiConverterTypeFfiAgentConfig.write(value, into: &buf) |
| 3191 | } |
| 3192 | |
| 3193 | public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> SwiftType { |
| 3194 | switch try readInt(&buf) as Int8 { |
| 3195 | case 0: return nil |
| 3196 | case 1: return try FfiConverterTypeFfiAgentConfig.read(from: &buf) |
| 3197 | default: throw UniffiInternalError.unexpectedOptionalTag |
| 3198 | } |
| 3199 | } |
| 3200 | } |
| 3201 | |
| 3202 | #if swift(>=5.8) |
| 3203 | @_documentation(visibility: private) |
| 3204 | #endif |
| 3205 | fileprivate struct FfiConverterOptionTypeFfiSamplingConfig: FfiConverterRustBuffer { |
| 3206 | typealias SwiftType = FfiSamplingConfig? |
| 3207 | |
| 3208 | public static func write(_ value: SwiftType, into buf: inout [UInt8]) { |
| 3209 | guard let value = value else { |
| 3210 | writeInt(&buf, Int8(0)) |
| 3211 | return |
| 3212 | } |
| 3213 | writeInt(&buf, Int8(1)) |
| 3214 | FfiConverterTypeFfiSamplingConfig.write(value, into: &buf) |
| 3215 | } |
| 3216 | |
| 3217 | public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> SwiftType { |
| 3218 | switch try readInt(&buf) as Int8 { |
| 3219 | case 0: return nil |
| 3220 | case 1: return try FfiConverterTypeFfiSamplingConfig.read(from: &buf) |
| 3221 | default: throw UniffiInternalError.unexpectedOptionalTag |
| 3222 | } |
| 3223 | } |
| 3224 | } |
| 3225 | |
| 3226 | #if swift(>=5.8) |
| 3227 | @_documentation(visibility: private) |
| 3228 | #endif |
| 3229 | fileprivate struct FfiConverterSequenceString: FfiConverterRustBuffer { |
| 3230 | typealias SwiftType = [String] |
| 3231 | |
| 3232 | public static func write(_ value: [String], into buf: inout [UInt8]) { |
| 3233 | let len = Int32(value.count) |
| 3234 | writeInt(&buf, len) |
| 3235 | for item in value { |
| 3236 | FfiConverterString.write(item, into: &buf) |
| 3237 | } |
| 3238 | } |
| 3239 | |
| 3240 | public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> [String] { |
| 3241 | let len: Int32 = try readInt(&buf) |
| 3242 | var seq = [String]() |
| 3243 | seq.reserveCapacity(Int(len)) |
| 3244 | for _ in 0 ..< len { |
| 3245 | seq.append(try FfiConverterString.read(from: &buf)) |
| 3246 | } |
| 3247 | return seq |
| 3248 | } |
| 3249 | } |
| 3250 | |
| 3251 | #if swift(>=5.8) |
| 3252 | @_documentation(visibility: private) |
| 3253 | #endif |
| 3254 | fileprivate struct FfiConverterSequenceTypeFfiChatMessage: FfiConverterRustBuffer { |
| 3255 | typealias SwiftType = [FfiChatMessage] |
| 3256 | |
| 3257 | public static func write(_ value: [FfiChatMessage], into buf: inout [UInt8]) { |
| 3258 | let len = Int32(value.count) |
| 3259 | writeInt(&buf, len) |
| 3260 | for item in value { |
| 3261 | FfiConverterTypeFfiChatMessage.write(item, into: &buf) |
| 3262 | } |
| 3263 | } |
| 3264 | |
| 3265 | public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> [FfiChatMessage] { |
| 3266 | let len: Int32 = try readInt(&buf) |
| 3267 | var seq = [FfiChatMessage]() |
| 3268 | seq.reserveCapacity(Int(len)) |
| 3269 | for _ in 0 ..< len { |
| 3270 | seq.append(try FfiConverterTypeFfiChatMessage.read(from: &buf)) |
| 3271 | } |
| 3272 | return seq |
| 3273 | } |
| 3274 | } |
| 3275 | private let UNIFFI_RUST_FUTURE_POLL_READY: Int8 = 0 |
| 3276 | private let UNIFFI_RUST_FUTURE_POLL_WAKE: Int8 = 1 |
| 3277 | |
| 3278 | fileprivate let uniffiContinuationHandleMap = UniffiHandleMap<UnsafeContinuation<Int8, Never>>() |
| 3279 | |
| 3280 | fileprivate func uniffiRustCallAsync<F, T>( |
| 3281 | rustFutureFunc: () -> UInt64, |
| 3282 | pollFunc: (UInt64, @escaping UniffiRustFutureContinuationCallback, UInt64) -> (), |
| 3283 | completeFunc: (UInt64, UnsafeMutablePointer<RustCallStatus>) -> F, |
| 3284 | freeFunc: (UInt64) -> (), |
| 3285 | liftFunc: (F) throws -> T, |
| 3286 | errorHandler: ((RustBuffer) throws -> Swift.Error)? |
| 3287 | ) async throws -> T { |
| 3288 | // Make sure to call the ensure init function since future creation doesn't have a |
| 3289 | // RustCallStatus param, so doesn't use makeRustCall() |
| 3290 | uniffiEnsureEdAgentFfiInitialized() |
| 3291 | let rustFuture = rustFutureFunc() |
| 3292 | defer { |
| 3293 | freeFunc(rustFuture) |
| 3294 | } |
| 3295 | var pollResult: Int8; |
| 3296 | repeat { |
| 3297 | pollResult = await withUnsafeContinuation { |
| 3298 | pollFunc( |
| 3299 | rustFuture, |
| 3300 | { handle, pollResult in |
| 3301 | uniffiFutureContinuationCallback(handle: handle, pollResult: pollResult) |
| 3302 | }, |
| 3303 | uniffiContinuationHandleMap.insert(obj: $0) |
| 3304 | ) |
| 3305 | } |
| 3306 | } while pollResult != UNIFFI_RUST_FUTURE_POLL_READY |
| 3307 | |
| 3308 | return try liftFunc(makeRustCall( |
| 3309 | { completeFunc(rustFuture, $0) }, |
| 3310 | errorHandler: errorHandler |
| 3311 | )) |
| 3312 | } |
| 3313 | |
| 3314 | // Callback handlers for an async calls. These are invoked by Rust when the future is ready. They |
| 3315 | // lift the return value or error and resume the suspended function. |
| 3316 | fileprivate func uniffiFutureContinuationCallback(handle: UInt64, pollResult: Int8) { |
| 3317 | if let continuation = try? uniffiContinuationHandleMap.remove(handle: handle) { |
| 3318 | continuation.resume(returning: pollResult) |
| 3319 | } else { |
| 3320 | print("uniffiFutureContinuationCallback invalid handle") |
| 3321 | } |
| 3322 | } |
| 3323 | private func uniffiTraitInterfaceCallAsync<T>( |
| 3324 | makeCall: @escaping () async throws -> T, |
| 3325 | handleSuccess: @escaping (T) -> (), |
| 3326 | handleError: @escaping (Int8, RustBuffer) -> (), |
| 3327 | droppedCallback: UnsafeMutablePointer<UniffiForeignFutureDroppedCallbackStruct> |
| 3328 | ) { |
| 3329 | let task = Task { |
| 3330 | // Note: it's important we call either `handleSuccess` or `handleError` exactly once. Each |
| 3331 | // call consumes an Arc reference, which means there should be no possibility of a double |
| 3332 | // call. The following code is structured so that will will never call both `handleSuccess` |
| 3333 | // and `handleError`, even in the face of weird errors. |
| 3334 | // |
| 3335 | // On platforms that need extra machinery to make C-ABI calls, like JNA or ctypes, it's |
| 3336 | // possible that we fail to make either call. However, it doesn't seem like this is |
| 3337 | // possible on Swift since swift can just make the C call directly. |
| 3338 | var callResult: T |
| 3339 | do { |
| 3340 | callResult = try await makeCall() |
| 3341 | } catch { |
| 3342 | handleError(CALL_UNEXPECTED_ERROR, FfiConverterString.lower(String(describing: error))) |
| 3343 | return |
| 3344 | } |
| 3345 | handleSuccess(callResult) |
| 3346 | } |
| 3347 | let handle = UNIFFI_FOREIGN_FUTURE_HANDLE_MAP.insert(obj: task) |
| 3348 | droppedCallback.pointee = UniffiForeignFutureDroppedCallbackStruct( |
| 3349 | handle: handle, |
| 3350 | free: uniffiForeignFutureDroppedCallback |
| 3351 | ) |
| 3352 | } |
| 3353 | |
| 3354 | private func uniffiTraitInterfaceCallAsyncWithError<T, E>( |
| 3355 | makeCall: @escaping () async throws -> T, |
| 3356 | handleSuccess: @escaping (T) -> (), |
| 3357 | handleError: @escaping (Int8, RustBuffer) -> (), |
| 3358 | lowerError: @escaping (E) -> RustBuffer, |
| 3359 | droppedCallback: UnsafeMutablePointer<UniffiForeignFutureDroppedCallbackStruct> |
| 3360 | ) { |
| 3361 | let task = Task { |
| 3362 | // See the note in uniffiTraitInterfaceCallAsync for details on `handleSuccess` and |
| 3363 | // `handleError`. |
| 3364 | var callResult: T |
| 3365 | do { |
| 3366 | callResult = try await makeCall() |
| 3367 | } catch let error as E { |
| 3368 | handleError(CALL_ERROR, lowerError(error)) |
| 3369 | return |
| 3370 | } catch { |
| 3371 | handleError(CALL_UNEXPECTED_ERROR, FfiConverterString.lower(String(describing: error))) |
| 3372 | return |
| 3373 | } |
| 3374 | handleSuccess(callResult) |
| 3375 | } |
| 3376 | let handle = UNIFFI_FOREIGN_FUTURE_HANDLE_MAP.insert(obj: task) |
| 3377 | droppedCallback.pointee = UniffiForeignFutureDroppedCallbackStruct( |
| 3378 | handle: handle, |
| 3379 | free: uniffiForeignFutureDroppedCallback |
| 3380 | ) |
| 3381 | } |
| 3382 | |
| 3383 | // Borrow the callback handle map implementation to store foreign future handles |
| 3384 | // TODO: consolidate the handle-map code (https://github.com/mozilla/uniffi-rs/pull/1823) |
| 3385 | fileprivate let UNIFFI_FOREIGN_FUTURE_HANDLE_MAP = UniffiHandleMap<UniffiForeignFutureTask>() |
| 3386 | |
| 3387 | // Protocol for tasks that handle foreign futures. |
| 3388 | // |
| 3389 | // Defining a protocol allows all tasks to be stored in the same handle map. This can't be done |
| 3390 | // with the task object itself, since has generic parameters. |
| 3391 | fileprivate protocol UniffiForeignFutureTask { |
| 3392 | func cancel() |
| 3393 | } |
| 3394 | |
| 3395 | extension Task: UniffiForeignFutureTask {} |
| 3396 | |
| 3397 | private func uniffiForeignFutureDroppedCallback(handle: UInt64) { |
| 3398 | do { |
| 3399 | let task = try UNIFFI_FOREIGN_FUTURE_HANDLE_MAP.remove(handle: handle) |
| 3400 | // Set the cancellation flag on the task. If it's still running, the code can check the |
| 3401 | // cancellation flag or call `Task.checkCancellation()`. If the task has completed, this is |
| 3402 | // a no-op. |
| 3403 | task.cancel() |
| 3404 | } catch { |
| 3405 | print("uniffiForeignFutureDroppedCallback: handle missing from handlemap") |
| 3406 | } |
| 3407 | } |
| 3408 | |
| 3409 | // For testing |
| 3410 | public func uniffiForeignFutureHandleCountEdAgentFfi() -> Int { |
| 3411 | UNIFFI_FOREIGN_FUTURE_HANDLE_MAP.count |
| 3412 | } |
| 3413 | public func configureCacheDir(path: String) {try! rustCall() { |
| 3414 | uniffi_ed_agent_ffi_fn_func_configure_cache_dir( |
| 3415 | FfiConverterString.lower(path),$0 |
| 3416 | ) |
| 3417 | } |
| 3418 | } |
| 3419 | public func defaultAgentModelConfig() -> FfiGgufModelConfig { |
| 3420 | return try! FfiConverterTypeFfiGgufModelConfig_lift(try! rustCall() { |
| 3421 | uniffi_ed_agent_ffi_fn_func_default_agent_model_config($0 |
| 3422 | ) |
| 3423 | }) |
| 3424 | } |
| 3425 | |
| 3426 | private enum InitializationResult { |
| 3427 | case ok |
| 3428 | case contractVersionMismatch |
| 3429 | case apiChecksumMismatch |
| 3430 | } |
| 3431 | // Use a global variable to perform the versioning checks. Swift ensures that |
| 3432 | // the code inside is only computed once. |
| 3433 | private let initializationResult: InitializationResult = { |
| 3434 | // Get the bindings contract version from our ComponentInterface |
| 3435 | let bindings_contract_version = 30 |
| 3436 | // Get the scaffolding contract version by calling the into the dylib |
| 3437 | let scaffolding_contract_version = ffi_ed_agent_ffi_uniffi_contract_version() |
| 3438 | if bindings_contract_version != scaffolding_contract_version { |
| 3439 | return InitializationResult.contractVersionMismatch |
| 3440 | } |
| 3441 | if (uniffi_ed_agent_ffi_checksum_func_configure_cache_dir() != 30620) { |
| 3442 | return InitializationResult.apiChecksumMismatch |
| 3443 | } |
| 3444 | if (uniffi_ed_agent_ffi_checksum_func_default_agent_model_config() != 44321) { |
| 3445 | return InitializationResult.apiChecksumMismatch |
| 3446 | } |
| 3447 | if (uniffi_ed_agent_ffi_checksum_method_ffiedagent_cancel() != 42085) { |
| 3448 | return InitializationResult.apiChecksumMismatch |
| 3449 | } |
| 3450 | if (uniffi_ed_agent_ffi_checksum_method_ffiedagent_cancel_stream() != 63923) { |
| 3451 | return InitializationResult.apiChecksumMismatch |
| 3452 | } |
| 3453 | if (uniffi_ed_agent_ffi_checksum_method_ffiedagent_clear_history() != 19615) { |
| 3454 | return InitializationResult.apiChecksumMismatch |
| 3455 | } |
| 3456 | if (uniffi_ed_agent_ffi_checksum_method_ffiedagent_clear_system_prompt() != 50345) { |
| 3457 | return InitializationResult.apiChecksumMismatch |
| 3458 | } |
| 3459 | if (uniffi_ed_agent_ffi_checksum_method_ffiedagent_generate() != 6127) { |
| 3460 | return InitializationResult.apiChecksumMismatch |
| 3461 | } |
| 3462 | if (uniffi_ed_agent_ffi_checksum_method_ffiedagent_history() != 36014) { |
| 3463 | return InitializationResult.apiChecksumMismatch |
| 3464 | } |
| 3465 | if (uniffi_ed_agent_ffi_checksum_method_ffiedagent_info() != 9944) { |
| 3466 | return InitializationResult.apiChecksumMismatch |
| 3467 | } |
| 3468 | if (uniffi_ed_agent_ffi_checksum_method_ffiedagent_is_loaded() != 28871) { |
| 3469 | return InitializationResult.apiChecksumMismatch |
| 3470 | } |
| 3471 | if (uniffi_ed_agent_ffi_checksum_method_ffiedagent_load_assigned_model() != 60966) { |
| 3472 | return InitializationResult.apiChecksumMismatch |
| 3473 | } |
| 3474 | if (uniffi_ed_agent_ffi_checksum_method_ffiedagent_load_default_agent_model() != 47518) { |
| 3475 | return InitializationResult.apiChecksumMismatch |
| 3476 | } |
| 3477 | if (uniffi_ed_agent_ffi_checksum_method_ffiedagent_load_gguf_model() != 17854) { |
| 3478 | return InitializationResult.apiChecksumMismatch |
| 3479 | } |
| 3480 | if (uniffi_ed_agent_ffi_checksum_method_ffiedagent_load_uqff_model() != 11023) { |
| 3481 | return InitializationResult.apiChecksumMismatch |
| 3482 | } |
| 3483 | if (uniffi_ed_agent_ffi_checksum_method_ffiedagent_register_tool() != 34863) { |
| 3484 | return InitializationResult.apiChecksumMismatch |
| 3485 | } |
| 3486 | if (uniffi_ed_agent_ffi_checksum_method_ffiedagent_remove_all_tools() != 36535) { |
| 3487 | return InitializationResult.apiChecksumMismatch |
| 3488 | } |
| 3489 | if (uniffi_ed_agent_ffi_checksum_method_ffiedagent_restore_history() != 25771) { |
| 3490 | return InitializationResult.apiChecksumMismatch |
| 3491 | } |
| 3492 | if (uniffi_ed_agent_ffi_checksum_method_ffiedagent_run() != 39233) { |
| 3493 | return InitializationResult.apiChecksumMismatch |
| 3494 | } |
| 3495 | if (uniffi_ed_agent_ffi_checksum_method_ffiedagent_send() != 839) { |
| 3496 | return InitializationResult.apiChecksumMismatch |
| 3497 | } |
| 3498 | if (uniffi_ed_agent_ffi_checksum_method_ffiedagent_set_sampling() != 44594) { |
| 3499 | return InitializationResult.apiChecksumMismatch |
| 3500 | } |
| 3501 | if (uniffi_ed_agent_ffi_checksum_method_ffiedagent_set_system_prompt() != 31838) { |
| 3502 | return InitializationResult.apiChecksumMismatch |
| 3503 | } |
| 3504 | if (uniffi_ed_agent_ffi_checksum_method_ffiedagent_stream_message() != 6788) { |
| 3505 | return InitializationResult.apiChecksumMismatch |
| 3506 | } |
| 3507 | if (uniffi_ed_agent_ffi_checksum_method_ffiedagent_unload() != 29612) { |
| 3508 | return InitializationResult.apiChecksumMismatch |
| 3509 | } |
| 3510 | if (uniffi_ed_agent_ffi_checksum_method_ffiedagent_unregister_tool() != 63973) { |
| 3511 | return InitializationResult.apiChecksumMismatch |
| 3512 | } |
| 3513 | if (uniffi_ed_agent_ffi_checksum_constructor_ffiedagent_new() != 19584) { |
| 3514 | return InitializationResult.apiChecksumMismatch |
| 3515 | } |
| 3516 | if (uniffi_ed_agent_ffi_checksum_constructor_ffiedagent_new_with_app_id() != 58709) { |
| 3517 | return InitializationResult.apiChecksumMismatch |
| 3518 | } |
| 3519 | if (uniffi_ed_agent_ffi_checksum_method_ffiapprovalhandler_approve() != 9982) { |
| 3520 | return InitializationResult.apiChecksumMismatch |
| 3521 | } |
| 3522 | if (uniffi_ed_agent_ffi_checksum_method_ffieventlistener_status_changed() != 50680) { |
| 3523 | return InitializationResult.apiChecksumMismatch |
| 3524 | } |
| 3525 | if (uniffi_ed_agent_ffi_checksum_method_ffieventlistener_text_delta() != 35660) { |
| 3526 | return InitializationResult.apiChecksumMismatch |
| 3527 | } |
| 3528 | if (uniffi_ed_agent_ffi_checksum_method_ffieventlistener_tool_requested() != 9203) { |
| 3529 | return InitializationResult.apiChecksumMismatch |
| 3530 | } |
| 3531 | if (uniffi_ed_agent_ffi_checksum_method_ffieventlistener_approval_requested() != 14469) { |
| 3532 | return InitializationResult.apiChecksumMismatch |
| 3533 | } |
| 3534 | if (uniffi_ed_agent_ffi_checksum_method_ffieventlistener_tool_started() != 36088) { |
| 3535 | return InitializationResult.apiChecksumMismatch |
| 3536 | } |
| 3537 | if (uniffi_ed_agent_ffi_checksum_method_ffieventlistener_tool_finished() != 51284) { |
| 3538 | return InitializationResult.apiChecksumMismatch |
| 3539 | } |
| 3540 | if (uniffi_ed_agent_ffi_checksum_method_ffieventlistener_agent_replied() != 55514) { |
| 3541 | return InitializationResult.apiChecksumMismatch |
| 3542 | } |
| 3543 | if (uniffi_ed_agent_ffi_checksum_method_ffieventlistener_warning() != 17877) { |
| 3544 | return InitializationResult.apiChecksumMismatch |
| 3545 | } |
| 3546 | if (uniffi_ed_agent_ffi_checksum_method_ffistreamlistener_on_delta() != 13726) { |
| 3547 | return InitializationResult.apiChecksumMismatch |
| 3548 | } |
| 3549 | if (uniffi_ed_agent_ffi_checksum_method_ffitoolexecutor_execute() != 36465) { |
| 3550 | return InitializationResult.apiChecksumMismatch |
| 3551 | } |
| 3552 | |
| 3553 | uniffiCallbackInitFfiApprovalHandler() |
| 3554 | uniffiCallbackInitFfiEventListener() |
| 3555 | uniffiCallbackInitFfiStreamListener() |
| 3556 | uniffiCallbackInitFfiToolExecutor() |
| 3557 | return InitializationResult.ok |
| 3558 | }() |
| 3559 | |
| 3560 | // Make the ensure init function public so that other modules which have external type references to |
| 3561 | // our types can call it. |
| 3562 | public func uniffiEnsureEdAgentFfiInitialized() { |
| 3563 | switch initializationResult { |
| 3564 | case .ok: |
| 3565 | break |
| 3566 | case .contractVersionMismatch: |
| 3567 | fatalError("UniFFI contract version mismatch: try cleaning and rebuilding your project") |
| 3568 | case .apiChecksumMismatch: |
| 3569 | fatalError("UniFFI API checksum mismatch: try cleaning and rebuilding your project") |
| 3570 | } |
| 3571 | } |
| 3572 | |
| 3573 | // swiftlint:enable all |