@@ -42,23 +42,17 @@ public actor ShortcutChatPlugin: ChatPlugin {
4242 guard let shortcutName, !shortcutName. isEmpty else {
4343 message. content =
4444 " Please provide the shortcut name in format: `/ \( Self . command) (shortcut name)`. "
45- await chatGPTService. mutateHistory { history in
46- history. append ( message)
47- }
45+ await chatGPTService. memory. appendMessage ( message)
4846 return
4947 }
5048
5149 var input = String ( content) . trimmingCharacters ( in: . whitespacesAndNewlines)
5250 if input. isEmpty {
5351 // if no input detected, use the previous message as input
54- input = await chatGPTService. history. last? . content ?? " "
55- await chatGPTService. mutateHistory { history in
56- history. append ( . init( role: . user, content: originalMessage) )
57- }
52+ input = await chatGPTService. memory. messages. last? . content ?? " "
53+ await chatGPTService. memory. appendMessage ( . init( role: . user, content: originalMessage) )
5854 } else {
59- await chatGPTService. mutateHistory { history in
60- history. append ( . init( role: . user, content: originalMessage) )
61- }
55+ await chatGPTService. memory. appendMessage ( . init( role: . user, content: originalMessage) )
6256 }
6357
6458 do {
@@ -71,7 +65,7 @@ public actor ShortcutChatPlugin: ChatPlugin {
7165 . appendingPathComponent ( " \( id) -input.txt " )
7266 let temporaryOutputFileURL = temporaryURL
7367 . appendingPathComponent ( " \( id) -output " )
74-
68+
7569 try input. write ( to: temporaryInputFileURL, atomically: true , encoding: . utf8)
7670
7771 let command = """
@@ -86,7 +80,7 @@ public actor ShortcutChatPlugin: ChatPlugin {
8680 currentDirectoryPath: " / " ,
8781 environment: [ : ]
8882 )
89-
83+
9084 await Task . yield ( )
9185
9286 if FileManager . default. fileExists ( atPath: temporaryOutputFileURL. path) {
@@ -96,33 +90,25 @@ public actor ShortcutChatPlugin: ChatPlugin {
9690 if text. isEmpty {
9791 message. content = " Finished "
9892 }
99- await chatGPTService. mutateHistory { history in
100- history. append ( message)
101- }
93+ await chatGPTService. memory. appendMessage ( message)
10294 } else {
10395 message. content = """
10496 [View File]( \( temporaryOutputFileURL) )
10597 """
106- await chatGPTService. mutateHistory { history in
107- history. append ( message)
108- }
98+ await chatGPTService. memory. appendMessage ( message)
10999 }
110-
100+
111101 return
112102 }
113-
103+
114104 message. content = " Finished "
115- await chatGPTService. mutateHistory { history in
116- history. append ( message)
117- }
105+ await chatGPTService. memory. appendMessage ( message)
118106 } catch {
119107 message. content = error. localizedDescription
120108 if error. localizedDescription. isEmpty {
121109 message. content = " Error "
122110 }
123- await chatGPTService. mutateHistory { history in
124- history. append ( message)
125- }
111+ await chatGPTService. memory. appendMessage ( message)
126112 }
127113 }
128114
0 commit comments