Skip to content

Releases: jamesrochabrun/SwiftAnthropic

SwiftAnthropic 2.2.2

Choose a tag to compare

@jamesrochabrun jamesrochabrun released this 18 Apr 01:23
b7d030c

What's Changed

  • Add support for returning an image as a toolResult by @hypermoose in #55
  • Fix Linux build: declare swift-nio as an explicit dependency for NIOFoundationCompat by @gestrich in #56
  • Add MIT LICENSE file by @jamesrochabrun in #58

New Contributors

Full Changelog: 2.2.1...2.2.2

SwiftAnthropic 2.2.1

Choose a tag to compare

@jamesrochabrun jamesrochabrun released this 16 Feb 07:04
655f8c0

What's Changed

New Contributors

Full Changelog: v2.2.0...2.2.1

SwiftAnthropic v2.2.0

Choose a tag to compare

@jamesrochabrun jamesrochabrun released this 26 Oct 05:35
4f9e21b

Overview

This PR adds full support for Anthropic's Skills API, enabling users to create, manage, and use skills in their SwiftAnthropic applications.

What's New

🎯 Core Features

Container Support

  • Add Container parameter to MessageParameter for specifying skills to load
  • Add Container response field to MessageResponse for reusing containers across conversations
  • Add SkillReference type for referencing both Anthropic-managed and custom skills
  • Support for version pinning (specific versions or "latest")

Skills Management

  • ✅ Create skills with file uploads (multipart/form-data)
  • ✅ List all available skills with filtering (source: custom/anthropic)
  • ✅ Retrieve individual skill details
  • ✅ Delete skills
  • ✅ Full version management (create, list, retrieve, delete)
  • ✅ Pagination support for large skill lists

📦 New API Types

Parameters:

  • SkillCreateParameter - Create new skills with files
  • SkillVersionCreateParameter - Create new skill versions
  • SkillFile - File data with metadata for uploads
  • ListSkillsParameter - Filter and paginate skill lists
  • ListSkillVersionsParameter - Paginate version lists

Responses:

  • SkillResponse - Individual skill metadata
  • ListSkillsResponse - Paginated skill results
  • SkillVersionResponse - Version-specific details
  • ListSkillVersionsResponse - Paginated version results

🔧 Implementation

Service Methods (8 new):

func createSkill(_:) async throws -> SkillResponse
func listSkills(parameter:) async throws -> ListSkillsResponse
func retrieveSkill(skillId:) async throws -> SkillResponse
func deleteSkill(skillId:) async throws

func createSkillVersion(skillId:_:) async throws -> SkillVersionResponse
func listSkillVersions(skillId:parameter:) async throws -> ListSkillVersionsResponse
func retrieveSkillVersion(skillId:version:) async throws -> SkillVersionResponse
func deleteSkillVersion(skillId:version:) async throws

Infrastructure:

  • Multipart/form-data encoding for file uploads
  • New API endpoints: /v1/skills, /v1/skills/{id}, /v1/skills/{id}/versions
  • Full AIProxy compatibility with device check support
  • Platform support: iOS 15+, macOS 12+, Linux

📱 Example Application Updates

New Skills Demo:

  • Interactive SkillsDemoView with UI for testing
  • SkillsDemoObservable with example implementations
  • Demonstrates listing available skills
  • Shows using skills in messages (XLSX spreadsheet example)
  • Demonstrates container reuse across multi-turn conversations
  • Includes streaming support with skills

Updated Files:

  • ApiKeyIntroView - Added Skills beta headers
  • OptionsListView - Added "Skills API" option

Usage Example

// List available skills
let skills = try await service.listSkills(parameter: nil)
print("Found \(skills.data.count) skills")

// Create a message using a skill
let parameter = MessageParameter(
    model: .claude37Sonnet,
    messages: [.init(role: .user, content: .text("Create a budget spreadsheet"))],
    maxTokens: 4096,
    tools: [.hosted(type: "code_execution_20250825", name: "code_execution")],
    container: .init(
        skills: [
            .init(type: .anthropic, skillId: "xlsx", version: "latest")
        ]
    )
)

let response = try await service.createMessage(parameter)

// Reuse container in follow-up
let followUp = MessageParameter(
    model: .claude37Sonnet,
    messages: updatedMessages,
    maxTokens: 4096,
    container: .init(
        id: response.container?.id,  // Reuse for performance
        skills: [.init(type: .anthropic, skillId: "xlsx")]
    )
)

Testing

Automated

  • ✅ Project builds successfully with no errors
  • ✅ All existing tests pass
  • ✅ Type-safe implementation with Swift enums

Manual Testing

Run the example app and:

  1. Select "Default Anthropic Service"
  2. Enter API key with Skills access
  3. Choose "Skills API" from the menu
  4. Test all three demo buttons

Technical Notes

  • Follows existing codebase patterns and conventions
  • Consistent documentation style with triple-slash comments
  • Proper error handling for all operations
  • Snake case conversion handled automatically
  • Full backward compatibility maintained

Files Changed

  • 10 modified files - Core API support
  • 4 new files - Skills parameters, responses, and demos
  • +1,242 lines added

Checklist

  • Code builds without errors
  • Follows existing code style
  • Documentation added
  • Example app updated
  • AIProxy compatibility maintained
  • Linux compatibility maintained

SwiftAnthropic v2.1.9

Choose a tag to compare

@jamesrochabrun jamesrochabrun released this 05 Aug 03:07
6a87348

What's Changed

  • Add AIProxy public key for dot com TLD by @lzell in #51

Full Changelog: v2.1.8...v2.1.9

SwiftAnthropic v2.1.8

Choose a tag to compare

@jamesrochabrun jamesrochabrun released this 16 Jul 05:21
0e718d8

Server Side Linux support

SwiftAnthropic v2.1.7

Choose a tag to compare

@jamesrochabrun jamesrochabrun released this 22 May 07:35
c069979

What's Changed

Full Changelog: v2.1.6...v2.1.7

SwiftAnthropic v2.1.6

Choose a tag to compare

@jamesrochabrun jamesrochabrun released this 20 May 18:12

Full Changelog: v2.1.5...v2.1.6

SwiftAnthropic v2.1.5

Choose a tag to compare

@jamesrochabrun jamesrochabrun released this 20 May 08:15

Changes for Claude Code SDK
Full Changelog: v2.1.4...v2.1.5

SwiftAnthropic v2.1.4

Choose a tag to compare

@jamesrochabrun jamesrochabrun released this 13 May 06:10
94e3bea

Web Search Tool

Screenshot 2025-05-12 at 11 10 04 PM

/// Copied from Anthropic website)

The web search tool gives Claude direct access to real-time web content, allowing it to answer questions with up-to-date information beyond its knowledge cutoff. Claude automatically cites sources from search results as part of its answer.

Supported models

Web search is available on:

  • Claude 3.7 Sonnet (claude-3-7-sonnet-20250219)
  • Claude 3.5 Sonnet (new) (claude-3-5-sonnet-latest)
  • Claude 3.5 Haiku (claude-3-5-haiku-latest)

How web search works:

When you add the web search tool to your API request:

Claude decides when to search based on the prompt.
The API executes the searches and provides Claude with the results. This process may repeat multiple times throughout a single request.
At the end of its turn, Claude provides a final response with cited sources.

Usage in SwiftAnthropic

SwiftAnthropic provides convenience initializers for web search tools, you can use it like this:

let webSearchTool = MessageParameter.webSearch(
   maxUses: 5,
   allowedDomains: ["wikipedia.org"],
   userLocation: .sanFrancisco
)
               
let parameters = MessageParameter(
model: .claude35Sonnet,
messages: messages,
maxTokens: 1024, 
tools: [webSearchTool])

SwiftAnthropic v2.1.3

Choose a tag to compare

@jamesrochabrun jamesrochabrun released this 17 Mar 04:36
c921b62

Documentation

Screenshot 2025-03-16 at 9 04 03 PM

MAJOR CHANGE ⚠️

This version makes a major change in how Tool are created, please update accordingly.

Previous

Previously, the Tool was implemented as a struct that you initialized directly:

let weatherTool = MessageParameter.Tool(
    name: "get_weather", 
    description: "Get the current weather in a given location",
    inputSchema: .init(
        type: .object,
        properties: [
            "location": .init(type: .string, description: "The city and state, e.g. San Francisco, CA"),
            "unit": .init(type: .string, description: "The unit of temperature, either celsius or fahrenheit")
        ],
        required: ["location"]
    )
)

Now

As of this update, Tool is now implemented as an enum with two cases:

  • function: For standard function-based tools that have a schema
let weatherTool = MessageParameter.Tool.function(
    name: "get_weather", 
    description: "Get the current weather in a given location",
    inputSchema: .init(
        type: .object,
        properties: [
            "location": .init(type: .string, description: "The city and state, e.g. San Francisco, CA"),
            "unit": .init(type: .string, description: "The unit of temperature, either celsius or fahrenheit")
        ],
        required: ["location"]
    ),
    cacheControl: nil
)
  • hosted: For Anthropic-hosted tools like the text editor
let textEditorTool = MessageParameter.Tool.hosted(
    type: "text_editor_20250124", 
    name: "str_replace_editor"
)

This change provides better type safety and a clearer distinction between different types of tools. All existing code using the previous struct-based approach will need to be updated to use the new enum-based approach.

Text Editor Tool

Claude can use an Anthropic-defined text editor tool to view and modify text files, helping you debug, fix, and improve your code or other text documents. This allows Claude to directly interact with your files, providing hands-on assistance rather than just suggesting changes.

Compatible Models

The text editor tool is only available for specific Claude models:

  • Claude 3.7 Sonnet: Use text_editor_20250124
  • Claude 3.5 Sonnet: Use text_editor_20241022

Both versions provide identical capabilities - the version you use should match the model you're working with.

Use Cases

Some examples of when to use the text editor tool are:

  • Code debugging: Have Claude identify and fix bugs in your code, from syntax errors to logic issues
  • Code refactoring: Let Claude improve your code structure, readability, and performance
  • Documentation generation: Ask Claude to add docstrings, comments, or README files
  • Test creation: Have Claude create unit tests for your code

Using the Text Editor Tool

Here's how to provide the text editor tool to Claude:

// Create a message asking Claude to help with code
let messageParameter = MessageParameter.Message(role: .user, content: .text("There's a syntax error in my primes.py file. Can you help fix it?"))

// Define the text editor tool using the hosted tool type
let textEditorTool = MessageParameter.Tool.hosted(
    type: "text_editor_20250124", // Use the appropriate version for your model
    name: "str_replace_editor"
)

// Create parameters including the tool
let parameters = MessageParameter(
    model: .claude37Sonnet, 
    messages: [messageParameter], 
    maxTokens: 1024,
    tools: [textEditorTool]
)

// Create message or stream
let message = try await service.createMessage(parameters)

// Process Claude's response
for content in message.content {
    if case .toolUse(let id, let name, let input) = content {
        // Handle Claude's tool use request
        if let command = input["command"]?.stringValue {
            switch command {
            case "view":
                // Handle view file request
                // Read file and return contents to Claude
            case "str_replace":
                // Handle text replacement request
                // Replace text in file
            case "create":
                // Handle file creation request
                // Create new file
            case "insert":
                // Handle text insertion request
                // Insert text at specific location
            case "undo_edit":
                // Handle undo request
                // Revert last edit
            default:
                break
            }
        }
    }
}

Available Commands

The text editor tool supports several commands for viewing and modifying files:

  1. view: Examine the contents of a file

    • Parameters: path (file path), view_range (optional line range)
  2. str_replace: Replace specific text in a file

    • Parameters: path (file path), old_str (text to replace), new_str (replacement text)
  3. create: Create a new file with specified content

    • Parameters: path (file path), file_text (content for the new file)
  4. insert: Insert text at a specific location in a file

    • Parameters: path (file path), insert_line (line number), new_str (text to insert)
  5. undo_edit: Revert the last edit made to a file

    • Parameters: path (file path)

For more information, see [Anthropic's Text Editor Tool documentation](https://docs.anthropic.com/en/docs/build-with-claude/tool-use/text-editor-tool).