Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add comtext picker for custom command
  • Loading branch information
intitni committed Jan 6, 2025
commit 6c19880f2ac6f2b345d80d0efcac1a2d8cc6b9b2
20 changes: 15 additions & 5 deletions Core/Sources/HostApp/CustomCommandSettings/CustomCommandView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,9 @@ struct CustomCommandView_Preview: PreviewProvider {
extraSystemPrompt: nil,
prompt: "Hello",
useExtraSystemPrompt: false
)
),
ignoreExistingAttachments: false,
attachments: []
),
.init(
commandId: "2",
Expand All @@ -285,7 +287,9 @@ struct CustomCommandView_Preview: PreviewProvider {
prompt: "Refactor",
continuousMode: false,
generateDescription: true
)
),
ignoreExistingAttachments: false,
attachments: []
),
], "CustomCommandView_Preview"))

Expand All @@ -299,7 +303,9 @@ struct CustomCommandView_Preview: PreviewProvider {
extraSystemPrompt: nil,
prompt: "Hello",
useExtraSystemPrompt: false
)
),
ignoreExistingAttachments: false,
attachments: [] as [CustomCommand.Attachment]
)))
),
reducer: { CustomCommandFeature(settings: settings) }
Expand All @@ -319,7 +325,9 @@ struct CustomCommandView_NoEditing_Preview: PreviewProvider {
extraSystemPrompt: nil,
prompt: "Hello",
useExtraSystemPrompt: false
)
),
ignoreExistingAttachments: false,
attachments: []
),
.init(
commandId: "2",
Expand All @@ -329,7 +337,9 @@ struct CustomCommandView_NoEditing_Preview: PreviewProvider {
prompt: "Refactor",
continuousMode: false,
generateDescription: true
)
),
ignoreExistingAttachments: false,
attachments: []
),
], "CustomCommandView_Preview"))

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,16 @@ struct EditCustomCommand {
var promptToCode = EditPromptToCodeCommand.State()
var customChat = EditCustomChatCommand.State()
var singleRoundDialog = EditSingleRoundDialogCommand.State()
var attachments = EditCustomCommandAttachment.State()

init(_ command: CustomCommand?) {
isNewCommand = command == nil
commandId = command?.id ?? UUID().uuidString
name = command?.name ?? "New Command"
attachments = .init(
attachments: command?.attachments ?? [],
ignoreExistingAttachments: command?.ignoreExistingAttachments ?? false
)

switch command?.feature {
case let .chatWithSelection(extraSystemPrompt, prompt, useExtraSystemPrompt):
Expand Down Expand Up @@ -83,6 +88,7 @@ struct EditCustomCommand {
case promptToCode(EditPromptToCodeCommand.Action)
case customChat(EditCustomChatCommand.Action)
case singleRoundDialog(EditSingleRoundDialogCommand.Action)
case attachments(EditCustomCommandAttachment.Action)
}

let settings: CustomCommandView.Settings
Expand All @@ -106,6 +112,10 @@ struct EditCustomCommand {
EditSingleRoundDialogCommand()
}

Scope(state: \.attachments, action: \.attachments) {
EditCustomCommandAttachment()
}

BindingReducer()

Reduce { state, action in
Expand Down Expand Up @@ -151,7 +161,9 @@ struct EditCustomCommand {
receiveReplyInNotification: state.receiveReplyInNotification
)
}
}()
}(),
ignoreExistingAttachments: state.attachments.ignoreExistingAttachments,
attachments: state.attachments.attachments
)

if state.isNewCommand {
Expand Down Expand Up @@ -184,6 +196,32 @@ struct EditCustomCommand {
return .none
case .singleRoundDialog:
return .none
case .attachments:
return .none
}
}
}
}

@Reducer
struct EditCustomCommandAttachment {
@ObservableState
struct State: Equatable {
var attachments: [CustomCommand.Attachment] = []
var ignoreExistingAttachments: Bool = false
}

enum Action: BindableAction, Equatable {
case binding(BindingAction<State>)
}

var body: some ReducerOf<Self> {
BindingReducer()

Reduce { _, action in
switch action {
case .binding:
return .none
}
}
}
Expand Down
Loading