@@ -74,17 +74,21 @@ struct ChatPanelMessages: View {
7474 }
7575
7676 ForEach ( chat. history. reversed ( ) , id: \. id) { message in
77- let text = message. text. isEmpty && !message. isUser ? " ... " : message
78- . text
77+ let text = message. text
7978
80- if message. isUser {
79+ switch message. role {
80+ case . user:
8181 UserMessage ( id: message. id, text: text, chat: chat)
8282 . listRowInsets ( EdgeInsets ( top: 0 , leading: - 8 , bottom: 0 , trailing: - 8 ) )
8383 . padding ( . vertical, 4 )
84- } else {
84+ case . assistant :
8585 BotMessage ( id: message. id, text: text, chat: chat)
8686 . listRowInsets ( EdgeInsets ( top: 0 , leading: - 8 , bottom: 0 , trailing: - 8 ) )
8787 . padding ( . vertical, 4 )
88+ case . function:
89+ FunctionMessage ( id: message. id, text: text)
90+ case . ignored:
91+ EmptyView ( )
8892 }
8993 }
9094 . listItemTint ( . clear)
@@ -147,7 +151,7 @@ private struct Instruction: View {
147151 - The text cursor location.
148152
149153 If you'd like me to examine the entire file, simply add `@file` to the beginning of your message.
150-
154+
151155 To use plugins, you can start a message with `/pluginName`.
152156 """
153157 )
@@ -162,7 +166,7 @@ private struct Instruction: View {
162166 - The text cursor location.
163167
164168 If you would like me to examine the selected code, please prefix your message with `@selection`. If you would like me to examine the entire file, please prefix your message with `@file`.
165-
169+
166170 To use plugins, you can start a message with `/pluginName`.
167171 """
168172 )
@@ -297,6 +301,21 @@ private struct BotMessage: View {
297301 }
298302}
299303
304+ struct FunctionMessage : View {
305+ let id : String
306+ let text : String
307+ @AppStorage ( \. chatFontSize) var chatFontSize
308+
309+ var body : some View {
310+ Markdown ( text)
311+ . textSelection ( . enabled)
312+ . markdownTheme ( . functionCall( fontSize: chatFontSize) )
313+ . scaleEffect ( x: - 1 , y: - 1 , anchor: . center)
314+ . padding ( . vertical, 2 )
315+ . padding ( . trailing, 2 )
316+ }
317+ }
318+
300319struct ChatPanelInputArea : View {
301320 @ObservedObject var chat : ChatProvider
302321 @Binding var typedMessage : String
@@ -398,7 +417,7 @@ struct ChatPanelInputArea: View {
398417 chat. send ( typedMessage)
399418 typedMessage = " "
400419 }
401-
420+
402421 func chatAutoCompletion( text: String , proposed: [ String ] , range: NSRange ) -> [ String ] {
403422 guard text. count == 1 else { return [ ] }
404423 let plugins = chat. pluginIdentifiers. map { " / \( $0) " }
@@ -407,7 +426,7 @@ struct ChatPanelInputArea: View {
407426 " @selection " ,
408427 " @file " ,
409428 ]
410-
429+
411430 let result : [ String ] = availableFeatures
412431 . filter { $0. hasPrefix ( text) && $0 != text }
413432 . compactMap {
@@ -584,24 +603,32 @@ struct ChatPanel_Preview: PreviewProvider {
584603 static let history : [ ChatMessage ] = [
585604 . init(
586605 id: " 1 " ,
587- isUser : true ,
606+ role : . user ,
588607 text: " **Hello** "
589608 ) ,
590609 . init(
591610 id: " 2 " ,
592- isUser : false ,
611+ role : . assistant ,
593612 text: """
594613 ```swift
595614 func foo() {}
596615 ```
597616 **Hey**! What can I do for you?**Hey**! What can I do for you?**Hey**! What can I do for you?**Hey**! What can I do for you?
598617 """
599618 ) ,
600- . init( id: " 5 " , isUser: false , text: " Yooo " ) ,
601- . init( id: " 4 " , isUser: true , text: " Yeeeehh " ) ,
619+ . init( id: " 7 " , role: . ignored, text: " Ignored " ) ,
620+ . init( id: " 6 " , role: . function, text: """
621+ Searching for something...
622+ - abc
623+ - [def](https://1.com)
624+ > hello
625+ > hi
626+ """ ) ,
627+ . init( id: " 5 " , role: . assistant, text: " Yooo " ) ,
628+ . init( id: " 4 " , role: . user, text: " Yeeeehh " ) ,
602629 . init(
603630 id: " 3 " ,
604- isUser : true ,
631+ role : . user ,
605632 text: #"""
606633 Please buy me a coffee!
607634 | Coffee | Milk |
@@ -624,7 +651,7 @@ struct ChatPanel_Preview: PreviewProvider {
624651 history: ChatPanel_Preview . history,
625652 isReceivingMessage: true
626653 ) )
627- . frame ( width: 450 , height: 700 )
654+ . frame ( width: 450 , height: 1200 )
628655 . colorScheme ( . dark)
629656 }
630657}
@@ -700,6 +727,3 @@ struct ChatPanel_Light_Preview: PreviewProvider {
700727 }
701728}
702729
703-
704-
705-
0 commit comments