iOS Intelligence Service
Functions
isModelFilesDownloaded
public func isModelFilesDownloaded(name: String) -> Bool
Checks whether model files for the given model name already exist on the device.
Parameters:
name: String— Model name (Orchestrator → Managed AI Models → Programmatic name).
unloadModel
public func unloadModel(
key: String,
onSuccess: (() -> Void)? = nil
)
Unloads the model for the given session key and releases memory.
Parameters:
key: String— Session key from loadModel.onSuccess: (() -> Void)?— Called after unload completes.
stopModelInference
public func stopModelInference(key: String)
Requests cancellation of generation for the given session key.
Parameters:
key: String— Session key.
isModelLoaded
public func isModelLoaded(key: String) -> Bool
Returns whether a model is loaded for the given session key.
Parameters:
key: String— Session key.
loadModel
public func loadModel(
name: String,
key: String,
modelParams: ModelParams? = nil,
onSuccess: @escaping @Sendable () -> Void,
onError: (@Sendable (Error) -> Void)? = nil
)
Loads the specified model into memory with optional parameters.
Parameters:
name: String— Model name (Orchestrator → Managed AI Models → Programmatic name).key: String— Session key for this load (used with invoke and unload).modelParams: ModelParams?— Optional runtime configuration.onSuccess: () -> VoidonError: ((Error) -> Void)?— Error callback.
downloadModelFiles
public func downloadModelFiles(
name: String,
onProgress: @escaping @Sendable (Double) -> Void,
onSuccess: @escaping @Sendable () -> Void,
onError: (@Sendable (Error) -> Void)? = nil
)
Downloads the model files for the given model name.
Parameters:
name: String— Model name (Orchestrator → Managed AI Models → Programmatic name).onProgress: (Double) -> Void— Progress callback (0.0–1.0).onSuccess: () -> VoidonError: ((Error) -> Void)? = nil— Error callback.
deleteModelFiles
public func deleteModelFiles(
name: String,
onSuccess: @escaping @Sendable () -> Void,
onError: (@Sendable (Error) -> Void)? = nil
)
Deletes all downloaded files for the given model.
Parameters:
name: String— Model name (Orchestrator → Managed AI Models → Programmatic name).onSuccess: () -> Void— Confirmation identifier.onError: ((Error) -> Void)? = nil— Error callback.
getDownloadedModelsList
public func getDownloadedModelsList() -> [String]
Returns a list of model names that are currently downloaded on the device.
Parameters: None.
invokeModel
public func invokeModel(
key: String,
prompts: [Prompt],
inferenceParams: InferenceParams = .init(),
onStream: @escaping @Sendable (String) -> Void,
onSuccess: @escaping @Sendable (String) -> Void,
onError: (@Sendable (Error) -> Void)? = nil
)
Runs the model using the provided prompts and inference parameters.
Parameters:
key: String— Session key from loadModel.prompts: [Prompt]— Input messages.inferenceParams: InferenceParams— Generation settings.onStream: (String) -> Void— Partial streamed output (required).onSuccess: (String) -> Void— Final model output.onError: ((Error) -> Void)?— Error callback.
syncManagedAIModels
public func syncManagedAIModels(
onSuccess: @escaping () -> Void,
onError: ((Error) -> Void)? = nil
)
Synchronizes the list of managed AI models with the Orchestrator.
Parameters:
onSuccess: () -> Void— Called when sync completes.onError: ((Error) -> Void)? = nil— Error callback.
getManagedAIModels
public func getManagedAIModels(
onSuccess: @escaping ([ManagedAIModel]) -> Void,
onError: ((Error) -> Void)? = nil
) -> [ManagedAIModel]
Retrieves all managed AI models stored locally.
Parameters:
onSuccess: ([ManagedAIModel]) -> Void— Model list.onError: ((Error) -> Void)? = nil— Error callback.
getManagedAIModel
public func getManagedAIModel(
name: String,
onSuccess: @escaping (ManagedAIModel?) -> Void,
onError: ((Error) -> Void)? = nil
) -> ManagedAIModel?
Retrieves a specific managed AI model by name.
Parameters:
name: String— Model name (Orchestrator → Managed AI Models → Programmatic name).onSuccess: (ManagedAIModel?) -> Void— Model or nil.onError: ((Error) -> Void)? = nil— Error callback.
syncRules
public func syncRules(
onSuccess: @escaping () -> Void,
onError: ((Error) -> Void)? = nil
)
Synchronizes rule definitions with the Orchestrator.
Parameters:
onSuccess: () -> Void— Completed callback.onError: ((Error) -> Void)? = nil— Error callback.
getRules
public func getRules(
onSuccess: @escaping ([Rule]) -> Void,
onError: ((Error) -> Void)? = nil
) -> [Rule]
Returns all stored rules.
Parameters:
onSuccess: ([Rule]) -> Void— Rule list.onError: ((Error) -> Void)? = nil— Error callback.
getRule
public func getRule(
name: String,
onSuccess: @escaping (Rule?) -> Void,
onError: ((Error) -> Void)? = nil
) -> Rule?
Retrieves a rule by its name.
Parameters:
name: String— Rule name.onSuccess: (Rule?) -> Void— Rule or nil.onError: ((Error) -> Void)? = nil— Error callback.
runRule
public func runRule(
name: String,
onSuccess: @escaping (Rule?) -> Void,
onError: ((Error) -> Void)? = nil
) -> Rule?
Evaluates a rule and returns its updated state.
Parameters:
name: String— Rule name.onSuccess: (Rule?) -> Void— Resulting rule state.onError: ((Error) -> Void)? = nil— Error callback.
runRules
public func runRules(
onlyOnInit: Bool,
onSuccess: @escaping ([Rule]) -> Void,
onError: ((Error) -> Void)? = nil
)
Evaluates multiple rules at once.
Parameters:
onlyOnInit: Bool— If true, only initialization rules run.onSuccess: ([Rule]) -> Void— Updated rules.onError: ((Error) -> Void)? = nil— Error callback.
Classes
LlamaGrammarConfig
public struct LlamaGrammarConfig: Equatable, Sendable {
public let grammar: String
public let grammarRoot: String
}
InferenceParams
public struct InferenceParams {
public var temperature: Float = 0.8
public var maxTokens: Int = 10_000
public var topP: Float = 0.95
public var topK: Int32? = nil
public var grammarConfig: LlamaGrammarConfig? = nil
}
ModelParams
public struct ModelParams {
/// Context window size (default: 512).
public var nCtx: Int = 512
/// Batch size for inference (default: 64).
public var nBatchSize: Int = 64
/// Number of CPU threads (default: available processors, minimum 2).
public var nThreads: Int = max(ProcessInfo.processInfo.processorCount, 2)
/// Number of GPU layers to load (default: 20).
public var nGpuLayers: Int = 20
}
ManagedAIModel
public struct ManagedAIModel: Codable {
public var id: String
public var name: String?
public var text: String?
public var modelDescription: String?
public var downloadUrl: String?
public var imageUrl: String?
public var thinking: Bool?
}
Rule
public class Rule: Codable {
public let id: String
public let name: String
public let text: String?
public let trigger: String?
public let condition: Filter
public let action: Action
}
Filter
public class Filter: RuleCondition {
public let type: String?
public let filters: [Filter]?
public let filter: Filter?
public let criteria: Criteria?
}
Criteria
public class Criteria: RuleCondition {
public let field: String
public let criteriaOperator: String
public let value: String
}
Action
public class Action: RuleAction {
public let type: String
public let config: Config?
}
Config
public class Config: Codable {
// ScriptConfig
public let script: Script?
// SignalCallConfig
public let signal: String?
public let payload: String?
// NotificationConfig
public let title: String?
public let message: String?
// HostAppCallConfig
public let event: String?
}
Prompt
public struct Prompt: Sendable {
public enum Role: String, Sendable {
case system
case user
case assistant
}
public let role: Role
public let content: String
}