Skip to content
Open
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
5 changes: 4 additions & 1 deletion Sources/AnyLanguageModelMacros/GenerableMacro.swift
Original file line number Diff line number Diff line change
Expand Up @@ -690,12 +690,15 @@ public struct GenerableMacro: MemberMacro, ExtensionMacro {

return DeclSyntax(
stringLiteral: """
public struct PartiallyGenerated: Sendable, ConvertibleFromGeneratedContent {
public struct PartiallyGenerated: Identifiable, Sendable, ConvertibleFromGeneratedContent {
public var id: GenerationID
Copy link

Copilot AI Dec 23, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The id property should be declared as public let instead of public var to make it immutable. This is consistent with: 1) the other properties in the PartiallyGenerated struct which are all declared as let, 2) the semantics of Identifiable where the identity should remain stable and not change, and 3) the documentation in GenerationID which states that IDs are "stable for the duration of a response".

Suggested change
public var id: GenerationID
public let id: GenerationID

Copilot uses AI. Check for mistakes.

\(optionalProperties)

private let rawContent: GeneratedContent

public init(_ generatedContent: GeneratedContent) throws {
self.id = generatedContent.id ?? GenerationID()
self.rawContent = generatedContent

if \(properties.isEmpty ? "case .structure = generatedContent.kind" : "case .structure(let properties, _) = generatedContent.kind") {
Expand Down
13 changes: 9 additions & 4 deletions Tests/AnyLanguageModelTests/GenerableMacroTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -126,13 +126,18 @@ struct GenerableMacroTests {

@Test("Create instance from GeneratedContent")
func fromGeneratedContent() throws {
let content = GeneratedContent(properties: [
"name": GeneratedContent("Bob"),
"age": GeneratedContent(kind: .number(25)),
])
let generationID = GenerationID()
let content = GeneratedContent(
properties: [
"name": GeneratedContent("Bob"),
"age": GeneratedContent(kind: .number(25)),
],
id: generationID
)

let args = try TestArguments(content)
#expect(args.name == "Bob")
#expect(args.age == 25)
#expect(args.asPartiallyGenerated().id == generationID)
}
}