Skip to content
Merged
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
1 change: 0 additions & 1 deletion Examples/ChatApp/Sources/Models/SupplementalMessage.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import Foundation

/// A non-agent system message injected into the chat list for lifecycle events.
///
/// Examples: agent connection confirmation, inline error notifications.
/// Rendered as distinct, non-interactive rows by `SupplementalMessageBubbleView`.
struct SupplementalMessage: Identifiable, Sendable {
let id: String
Expand Down
17 changes: 0 additions & 17 deletions Sources/AGUIAgentSDK/AgUiAgentConfig.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,6 @@ import Foundation
/// `AgUiAgentConfig` provides all options for a stateless AG-UI agent, including
/// authentication helpers, tool registry, per-request context, and timeout tuning.
///
/// ## Example
///
/// ```swift
/// let agent = AgUiAgent(url: agentURL) { config in
/// config.bearerToken = "sk-…"
/// config.systemPrompt = "You are a helpful assistant."
/// config.toolRegistry = myRegistry
/// }
/// ```
///
/// ## Auth Convenience
///
/// Setting `bearerToken` or `apiKey` automatically merges the corresponding header
/// into the final header dictionary via ``buildHeaders()``. Explicit entries in
/// ``headers`` take precedence over auto-generated auth headers.
///
/// - SeeAlso: ``AgUiAgent``, ``AgentBuilders``
public struct AgUiAgentConfig: Sendable {

// MARK: - Auth
Expand Down
21 changes: 0 additions & 21 deletions Sources/AGUIAgentSDK/AgentBuilders.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,27 +9,6 @@ import Foundation
/// `AgentBuilders` mirrors the `AgentBuilders` pattern from the Kotlin SDK,
/// providing clean one-liner factory calls for the most common agent configurations.
///
/// ## Examples
///
/// ```swift
/// // Bearer-token authenticated agent
/// let agent = AgentBuilders.agentWithBearer(url: agentURL, token: "sk-…")
///
/// // API-key authenticated agent
/// let agent = AgentBuilders.agentWithApiKey(url: agentURL, apiKey: "my-key")
///
/// // Agent with custom tool registry
/// let agent = AgentBuilders.agentWithTools(url: agentURL, registry: myRegistry)
///
/// // Stateful chat agent with a system prompt
/// let agent = AgentBuilders.chatAgent(url: agentURL, systemPrompt: "You are a helpful assistant.")
///
/// // Stateful agent with pre-seeded JSON state
/// let agent = AgentBuilders.statefulAgent(url: agentURL, initialState: Data("{\"mode\":\"creative\"}".utf8))
///
/// // Debug agent that logs verbose pipeline output
/// let agent = AgentBuilders.debugAgent(url: agentURL)
/// ```
public enum AgentBuilders {

// MARK: - Stateless agents
Expand Down
16 changes: 0 additions & 16 deletions Sources/AGUIAgentSDK/AgentMessage.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,6 @@ import Foundation
/// `AgentMessage` is a concrete value type that is `Identifiable` and `Equatable`,
/// making it safe to use directly in `List`, `ForEach`, and `@Observable` properties.
///
/// ## Usage in SwiftUI
///
/// ```swift
/// List(viewModel.messages) { message in
/// MessageBubble(message: message)
/// }
/// ```
///
/// ## Relationship to the protocol layer
///
/// `AgentMessage` is built by ``AgentViewModel`` / ``AgentViewModelCompat`` as events
/// arrive from the stream. It is not decoded from the wire — it is assembled in the
/// view model from `TextMessageStartEvent`, `TextMessageContentEvent`, and
/// `TextMessageEndEvent` events.
///
/// - SeeAlso: ``AgentViewModel``, ``AgentViewModelCompat``, ``AgentError``
public struct AgentMessage: Sendable, Identifiable, Equatable {

// MARK: - Role
Expand Down
48 changes: 0 additions & 48 deletions Sources/AGUIAgentSDK/AgentViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,54 +16,6 @@ import Observation
/// SwiftUI views that read `messages`, `isRunning`, or `lastError` are re-rendered only
/// when those specific properties change.
///
/// For iOS 16 / macOS 13 support use ``AgentViewModelCompat`` (`ObservableObject`).
///
/// ## Basic SwiftUI usage
///
/// ```swift
/// @State private var vm = AgentViewModel(
/// agent: StatefulAgUiAgent(baseURL: agentURL)
/// )
///
/// var body: some View {
/// VStack {
/// ScrollView {
/// ForEach(vm.messages) { message in
/// MessageBubble(message: message)
/// }
/// }
/// HStack {
/// TextField("Message", text: $draft)
/// Button("Send") {
/// Task { await vm.send(draft) }
/// }
/// .disabled(vm.isRunning)
/// }
/// if let error = vm.lastError {
/// Text(error.localizedDescription).foregroundColor(.red)
/// }
/// }
/// }
/// ```
///
/// ## Streaming text
///
/// As the agent streams tokens, each `TextMessageContentEvent` delta is appended
/// to the last assistant `AgentMessage` in place — the message `id` stays the
/// same so SwiftUI animates the existing row rather than replacing it.
///
/// ## Error handling
///
/// - `RunErrorEvent` from the agent sets `lastError` as ``AgentError/runError(message:code:)``
/// - Transport-level failures (network, timeout) set `lastError` as whatever `Error` was thrown
/// - `lastError` is cleared automatically at the start of each new `send()` call
///
/// ## Thread safety
///
/// `AgentViewModel` is isolated to `@MainActor`. Call `send()` and `clear()`
/// from SwiftUI button handlers or `Task { }` blocks — they are already on the main actor.
///
/// - SeeAlso: ``AgentViewModelCompat``, ``ChatAgent``, ``AgentMessage``, ``AgentError``
@available(iOS 17, macOS 14, tvOS 17, watchOS 10, *)
@Observable
@MainActor
Expand Down
46 changes: 0 additions & 46 deletions Sources/AGUIAgentSDK/AgentViewModelCompat.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,52 +11,6 @@ import Foundation
/// macOS 14+, prefer the zero-boilerplate ``AgentViewModel`` which uses the
/// `@Observable` macro instead.
///
/// ## Basic SwiftUI usage
///
/// ```swift
/// @StateObject private var vm = AgentViewModelCompat(
/// agent: StatefulAgUiAgent(baseURL: agentURL)
/// )
///
/// var body: some View {
/// VStack {
/// ScrollView {
/// ForEach(vm.messages) { message in
/// MessageBubble(message: message)
/// }
/// }
/// HStack {
/// TextField("Message", text: $draft)
/// Button("Send") {
/// Task { await vm.send(draft) }
/// }
/// .disabled(vm.isRunning)
/// }
/// if let error = vm.lastError {
/// Text(error.localizedDescription).foregroundColor(.red)
/// }
/// }
/// }
/// ```
///
/// ## Streaming text
///
/// As the agent streams tokens, each `TextMessageContentEvent` delta is appended
/// to the last assistant `AgentMessage` in place — the message `id` stays the
/// same so SwiftUI animates the existing row rather than replacing it.
///
/// ## Error handling
///
/// - `RunErrorEvent` from the agent sets `lastError` as ``AgentError/runError(message:code:)``
/// - Transport-level failures (network, timeout) set `lastError` as whatever `Error` was thrown
/// - `lastError` is cleared automatically at the start of each new `send()` call
///
/// ## Thread safety
///
/// `AgentViewModelCompat` is isolated to `@MainActor`. Call `send()` and `clear()`
/// from SwiftUI button handlers or `Task { }` blocks — they are already on the main actor.
///
/// - SeeAlso: ``AgentViewModel``, ``ChatAgent``, ``AgentMessage``, ``AgentError``
@MainActor
public final class AgentViewModelCompat: ObservableObject {

Expand Down
20 changes: 0 additions & 20 deletions Sources/AGUIAgentSDK/ChatAgent.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,26 +10,6 @@ import Foundation
/// agent implementation and makes both the view models and any custom agent
/// implementations fully testable through mocks.
///
/// ## Built-in conformances
///
/// ``StatefulAgUiAgent`` conforms to `ChatAgent` out of the box via a retroactive
/// extension in this file.
///
/// ## Custom agents
///
/// ```swift
/// struct MockChatAgent: ChatAgent {
/// func chat(message: String, threadId: String) async throws
/// -> AsyncThrowingStream<any AGUIEvent, Error>
/// {
/// // Return test events
/// }
///
/// func clearHistory(threadId: String?) async {}
/// }
/// ```
///
/// - SeeAlso: ``AgentViewModel``, ``AgentViewModelCompat``, ``StatefulAgUiAgent``
public protocol ChatAgent: Sendable {

/// Sends a user message and returns the resulting AG-UI event stream.
Expand Down
22 changes: 0 additions & 22 deletions Sources/AGUIAgentSDK/ConversationHistoryManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,28 +18,6 @@ import Foundation
/// When trimming, the manager preserves system messages while removing the
/// oldest user/assistant message pairs to fit within the specified limit.
///
/// ## Example
///
/// ```swift
/// let manager = ConversationHistoryManager()
///
/// // Add messages to a thread
/// await manager.append(
/// message: SystemMessage(id: "sys1", content: "You are helpful"),
/// to: "chat-1"
/// )
/// await manager.append(
/// message: UserMessage(id: "usr1", content: "Hello"),
/// to: "chat-1"
/// )
///
/// // Get history
/// let history = await manager.history(for: "chat-1")
/// print(history.count) // 2
///
/// // Trim to size
/// await manager.trim(threadId: "chat-1", maxLength: 10)
/// ```
actor ConversationHistoryManager {
/// Storage for per-thread conversation histories.
private var threadHistories: [String: [any Message]] = [:]
Expand Down
49 changes: 0 additions & 49 deletions Sources/AGUIAgentSDK/StatefulAgUiAgent.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,55 +11,6 @@ import Foundation
/// conversational AI interfaces. It automatically tracks message history per thread,
/// manages state updates, and provides convenient methods for common patterns.
///
/// ## Basic Usage
///
/// ```swift
/// let agent = StatefulAgUiAgent(baseURL: URL(string: "https://agent.example.com")!)
///
/// let stream = try await agent.chat(message: "Hello!")
/// for try await event in stream {
/// if let content = event as? TextMessageContentEvent {
/// print(content.delta, terminator: "")
/// }
/// }
/// ```
///
/// ## Advanced Configuration
///
/// ```swift
/// var config = StatefulAgUiAgentConfig(baseURL: agentURL)
/// config.systemPrompt = "You are a helpful AI assistant."
/// config.maxHistoryLength = 50
/// config.timeout = .seconds(60)
///
/// let agent = StatefulAgUiAgent(configuration: config)
///
/// // Multi-turn conversation
/// _ = try await agent.chat(message: "What's the weather?")
/// _ = try await agent.chat(message: "And tomorrow?") // Maintains context
/// ```
///
/// ## Thread Management
///
/// Each conversation can have its own thread with independent history:
///
/// ```swift
/// // Conversation 1
/// let stream1 = try await agent.chat(message: "Hello", threadId: "user-123")
///
/// // Conversation 2 (separate history)
/// let stream2 = try await agent.chat(message: "Hi", threadId: "user-456")
/// ```
///
/// ## Features
///
/// - **Automatic History**: User and assistant messages are tracked automatically
/// - **System Prompts**: Configurable system message for agent behavior
/// - **History Trimming**: Keeps conversations within token limits
/// - **State Management**: Tracks and updates agent state from events
/// - **Thread Safety**: Actor-based concurrency for safe multi-threaded use
///
/// - SeeAlso: ``StatefulAgUiAgentConfig``, ``ConversationHistoryManager``
public final class StatefulAgUiAgent: Sendable {
/// The underlying HTTP agent for communication.
private let httpAgent: HttpAgent
Expand Down
11 changes: 0 additions & 11 deletions Sources/AGUIAgentSDK/StatefulAgUiAgentConfig.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,6 @@ import Foundation
/// This struct provides all configuration options for creating a stateful agent,
/// including HTTP settings, conversation management, and agent behavior.
///
/// ## Example
///
/// ```swift
/// var config = StatefulAgUiAgentConfig(baseURL: agentURL)
/// config.systemPrompt = "You are a helpful AI assistant."
/// config.maxHistoryLength = 50
/// config.timeout = .seconds(60)
/// config.headers = ["Authorization": "Bearer token"]
///
/// let agent = StatefulAgUiAgent(configuration: config)
/// ```
public struct StatefulAgUiAgentConfig: Sendable {
/// The base URL of the AG-UI agent server.
public var baseURL: URL
Expand Down
19 changes: 0 additions & 19 deletions Sources/AGUIAgentSDK/Tools/ClientToolResponseHandler.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,25 +10,6 @@ import Foundation
/// Sends tool results back to the agent by initiating a new run containing
/// only the tool result message. This mirrors the Kotlin `ClientToolResponseHandler`.
///
/// ## How it works
///
/// When a tool call completes, the result must be delivered back to the agent
/// so it can continue the conversation. `ClientToolResponseHandler` does this
/// by constructing a minimal `RunAgentInput` containing the `ToolMessage` and
/// executing a new run through the same `HttpAgent`. The resulting events are
/// consumed and discarded — callers receive the results through the ongoing
/// conversation stream, not here.
///
/// ## Example
///
/// ```swift
/// let httpAgent = HttpAgent(baseURL: agentURL)
/// let handler = ClientToolResponseHandler(httpAgent: httpAgent)
/// let manager = ToolExecutionManager(
/// toolRegistry: registry,
/// responseHandler: handler
/// )
/// ```
public final class ClientToolResponseHandler: ToolResponseHandler, Sendable {

private let httpAgent: HttpAgent
Expand Down
10 changes: 0 additions & 10 deletions Sources/AGUIClient/AGUIClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,6 @@ import Foundation
/// - Event stream management
/// - State synchronization
///
/// ## Usage
///
/// ```swift
/// import AGUIClient
///
/// let agent = HttpAgent(baseURL: agentURL)
/// for try await event in try await agent.run(input) {
/// // Process events
/// }
/// ```
public struct AGUIClient {
/// The version of the AGUIClient module.
public static let version = "0.1.0"
Expand Down
20 changes: 0 additions & 20 deletions Sources/AGUIClient/State/DefaultApplyEvents.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,26 +12,6 @@ extension AsyncSequence where Element == any AGUIEvent {
/// triggering event. Callers should accumulate values from successive emissions
/// to build the complete agent state.
///
/// ## Example
///
/// ```swift
/// var currentMessages: [any Message] = []
/// var currentState: State = Data("{}".utf8)
///
/// for try await agentState in eventStream.applyEvents(input: input) {
/// if let messages = agentState.messages {
/// currentMessages = messages
/// }
/// if let state = agentState.state {
/// currentState = state
/// }
/// }
/// ```
///
/// - Parameters:
/// - input: The `RunAgentInput` that seeded this run, providing initial messages and state.
/// - subscribers: Optional list of subscribers to notify of events (reserved for future use).
/// - Returns: An `AsyncThrowingStream` of `AgentState` emissions.
public func applyEvents(
input: RunAgentInput,
subscribers: [any AgentSubscriber] = []
Expand Down
Loading
Loading