Skip to content

Commit 46a91ee

Browse files
committed
Update single round dialog to support template
1 parent b76ca97 commit 46a91ee

File tree

3 files changed

+34
-10
lines changed

3 files changed

+34
-10
lines changed

Core/Sources/ChatService/ChatService.swift

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ public final class ChatService: ObservableObject {
8585
isReceivingMessage = false
8686
}
8787
}
88-
88+
8989
public func sendAndWait(content: String) async throws -> String {
9090
try await send(content: content)
9191
if let reply = await memory.history.last(where: { $0.role == .assistant })?.content {
@@ -215,5 +215,21 @@ public final class ChatService: ObservableObject {
215215
try await send(content: templateProcessor.process(sendingMessageImmediately))
216216
}
217217
}
218+
219+
public func handleSingleRoundDialogCommand(
220+
systemPrompt: String?,
221+
overwriteSystemPrompt: Bool,
222+
prompt: String
223+
) async throws -> String {
224+
let templateProcessor = CustomCommandTemplateProcessor()
225+
if let systemPrompt {
226+
if overwriteSystemPrompt {
227+
mutateSystemPrompt(templateProcessor.process(systemPrompt))
228+
} else {
229+
mutateExtraSystemPrompt(templateProcessor.process(systemPrompt))
230+
}
231+
}
232+
return try await sendAndWait(content: templateProcessor.process(prompt))
233+
}
218234
}
219235

Core/Sources/Service/SuggestionCommandHandler/WindowBaseCommandHandler.swift

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -400,16 +400,12 @@ extension WindowBaseCommandHandler {
400400

401401
let service = ChatService()
402402

403-
if let systemPrompt {
404-
if overwriteSystemPrompt {
405-
service.mutateSystemPrompt(systemPrompt)
406-
} else {
407-
service.mutateExtraSystemPrompt(systemPrompt)
408-
}
409-
}
403+
let result = try await service.handleSingleRoundDialogCommand(
404+
systemPrompt: systemPrompt,
405+
overwriteSystemPrompt: overwriteSystemPrompt,
406+
prompt: prompt
407+
)
410408

411-
let result = try await service.sendAndWait(content: prompt)
412-
413409
guard receiveReplyInNotification else { return }
414410

415411
let granted = try await UNUserNotificationCenter.current()

Tool/Sources/Preferences/Types/CustomCommand.swift

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,18 @@ public struct CustomCommand: Codable, Equatable {
4141
self.feature = feature
4242
}
4343

44+
public init(from decoder: Decoder) throws {
45+
let container = try decoder.container(keyedBy: CodingKeys.self)
46+
commandId = try container.decodeIfPresent(String.self, forKey: .commandId)
47+
name = try container.decode(String.self, forKey: .name)
48+
feature = (try? container
49+
.decode(CustomCommand.Feature.self, forKey: .feature)) ?? .chatWithSelection(
50+
extraSystemPrompt: "",
51+
prompt: "",
52+
useExtraSystemPrompt: false
53+
)
54+
}
55+
4456
var legacyId: String {
4557
name.sha1HexString
4658
}

0 commit comments

Comments
 (0)