Releases: jamesrochabrun/SwiftAnthropic
Release list
SwiftAnthropic 2.2.2
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
- @hypermoose made their first contribution in #55
- @gestrich made their first contribution in #56
Full Changelog: 2.2.1...2.2.2
SwiftAnthropic 2.2.1
What's Changed
- Add User-Agent header to all outgoing requests by @mikelambert in #54
New Contributors
- @mikelambert made their first contribution in #54
Full Changelog: v2.2.0...2.2.1
SwiftAnthropic v2.2.0
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
Containerparameter toMessageParameterfor specifying skills to load - Add
Containerresponse field toMessageResponsefor reusing containers across conversations - Add
SkillReferencetype 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 filesSkillVersionCreateParameter- Create new skill versionsSkillFile- File data with metadata for uploadsListSkillsParameter- Filter and paginate skill listsListSkillVersionsParameter- Paginate version lists
Responses:
SkillResponse- Individual skill metadataListSkillsResponse- Paginated skill resultsSkillVersionResponse- Version-specific detailsListSkillVersionsResponse- 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 throwsInfrastructure:
- 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
SkillsDemoViewwith UI for testing SkillsDemoObservablewith 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 headersOptionsListView- 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:
- Select "Default Anthropic Service"
- Enter API key with Skills access
- Choose "Skills API" from the menu
- 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
What's Changed
Full Changelog: v2.1.8...v2.1.9
SwiftAnthropic v2.1.8
Server Side Linux support
SwiftAnthropic v2.1.7
What's Changed
- Updating models to work with Claude Code by @jamesrochabrun in #48
Full Changelog: v2.1.6...v2.1.7
SwiftAnthropic v2.1.6
Full Changelog: v2.1.5...v2.1.6
SwiftAnthropic v2.1.5
Changes for Claude Code SDK
Full Changelog: v2.1.4...v2.1.5
SwiftAnthropic v2.1.4
Web Search Tool
/// 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
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:
-
view: Examine the contents of a file
- Parameters:
path(file path),view_range(optional line range)
- Parameters:
-
str_replace: Replace specific text in a file
- Parameters:
path(file path),old_str(text to replace),new_str(replacement text)
- Parameters:
-
create: Create a new file with specified content
- Parameters:
path(file path),file_text(content for the new file)
- Parameters:
-
insert: Insert text at a specific location in a file
- Parameters:
path(file path),insert_line(line number),new_str(text to insert)
- Parameters:
-
undo_edit: Revert the last edit made to a file
- Parameters:
path(file path)
- Parameters:
For more information, see [Anthropic's Text Editor Tool documentation](https://docs.anthropic.com/en/docs/build-with-claude/tool-use/text-editor-tool).
