Skip to content

Commit da20352

Browse files
committed
Merge branch 'feature/custom-command-one-time-conversation' into develop
2 parents fad5fae + 9c38bc9 commit da20352

15 files changed

Lines changed: 1016 additions & 441 deletions

File tree

Core/Package.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,8 +128,10 @@ let package = Package(
128128
"CodeiumService",
129129
"SuggestionModel",
130130
"LaunchAgentManager",
131+
.product(name: "MarkdownUI", package: "swift-markdown-ui"),
131132
.product(name: "OpenAIService", package: "Tool"),
132133
.product(name: "Preferences", package: "Tool"),
134+
.product(name: "ComposableArchitecture", package: "swift-composable-architecture"),
133135
]
134136
),
135137

Core/Sources/ChatService/ChatService.swift

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,14 @@ public final class ChatService: ObservableObject {
8686
}
8787
}
8888

89+
public func sendAndWait(content: String) async throws -> String {
90+
try await send(content: content)
91+
if let reply = await memory.history.last(where: { $0.role == .assistant })?.content {
92+
return reply
93+
}
94+
return ""
95+
}
96+
8997
public func stopReceivingMessage() async {
9098
await pluginController.stopResponding()
9199
await chatGPTService.stopReceivingMessage()
@@ -175,8 +183,8 @@ public final class ChatService: ObservableObject {
175183
sendingMessageImmediately: prompt,
176184
name: command.name
177185
)
178-
case .promptToCode:
179-
return nil
186+
case .promptToCode: return nil
187+
case .singleRoundDialog: return nil
180188
}
181189
}()
182190

@@ -207,5 +215,21 @@ public final class ChatService: ObservableObject {
207215
try await send(content: templateProcessor.process(sendingMessageImmediately))
208216
}
209217
}
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+
}
210234
}
211235

Core/Sources/ChatTab/ChatGPT/ChatPanel.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -463,6 +463,7 @@ struct ChatContextMenu: View {
463463
switch $0.feature {
464464
case .chatWithSelection, .customChat: return true
465465
case .promptToCode: return false
466+
case .singleRoundDialog: return false
466467
}
467468
},
468469
id: \.name
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
import ComposableArchitecture
2+
import Foundation
3+
import Preferences
4+
import SwiftUI
5+
6+
struct CustomCommandFeature: ReducerProtocol {
7+
struct State: Equatable {
8+
var editCustomCommand: EditCustomCommand.State?
9+
}
10+
11+
let settings: CustomCommandView.Settings
12+
let toast: (Text, ToastType) -> Void
13+
14+
enum Action: Equatable {
15+
case createNewCommand
16+
case editCommand(CustomCommand)
17+
case editCustomCommand(EditCustomCommand.Action)
18+
case deleteCommand(CustomCommand)
19+
}
20+
21+
var body: some ReducerProtocol<State, Action> {
22+
Reduce { state, action in
23+
switch action {
24+
case .createNewCommand:
25+
state.editCustomCommand = EditCustomCommand.State(nil)
26+
return .none
27+
case let .editCommand(command):
28+
state.editCustomCommand = EditCustomCommand.State(command)
29+
return .none
30+
case .editCustomCommand(.close):
31+
state.editCustomCommand = nil
32+
return .none
33+
case let .deleteCommand(command):
34+
settings.customCommands.removeAll(
35+
where: { $0.id == command.id }
36+
)
37+
if state.editCustomCommand?.commandId == command.id {
38+
state.editCustomCommand = nil
39+
}
40+
return .none
41+
case .editCustomCommand:
42+
return .none
43+
44+
}
45+
}.ifLet(\.editCustomCommand, action: /Action.editCustomCommand) {
46+
EditCustomCommand(settings: settings, toast: toast)
47+
}
48+
}
49+
}

0 commit comments

Comments
 (0)