11import Foundation
2+ import Preferences
23import SwiftUI
34
45public final class ChatProvider : ObservableObject {
56 let id = UUID ( )
67 @Published public var history : [ ChatMessage ] = [ ]
78 @Published public var isReceivingMessage = false
9+ public var systemPrompt = " "
10+ public var extraSystemPrompt = " "
811 public var onMessageSend : ( String ) -> Void
912 public var onStop : ( ) -> Void
1013 public var onClear : ( ) -> Void
1114 public var onClose : ( ) -> Void
1215 public var onSwitchContext : ( ) -> Void
1316 public var onDeleteMessage : ( String ) -> Void
1417 public var onResendMessage : ( String ) -> Void
18+ public var onResetPrompt : ( ) -> Void
19+ public var onRunCustomCommand : ( CustomCommand ) -> Void = { _ in }
1520
1621 public init (
1722 history: [ ChatMessage ] = [ ] ,
@@ -22,7 +27,9 @@ public final class ChatProvider: ObservableObject {
2227 onClose: @escaping ( ) -> Void = { } ,
2328 onSwitchContext: @escaping ( ) -> Void = { } ,
2429 onDeleteMessage: @escaping ( String ) -> Void = { _ in } ,
25- onResendMessage: @escaping ( String ) -> Void = { _ in }
30+ onResendMessage: @escaping ( String ) -> Void = { _ in } ,
31+ onResetPrompt: @escaping ( ) -> Void = { } ,
32+ onRunCustomCommand: @escaping ( CustomCommand ) -> Void = { _ in }
2633 ) {
2734 self . history = history
2835 self . isReceivingMessage = isReceivingMessage
@@ -33,6 +40,8 @@ public final class ChatProvider: ObservableObject {
3340 self . onSwitchContext = onSwitchContext
3441 self . onDeleteMessage = onDeleteMessage
3542 self . onResendMessage = onResendMessage
43+ self . onResetPrompt = onResetPrompt
44+ self . onRunCustomCommand = onRunCustomCommand
3645 }
3746
3847 public func send( _ message: String ) { onMessageSend ( message) }
@@ -42,6 +51,10 @@ public final class ChatProvider: ObservableObject {
4251 public func switchContext( ) { onSwitchContext ( ) }
4352 public func deleteMessage( id: String ) { onDeleteMessage ( id) }
4453 public func resendMessage( id: String ) { onResendMessage ( id) }
54+ public func resetPrompt( ) { onResetPrompt ( ) }
55+ public func triggerCustomCommand( _ command: CustomCommand ) {
56+ onRunCustomCommand ( command)
57+ }
4558}
4659
4760public struct ChatMessage : Equatable {
@@ -55,3 +68,4 @@ public struct ChatMessage: Equatable {
5568 self . text = text
5669 }
5770}
71+
0 commit comments