Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 60 additions & 0 deletions .swiftpm/xcode/xcshareddata/xcschemes/aiXplainKitTests.xcscheme
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1540"
version = "1.7">
<BuildAction
parallelizeBuildables = "YES"
buildImplicitDependencies = "YES">
</BuildAction>
<TestAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
shouldUseLaunchSchemeArgsEnv = "YES"
shouldAutocreateTestPlan = "YES">
<Testables>
<TestableReference
skipped = "NO">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "aiXplainKitTests"
BuildableName = "aiXplainKitTests"
BlueprintName = "aiXplainKitTests"
ReferencedContainer = "container:">
</BuildableReference>
</TestableReference>
</Testables>
</TestAction>
<LaunchAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
launchStyle = "0"
useCustomWorkingDirectory = "NO"
ignoresPersistentStateOnLaunch = "NO"
debugDocumentVersioning = "YES"
debugServiceExtension = "internal"
allowLocationSimulation = "YES">
<EnvironmentVariables>
<EnvironmentVariable
key = "TEAM_API_KEY"
value = "d5e3e1a80cacd7191b5bf3020d8d4adeba4a5e74553e030ec7639950def67cb4"
isEnabled = "YES">
</EnvironmentVariable>
</EnvironmentVariables>
</LaunchAction>
<ProfileAction
buildConfiguration = "Release"
shouldUseLaunchSchemeArgsEnv = "YES"
savedToolIdentifier = ""
useCustomWorkingDirectory = "NO"
debugDocumentVersioning = "YES">
</ProfileAction>
<AnalyzeAction
buildConfiguration = "Debug">
</AnalyzeAction>
<ArchiveAction
buildConfiguration = "Release"
revealArchiveInOrganizer = "YES">
</ArchiveAction>
</Scheme>
5 changes: 2 additions & 3 deletions Sources/aiXplainKit/Manager/FileManager/FileManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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://"):
Expand All @@ -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
}

}
56 changes: 56 additions & 0 deletions Sources/aiXplainKit/Modules/Agents/Agents+session.swift
Original file line number Diff line number Diff line change
@@ -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
}


}



6 changes: 5 additions & 1 deletion Sources/aiXplainKit/Modules/Model/Model.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down Expand Up @@ -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)")
Expand Down Expand Up @@ -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
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import Foundation
struct AgentExecuteResponse:Decodable{
let requestId:String
let sessionId:String
let sessionId:String?
let data:String

var maybeUrl:URL?{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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(
Expand Down
21 changes: 21 additions & 0 deletions Sources/aiXplainKit/Provider/Agent/.swift
Original file line number Diff line number Diff line change
@@ -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
}