Skip to content

Commit 4f199b5

Browse files
committed
Make resend work for plugin
1 parent 77f1b57 commit 4f199b5

File tree

4 files changed

+24
-12
lines changed

4 files changed

+24
-12
lines changed

Core/Sources/ChatPlugins/AITerminalChatPlugin.swift

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public actor AITerminalChatPlugin: ChatPlugin {
1919
self.delegate = delegate
2020
}
2121

22-
public func send(content: String) async {
22+
public func send(content: String, originalMessage: String) async {
2323
if !isStarted {
2424
isStarted = true
2525
delegate?.pluginDidStart(self)
@@ -69,7 +69,11 @@ public actor AITerminalChatPlugin: ChatPlugin {
6969
}
7070
} else {
7171
await chatGPTService.mutateHistory { history in
72-
history.append(.init(role: .user, content: "Run a command to \(content)"))
72+
history.append(.init(
73+
role: .user,
74+
content: originalMessage,
75+
summary: "Run a command to \(content)")
76+
)
7377
}
7478
delegate?.pluginDidStartResponding(self)
7579
let result = try await generateCommand(task: content)

Core/Sources/ChatPlugins/ChatPlugin.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ public protocol ChatPlugin: AnyObject {
77
var name: String { get }
88

99
init(inside chatGPTService: any ChatGPTServiceType, delegate: ChatPluginDelegate)
10-
func send(content: String) async
10+
func send(content: String, originalMessage: String) async
1111
func cancel() async
1212
func stopResponding() async
1313
}

Core/Sources/ChatPlugins/TerminalChatPlugin.swift

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public actor TerminalChatPlugin: ChatPlugin {
1717
self.delegate = delegate
1818
}
1919

20-
public func send(content: String) async {
20+
public func send(content: String, originalMessage: String) async {
2121
delegate?.pluginDidStart(self)
2222
delegate?.pluginDidStartResponding(self)
2323

@@ -38,7 +38,11 @@ public actor TerminalChatPlugin: ChatPlugin {
3838
let projectURL = try await Environment.fetchCurrentProjectRootURL(fileURL)
3939

4040
await chatGPTService.mutateHistory { history in
41-
history.append(.init(role: .user, content: "Run command: \(content)"))
41+
history.append(.init(
42+
role: .user,
43+
content: originalMessage,
44+
summary: "Run command: \(content)")
45+
)
4246
}
4347

4448
if isCancelled { throw CancellationError() }

Core/Sources/ChatService/ChatService.swift

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -53,24 +53,28 @@ public final class ChatService: ObservableObject {
5353
}
5454
}
5555
} else if let runningPlugin {
56-
await runningPlugin.send(content: content)
56+
await runningPlugin.send(content: content, originalMessage: content)
5757
} else if let pluginType = plugins[command] {
5858
let plugin = pluginType.init(inside: chatGPTService, delegate: self)
5959
if #available(macOS 13.0, *) {
6060
await plugin.send(
6161
content: String(
6262
content.dropFirst(command.count + 1)
6363
.trimmingPrefix(while: { $0 == " " })
64-
)
64+
),
65+
originalMessage: content
6566
)
6667
} else {
67-
await plugin.send(content: String(content.dropFirst(command.count + 1)))
68+
await plugin.send(
69+
content: String(content.dropFirst(command.count + 1)),
70+
originalMessage: content
71+
)
6872
}
6973
} else {
7074
_ = try await chatGPTService.send(content: content, summary: nil)
7175
}
7276
} else if let runningPlugin {
73-
await runningPlugin.send(content: content)
77+
await runningPlugin.send(content: content, originalMessage: content)
7478
} else {
7579
_ = try await chatGPTService.send(content: content, summary: nil)
7680
}
@@ -89,13 +93,13 @@ public final class ChatService: ObservableObject {
8993
}
9094
await chatGPTService.clearHistory()
9195
}
92-
96+
9397
public func deleteMessage(id: String) async {
9498
await chatGPTService.mutateHistory { messages in
9599
messages.removeAll(where: { $0.id == id })
96100
}
97101
}
98-
102+
99103
public func resendMessage(id: String) async throws {
100104
if let message = (await chatGPTService.history).first(where: { $0.id == id }) {
101105
try await send(content: message.content)
@@ -133,7 +137,7 @@ extension ChatService: ChatPluginDelegate {
133137
public func shouldStartAnotherPlugin(_ type: ChatPlugin.Type, withContent content: String) {
134138
let plugin = type.init(inside: chatGPTService, delegate: self)
135139
Task {
136-
await plugin.send(content: content)
140+
await plugin.send(content: content, originalMessage: content)
137141
}
138142
}
139143
}

0 commit comments

Comments
 (0)