Skip to content

Commit 4298221

Browse files
committed
Add id to references
1 parent f1cb526 commit 4298221

2 files changed

Lines changed: 10 additions & 2 deletions

File tree

Tool/Sources/ChatBasic/ChatAgent.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ public enum ChatAgentResponse {
44
public enum Content {
55
case text(String)
66
}
7-
7+
88
public enum ActionResult {
99
case success(String)
1010
case failure(String)

Tool/Sources/ChatBasic/ChatMessage.swift

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ public struct ChatMessage: Equatable, Codable {
5959
}
6060

6161
/// A reference to include in a chat message.
62-
public struct Reference: Codable, Equatable {
62+
public struct Reference: Codable, Equatable, Identifiable {
6363
/// The kind of reference.
6464
public enum Kind: Codable, Equatable {
6565
public enum Symbol: String, Codable {
@@ -89,6 +89,8 @@ public struct ChatMessage: Equatable, Codable {
8989
case error
9090
}
9191

92+
@FallbackDecoding<ReferenceIDFallback>
93+
public var id: String
9294
/// The title of the reference.
9395
public var title: String
9496
/// The content of the reference.
@@ -98,10 +100,12 @@ public struct ChatMessage: Equatable, Codable {
98100
public var kind: Kind
99101

100102
public init(
103+
id: String = UUID().uuidString,
101104
title: String,
102105
content: String,
103106
kind: Kind
104107
) {
108+
self.id = id
105109
self.title = title
106110
self.content = content
107111
self.kind = kind
@@ -188,6 +192,10 @@ public struct ReferenceKindFallback: FallbackValueProvider {
188192
public static var defaultValue: ChatMessage.Reference.Kind { .other(kind: "Unknown") }
189193
}
190194

195+
public struct ReferenceIDFallback: FallbackValueProvider {
196+
public static var defaultValue: String { UUID().uuidString }
197+
}
198+
191199
public struct ChatMessageRoleFallback: FallbackValueProvider {
192200
public static var defaultValue: ChatMessage.Role { .user }
193201
}

0 commit comments

Comments
 (0)