Skip to content

Commit ac2aba7

Browse files
committed
ensure we always provide an ID
1 parent d6c4faa commit ac2aba7

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ public struct ContentView: View {
5151

5252
func sendMessage(message: String) {
5353
Task {
54-
try! await api.send(event: .createConversationItem(Item(message: .init(from: .user, content: [.text(message)]))))
54+
try! await api.send(event: .createConversationItem(Item(message: .init(id: "msg-1", from: .user, content: [.text(message)]))))
5555
try! await api.send(event: .createResponse())
5656
}
5757
}

src/Models/Item.swift

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ public enum Item: Sendable {
141141
}
142142

143143
/// The unique ID of the item.
144-
public var id: String?
144+
public var id: String
145145
/// The type of the item
146146
private var type: String = "message"
147147
/// The status of the item
@@ -151,7 +151,7 @@ public enum Item: Sendable {
151151
/// The content of the message.
152152
public var content: [Content]
153153

154-
public init(id: String? = nil, from role: ItemRole, content: [Content]) {
154+
public init(id: String, from role: ItemRole, content: [Content]) {
155155
self.id = id
156156
self.role = role
157157
status = .completed
@@ -195,6 +195,17 @@ public enum Item: Sendable {
195195
case functionCall(FunctionCall)
196196
case functionCallOutput(FunctionCallOutput)
197197

198+
public var id: String {
199+
switch self {
200+
case let .message(message):
201+
return message.id
202+
case let .functionCall(functionCall):
203+
return functionCall.id
204+
case let .functionCallOutput(functionCallOutput):
205+
return functionCallOutput.id
206+
}
207+
}
208+
198209
public init(message: Message) {
199210
self = .message(message)
200211
}

0 commit comments

Comments
 (0)