V0.11.x (#199)
* Support 2025-06-18 Spec (#167) * Support OpenAI _meta for Tool * Update init * Add title and outputSchema * Concurreny issue * General fields * Add Generate Fields to Server elements * 4 tab spacing * Update Version * Elicitation * Format * More tests and inits * Elicitation in README * Fix orphaned test * Add title to more structs * Public init * Fix meta validation and make tests more generic * Format and make Result properties public again * Revert more visibility changes * feat: 2025-11-25 phase 1, includes Version, Icon, Progress (#181) * chore: fixed unit tests * feat: added icon and progess base structs * feat: added progress notification and meta to callTool * feat: added tests * feat: simplified RequestMeta encoding/decoding * tests: added unit test to track progress * chore: rebased v0.11.x * feat: implemented cancellation * feat: added overloaded callTool method * fix: encoding Response _meta fix * chore: added old version to the versions list * feat: 2025-11-25 phase 2; added Logging and Completions (#196) * feat: added Logging and Completions * feat: updated EmbeddedResource for the latest spec * chore: changed encoding of meta in Prompts to encodeIfPresent * feat: compliance tests + http server transport (#197) * feat: http server transport * feat: added http server transport * feat: removed unused files * feat: added conformance tests * feat: improved conformace testing * chore: removed redundant files * feat/2025-11-25: sampling, elicitation, roots (#198) * feat: Roots implementation * feat: added unit testing * feat: improved unit tests and fixed NetworkTransport crash * feat: implemented sampling and elicitation * feat: improved sampling tests * feat: improved elicitation tests * feat: improved confirmance tests * feat: improved Prompts unit tests * feat: removed test code * feat: updated conformance tests * chore: removed redundant commas * chore: removed 6.0.3 swift version from ci * chore: improved unit tests a little bit * chore: update README.md * chore: add server progress tracking example to README.md * chore: updated README.md * chore: updated transports table formatting * chore: updated MockNetworkConnection --------- Co-authored-by: Austin Evans <austinjevans@me.com> Co-authored-by: yehorsobko <yehorsobko@macpaw.com>
This commit is contained in:
parent
6fa1a97b41
commit
6112a3995a
1 changed files with 11854 additions and 828 deletions
|
|
@ -20,6 +20,8 @@ struct ToolTests {
|
|||
#expect(tool.name == "test_tool")
|
||||
#expect(tool.description == "A test tool")
|
||||
#expect(tool.inputSchema != nil)
|
||||
#expect(tool.title == nil)
|
||||
#expect(tool.outputSchema == nil)
|
||||
}
|
||||
|
||||
@Test("Tool Annotations initialization and properties")
|
||||
|
|
@ -202,6 +204,40 @@ struct ToolTests {
|
|||
#expect(decoded.inputSchema == tool.inputSchema)
|
||||
}
|
||||
|
||||
@Test("Tool encoding and decoding with title and output schema")
|
||||
func testToolEncodingDecodingWithTitleAndOutputSchema() throws {
|
||||
let tool = Tool(
|
||||
name: "test_tool",
|
||||
title: "Readable Test Tool",
|
||||
description: "Test tool description",
|
||||
inputSchema: .object([
|
||||
"type": .string("object"),
|
||||
"properties": .object([
|
||||
"param1": .string("String parameter")
|
||||
]),
|
||||
]),
|
||||
outputSchema: .object([
|
||||
"type": .string("object"),
|
||||
"properties": .object([
|
||||
"result": .string("String result")
|
||||
]),
|
||||
])
|
||||
)
|
||||
|
||||
let encoder = JSONEncoder()
|
||||
let decoder = JSONDecoder()
|
||||
|
||||
let data = try encoder.encode(tool)
|
||||
let decoded = try decoder.decode(Tool.self, from: data)
|
||||
|
||||
#expect(decoded.title == tool.title)
|
||||
#expect(decoded.outputSchema == tool.outputSchema)
|
||||
|
||||
let jsonString = String(decoding: data, as: UTF8.self)
|
||||
#expect(jsonString.contains("\"title\":\"Readable Test Tool\""))
|
||||
#expect(jsonString.contains("\"outputSchema\""))
|
||||
}
|
||||
|
||||
@Test("Text content encoding and decoding")
|
||||
func testToolContentTextEncoding() throws {
|
||||
let content = Tool.Content.text("Hello, world!")
|
||||
|
|
@ -223,7 +259,7 @@ struct ToolTests {
|
|||
let content = Tool.Content.image(
|
||||
data: "base64data",
|
||||
mimeType: "image/png",
|
||||
metadata: ["width": "100", "height": "100"]
|
||||
metadata: .init(additionalFields: ["width": "100", "height": "100"])
|
||||
)
|
||||
let encoder = JSONEncoder()
|
||||
let decoder = JSONDecoder()
|
||||
|
|
@ -243,26 +279,60 @@ struct ToolTests {
|
|||
|
||||
@Test("Resource content encoding and decoding")
|
||||
func testToolContentResourceEncoding() throws {
|
||||
let content = Tool.Content.resource(
|
||||
let resourceContent = Resource.Content.text(
|
||||
"Sample text",
|
||||
uri: "file://test.txt",
|
||||
mimeType: "text/plain",
|
||||
text: "Sample text"
|
||||
mimeType: "text/plain"
|
||||
)
|
||||
let content = Tool.Content.resource(resource: resourceContent, annotations: nil, _meta: nil)
|
||||
let encoder = JSONEncoder()
|
||||
let decoder = JSONDecoder()
|
||||
|
||||
let data = try encoder.encode(content)
|
||||
let decoded = try decoder.decode(Tool.Content.self, from: data)
|
||||
|
||||
if case .resource(let uri, let mimeType, let text) = decoded {
|
||||
#expect(uri == "file://test.txt")
|
||||
#expect(mimeType == "text/plain")
|
||||
#expect(text == "Sample text")
|
||||
if case .resource(let resource, let annotations, let _meta) = decoded {
|
||||
#expect(resource.uri == "file://test.txt")
|
||||
#expect(resource.mimeType == "text/plain")
|
||||
#expect(resource.text == "Sample text")
|
||||
#expect(annotations == nil)
|
||||
#expect(_meta == nil)
|
||||
} else {
|
||||
#expect(Bool(false), "Expected resource content")
|
||||
}
|
||||
}
|
||||
|
||||
@Test("Resource link content includes title")
|
||||
func testToolContentResourceLinkEncoding() throws {
|
||||
let content = Tool.Content.resourceLink(
|
||||
uri: "file://resource.txt",
|
||||
name: "resource_name",
|
||||
title: "Resource Title",
|
||||
description: "Resource description",
|
||||
mimeType: "text/plain"
|
||||
)
|
||||
let encoder = JSONEncoder()
|
||||
let decoder = JSONDecoder()
|
||||
|
||||
let data = try encoder.encode(content)
|
||||
let jsonString = String(decoding: data, as: UTF8.self)
|
||||
#expect(jsonString.contains("\"title\":\"Resource Title\""))
|
||||
|
||||
let decoded = try decoder.decode(Tool.Content.self, from: data)
|
||||
if case .resourceLink(
|
||||
let uri, let name, let title, let description, let mimeType, let annotations
|
||||
) = decoded {
|
||||
#expect(uri == "file://resource.txt")
|
||||
#expect(name == "resource_name")
|
||||
#expect(title == "Resource Title")
|
||||
#expect(description == "Resource description")
|
||||
#expect(mimeType == "text/plain")
|
||||
#expect(annotations == nil)
|
||||
} else {
|
||||
#expect(Bool(false), "Expected resourceLink content")
|
||||
}
|
||||
}
|
||||
|
||||
@Test("Audio content encoding and decoding")
|
||||
func testToolContentAudioEncoding() throws {
|
||||
let content = Tool.Content.audio(
|
||||
|
|
@ -422,7 +492,6 @@ struct ToolTests {
|
|||
#expect(Bool(false), "Expected success result")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test("Tool with missing description")
|
||||
func testToolWithMissingDescription() throws {
|
||||
|
|
@ -433,10 +502,11 @@ struct ToolTests {
|
|||
}
|
||||
"""
|
||||
let jsonData = jsonString.data(using: .utf8)!
|
||||
|
||||
|
||||
let tool = try JSONDecoder().decode(Tool.self, from: jsonData)
|
||||
|
||||
|
||||
#expect(tool.name == "test_tool")
|
||||
#expect(tool.description == nil)
|
||||
#expect(tool.inputSchema == [:])
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue