Skip to content

Commit 6c19880

Browse files
committed
Add comtext picker for custom command
1 parent ed57ecd commit 6c19880

File tree

6 files changed

+281
-30
lines changed

6 files changed

+281
-30
lines changed

Core/Sources/HostApp/CustomCommandSettings/CustomCommandView.swift

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,9 @@ struct CustomCommandView_Preview: PreviewProvider {
275275
extraSystemPrompt: nil,
276276
prompt: "Hello",
277277
useExtraSystemPrompt: false
278-
)
278+
),
279+
ignoreExistingAttachments: false,
280+
attachments: []
279281
),
280282
.init(
281283
commandId: "2",
@@ -285,7 +287,9 @@ struct CustomCommandView_Preview: PreviewProvider {
285287
prompt: "Refactor",
286288
continuousMode: false,
287289
generateDescription: true
288-
)
290+
),
291+
ignoreExistingAttachments: false,
292+
attachments: []
289293
),
290294
], "CustomCommandView_Preview"))
291295

@@ -299,7 +303,9 @@ struct CustomCommandView_Preview: PreviewProvider {
299303
extraSystemPrompt: nil,
300304
prompt: "Hello",
301305
useExtraSystemPrompt: false
302-
)
306+
),
307+
ignoreExistingAttachments: false,
308+
attachments: [] as [CustomCommand.Attachment]
303309
)))
304310
),
305311
reducer: { CustomCommandFeature(settings: settings) }
@@ -319,7 +325,9 @@ struct CustomCommandView_NoEditing_Preview: PreviewProvider {
319325
extraSystemPrompt: nil,
320326
prompt: "Hello",
321327
useExtraSystemPrompt: false
322-
)
328+
),
329+
ignoreExistingAttachments: false,
330+
attachments: []
323331
),
324332
.init(
325333
commandId: "2",
@@ -329,7 +337,9 @@ struct CustomCommandView_NoEditing_Preview: PreviewProvider {
329337
prompt: "Refactor",
330338
continuousMode: false,
331339
generateDescription: true
332-
)
340+
),
341+
ignoreExistingAttachments: false,
342+
attachments: []
333343
),
334344
], "CustomCommandView_Preview"))
335345

Core/Sources/HostApp/CustomCommandSettings/EditCustomCommand.swift

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,16 @@ struct EditCustomCommand {
2323
var promptToCode = EditPromptToCodeCommand.State()
2424
var customChat = EditCustomChatCommand.State()
2525
var singleRoundDialog = EditSingleRoundDialogCommand.State()
26+
var attachments = EditCustomCommandAttachment.State()
2627

2728
init(_ command: CustomCommand?) {
2829
isNewCommand = command == nil
2930
commandId = command?.id ?? UUID().uuidString
3031
name = command?.name ?? "New Command"
32+
attachments = .init(
33+
attachments: command?.attachments ?? [],
34+
ignoreExistingAttachments: command?.ignoreExistingAttachments ?? false
35+
)
3136

3237
switch command?.feature {
3338
case let .chatWithSelection(extraSystemPrompt, prompt, useExtraSystemPrompt):
@@ -83,6 +88,7 @@ struct EditCustomCommand {
8388
case promptToCode(EditPromptToCodeCommand.Action)
8489
case customChat(EditCustomChatCommand.Action)
8590
case singleRoundDialog(EditSingleRoundDialogCommand.Action)
91+
case attachments(EditCustomCommandAttachment.Action)
8692
}
8793

8894
let settings: CustomCommandView.Settings
@@ -106,6 +112,10 @@ struct EditCustomCommand {
106112
EditSingleRoundDialogCommand()
107113
}
108114

115+
Scope(state: \.attachments, action: \.attachments) {
116+
EditCustomCommandAttachment()
117+
}
118+
109119
BindingReducer()
110120

111121
Reduce { state, action in
@@ -151,7 +161,9 @@ struct EditCustomCommand {
151161
receiveReplyInNotification: state.receiveReplyInNotification
152162
)
153163
}
154-
}()
164+
}(),
165+
ignoreExistingAttachments: state.attachments.ignoreExistingAttachments,
166+
attachments: state.attachments.attachments
155167
)
156168

157169
if state.isNewCommand {
@@ -184,6 +196,32 @@ struct EditCustomCommand {
184196
return .none
185197
case .singleRoundDialog:
186198
return .none
199+
case .attachments:
200+
return .none
201+
}
202+
}
203+
}
204+
}
205+
206+
@Reducer
207+
struct EditCustomCommandAttachment {
208+
@ObservableState
209+
struct State: Equatable {
210+
var attachments: [CustomCommand.Attachment] = []
211+
var ignoreExistingAttachments: Bool = false
212+
}
213+
214+
enum Action: BindableAction, Equatable {
215+
case binding(BindingAction<State>)
216+
}
217+
218+
var body: some ReducerOf<Self> {
219+
BindingReducer()
220+
221+
Reduce { _, action in
222+
switch action {
223+
case .binding:
224+
return .none
187225
}
188226
}
189227
}

0 commit comments

Comments
 (0)