forked from github/CopilotForXcode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathChatContextMenu.swift
More file actions
87 lines (75 loc) · 2.12 KB
/
ChatContextMenu.swift
File metadata and controls
87 lines (75 loc) · 2.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
import AppKit
import ChatService
import ComposableArchitecture
import SharedUIComponents
import SwiftUI
struct ChatTabItemView: View {
let chat: StoreOf<Chat>
var body: some View {
WithPerceptionTracking {
Text(chat.title)
}
}
}
struct ChatConversationItemView: View {
let chat: StoreOf<Chat>
var body: some View {
WithPerceptionTracking {
Text(chat.title)
.frame(alignment: .leading)
}
}
}
struct ChatContextMenu: View {
let store: StoreOf<ChatMenu>
@AppStorage(\.customCommands) var customCommands
var body: some View {
WithPerceptionTracking {
currentSystemPrompt
.onAppear { store.send(.appear) }
currentExtraSystemPrompt
Divider()
customCommandMenu
}
}
@ViewBuilder
var currentSystemPrompt: some View {
Text("System Prompt:")
Text({
var text = store.systemPrompt
if text.isEmpty { text = "N/A" }
if text.count > 30 { text = String(text.prefix(30)) + "..." }
return text
}() as String)
}
@ViewBuilder
var currentExtraSystemPrompt: some View {
Text("Extra Prompt:")
Text({
var text = store.extraSystemPrompt
if text.isEmpty { text = "N/A" }
if text.count > 30 { text = String(text.prefix(30)) + "..." }
return text
}() as String)
}
var customCommandMenu: some View {
Menu("Custom Commands") {
ForEach(
customCommands.filter {
switch $0.feature {
case .chatWithSelection, .customChat: return true
case .promptToCode: return false
case .singleRoundDialog: return false
}
},
id: \.name
) { command in
Button(action: {
store.send(.customCommandButtonTapped(command))
}) {
Text(command.name)
}
}
}
}
}