diff --git a/.swiftpm/xcode/xcshareddata/xcschemes/aiXplainKitTests.xcscheme b/.swiftpm/xcode/xcshareddata/xcschemes/aiXplainKitTests.xcscheme new file mode 100644 index 0000000..f7ac229 --- /dev/null +++ b/.swiftpm/xcode/xcshareddata/xcschemes/aiXplainKitTests.xcscheme @@ -0,0 +1,60 @@ + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Sources/aiXplainKit/Manager/FileManager/FileManager.swift b/Sources/aiXplainKit/Manager/FileManager/FileManager.swift index da6c78e..435b96f 100644 --- a/Sources/aiXplainKit/Manager/FileManager/FileManager.swift +++ b/Sources/aiXplainKit/Manager/FileManager/FileManager.swift @@ -225,7 +225,7 @@ public final class FileUploadManager { /// - Parameter localURL: The local URL of the data to be uploaded if necessary. /// - Returns: The remote URL of the uploaded data. /// - Throws: Any error that may occur during the file upload process. - public func uploadDataIfNeedIt(from url: URL) async throws -> URL { + public func uploadDataIfNeedIt(from url: URL, temporary: Bool = true) async throws -> URL { var url = url switch url.absoluteString { case let link where link.starts(with: "s3://"): @@ -236,9 +236,8 @@ public final class FileUploadManager { break default: let fileManager = FileUploadManager() - url = try await fileManager.uploadFile(at: url) + url = try await fileManager.uploadFile(at: url, temporary: temporary) } return url } - } diff --git a/Sources/aiXplainKit/Modules/Agents/Agents+session.swift b/Sources/aiXplainKit/Modules/Agents/Agents+session.swift new file mode 100644 index 0000000..2e1c5a7 --- /dev/null +++ b/Sources/aiXplainKit/Modules/Agents/Agents+session.swift @@ -0,0 +1,56 @@ +// +// File.swift +// aiXplainKit +// +// Created by Joao Maia on 27/08/25. +// + +import Foundation + +extension Agent{ + //TODO: do this + public func createSession() async throws -> String { + var session = self.id + "_" + UUID().uuidString + let headers = try self.networking.buildHeader() + + let payload: [String: Any] = [ + "id": self.id, + "query": "/", + "sessionId": session, + "history": [], + "executionParams": [ + "maxTokens": 2048, + "maxIterations": 10, + "outputFormat": "TEXT", + "expectedOutput": NSNull() + ], + "allowHistoryAndSessionId": true + ] + + + guard let backendURL = APIKeyManager.shared.BACKEND_URL else { + throw AgentsError.missingBackendURL + } + + + guard let url = URL(string: backendURL.absoluteString + Networking.Endpoint.agentRun(agentIdentifier: self.id).path ) else { + throw AgentsError.invalidURL(url: backendURL.absoluteString) + } + + + let data = try JSONSerialization.data(withJSONObject: payload, options: []) + let response = try await networking.post(url: url, headers: headers, body: data) + + if let httpResponse = response.1 as? HTTPURLResponse, + httpResponse.statusCode != 201 { + throw NetworkingError.invalidStatusCode(statusCode: httpResponse.statusCode) + } + + return session + } + + +} + + + diff --git a/Sources/aiXplainKit/Modules/Model/Model.swift b/Sources/aiXplainKit/Modules/Model/Model.swift index 479af65..1300155 100644 --- a/Sources/aiXplainKit/Modules/Model/Model.swift +++ b/Sources/aiXplainKit/Modules/Model/Model.swift @@ -79,6 +79,8 @@ public class Model:Codable, CustomStringConvertible { /// The organization or individual who developed the model. public let developedBy: String + + public var supportsStreaming:Bool = false /// Parameters that can be passed to the model during execution public let parameters: [ModelParameter] @@ -135,6 +137,8 @@ public class Model:Codable, CustomStringConvertible { function = try? container.decodeIfPresent(Function.self, forKey: .function) + supportsStreaming = (try? container.decodeIfPresent(Bool.self, forKey: .supportsStreaming)) ?? false + privacy = nil license = nil logger = Logger(subsystem: "AiXplain", category: "Model(\(name)") @@ -190,7 +194,7 @@ public class Model:Codable, CustomStringConvertible { // Private enum for coding keys to improve readability and maintainability. private enum CodingKeys: String, CodingKey { - case id, name, description, supplier, version, license, privacy, pricing, hostedBy, developedBy, params, function + case id, name, description, supplier, version, license, privacy, pricing, hostedBy, developedBy, params, function, supportsStreaming } } diff --git a/Sources/aiXplainKit/Networking/ResponseDecoders/AgentExecuteResponse.swift b/Sources/aiXplainKit/Networking/ResponseDecoders/AgentExecuteResponse.swift index 6adcbc7..cd19300 100644 --- a/Sources/aiXplainKit/Networking/ResponseDecoders/AgentExecuteResponse.swift +++ b/Sources/aiXplainKit/Networking/ResponseDecoders/AgentExecuteResponse.swift @@ -8,7 +8,7 @@ import Foundation struct AgentExecuteResponse:Decodable{ let requestId:String - let sessionId:String + let sessionId:String? let data:String var maybeUrl:URL?{ diff --git a/Sources/aiXplainKit/Networking/ResponseDecoders/AgentOutput.swift b/Sources/aiXplainKit/Networking/ResponseDecoders/AgentOutput.swift index 4e7f5b7..a6f19ce 100644 --- a/Sources/aiXplainKit/Networking/ResponseDecoders/AgentOutput.swift +++ b/Sources/aiXplainKit/Networking/ResponseDecoders/AgentOutput.swift @@ -53,7 +53,8 @@ extension AgentOutput { // MARK: - DataClass public struct DataClass: Codable { - public let input, output, sessionID: String + public let input, output: String + public let sessionID: String? public let intermediateSteps: [IntermediateStep] enum CodingKeys: String, CodingKey { @@ -84,7 +85,7 @@ extension DataClass { func with( input: String? = nil, output: String? = nil, - sessionID: String? = nil, + sessionID: String?? = nil, intermediateSteps: [IntermediateStep]? = nil ) -> DataClass { return DataClass( diff --git a/Sources/aiXplainKit/Provider/Agent/.swift b/Sources/aiXplainKit/Provider/Agent/.swift new file mode 100644 index 0000000..6c1c3ca --- /dev/null +++ b/Sources/aiXplainKit/Provider/Agent/.swift @@ -0,0 +1,21 @@ +// +// File.swift +// aiXplainKit +// +// Created by Joao Maia on 27/08/25. +// + +import Foundation + +final public class AgentSessionProvider { + static public func create() -> AgentSession { + return AgentSession() + } +} + + + +struct AgentSelection { + let timestamp: Date = .now() + let sessionID: String = UUID().uuidString +}