Repair Toolbox navigation, chat web lookup, and model discovery
This commit is contained in:
+96
-12
@@ -73,6 +73,8 @@ struct ChatView: View {
|
||||
@AppStorage("composerSpellCheck") private var spellCheck = true
|
||||
@AppStorage("composerAutoCorrect") private var autoCorrect = false
|
||||
@AppStorage("studioChatSize") private var chatSize = 14
|
||||
@AppStorage("studioPalette") private var palette = StudioPalette.system
|
||||
@Environment(\.colorScheme) private var colorScheme
|
||||
@AppStorage("studioChatFont") private var chatFont = StudioFont.system
|
||||
@AppStorage("studioMode") private var mode = StudioMode.normal
|
||||
@State private var columns: NavigationSplitViewVisibility = .all
|
||||
@@ -124,6 +126,7 @@ struct ChatView: View {
|
||||
Divider()
|
||||
composer
|
||||
}
|
||||
.background(palette.surface(dark: colorScheme == .dark))
|
||||
.navigationTitle("AI Studio")
|
||||
.toolbar {
|
||||
Button("Documents", systemImage: "doc.on.doc") { showingLibrary = true }
|
||||
@@ -247,6 +250,18 @@ struct ChatView: View {
|
||||
Spacer()
|
||||
}
|
||||
.font(.caption)
|
||||
if studio.connectedKnowledge != nil {
|
||||
Toggle("Search connected knowledge index for this chat", isOn: $studio.useExternalKnowledge)
|
||||
.font(.caption).disabled(studio.running)
|
||||
}
|
||||
if !studio.knowledgeStatus.isEmpty {
|
||||
Label(studio.knowledgeStatus, systemImage: "books.vertical")
|
||||
.font(.caption).foregroundStyle(.secondary).textSelection(.enabled)
|
||||
}
|
||||
if !studio.webStatus.isEmpty {
|
||||
Label(studio.webStatus, systemImage: "globe")
|
||||
.font(.caption).foregroundStyle(.secondary).textSelection(.enabled)
|
||||
}
|
||||
ChatComposerInput(text: $studio.prompt, canSend: !studio.running, spellCheck: spellCheck,
|
||||
autoCorrect: autoCorrect, font: chatFont.appKit(size: chatSize), send: sendMessage)
|
||||
.frame(height: 62)
|
||||
@@ -279,6 +294,8 @@ struct ChatView: View {
|
||||
|
||||
struct MessageView: View {
|
||||
let message: Message
|
||||
@AppStorage("studioPalette") private var palette = StudioPalette.system
|
||||
@Environment(\.colorScheme) private var colorScheme
|
||||
var streaming = false
|
||||
|
||||
var body: some View {
|
||||
@@ -315,7 +332,7 @@ struct MessageView: View {
|
||||
}
|
||||
.frame(maxWidth: .infinity, alignment: .leading)
|
||||
.padding(14)
|
||||
.background(message.role == .user ? Color.accentColor.opacity(0.08) : Color.secondary.opacity(0.06),
|
||||
.background(palette.message(dark: colorScheme == .dark, user: message.role == .user),
|
||||
in: RoundedRectangle(cornerRadius: 12))
|
||||
}
|
||||
}
|
||||
@@ -335,7 +352,6 @@ struct BackendSettings: View {
|
||||
@State private var pickingFolder = false
|
||||
@State private var confirmRemoval = false
|
||||
@State private var folderError = ""
|
||||
@State private var modelsEndpoint = ""
|
||||
|
||||
var body: some View {
|
||||
Form {
|
||||
@@ -369,16 +385,25 @@ struct BackendSettings: View {
|
||||
TextField("Chat model", text: $model, prompt: Text("model:tag"))
|
||||
HStack {
|
||||
Button("Refresh Installed Models") {
|
||||
modelsEndpoint = endpoint
|
||||
studio.refresh(endpoint: endpoint)
|
||||
}
|
||||
.disabled(studio.managing)
|
||||
if studio.managing { Button("Cancel") { studio.cancelManagement() } }
|
||||
}
|
||||
if modelsEndpoint == endpoint, !studio.models.isEmpty {
|
||||
Menu("Installed Models") {
|
||||
ForEach(studio.models) { entry in
|
||||
Button(entry.name) { model = entry.name }
|
||||
if studio.modelListEndpoint == endpoint {
|
||||
ForEach(studio.models) { entry in
|
||||
HStack {
|
||||
Label(entry.name, systemImage: "cube")
|
||||
Spacer()
|
||||
if let size = entry.size {
|
||||
Text(ByteCountFormatter.string(fromByteCount: size, countStyle: .file))
|
||||
.foregroundStyle(.secondary).font(.caption)
|
||||
}
|
||||
Button(model == entry.name && !mlxOnly && !compatibleEnabled ? "Selected" : "Use Model") {
|
||||
model = entry.name
|
||||
mlxOnly = false
|
||||
compatibleEnabled = false
|
||||
}.disabled(model == entry.name && !mlxOnly && !compatibleEnabled)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -390,7 +415,6 @@ struct BackendSettings: View {
|
||||
HStack {
|
||||
TextField("Download model", text: $tag, prompt: Text("model:tag"))
|
||||
Button("Pull") {
|
||||
modelsEndpoint = endpoint
|
||||
studio.pull(tag, endpoint: endpoint)
|
||||
}
|
||||
.disabled(studio.managing || tag.trimmingCharacters(in: .whitespacesAndNewlines).isEmpty)
|
||||
@@ -410,6 +434,11 @@ struct BackendSettings: View {
|
||||
}
|
||||
}
|
||||
.formStyle(.grouped)
|
||||
.onAppear {
|
||||
if !mlxOnly && !compatibleEnabled && studio.modelListEndpoint != endpoint {
|
||||
studio.refresh(endpoint: endpoint)
|
||||
}
|
||||
}
|
||||
.frame(width: 590, height: 550)
|
||||
.fileImporter(isPresented: $pickingFolder, allowedContentTypes: [.folder]) { result in
|
||||
do {
|
||||
@@ -1161,6 +1190,7 @@ struct ChatComposerInput: NSViewRepresentable {
|
||||
struct ToolboxSheet: View {
|
||||
@Environment(\.dismiss) private var dismiss
|
||||
@ObservedObject var studio: StudioModel
|
||||
@State private var section = "servers"
|
||||
|
||||
var body: some View {
|
||||
VStack(spacing: 0) {
|
||||
@@ -1170,10 +1200,19 @@ struct ToolboxSheet: View {
|
||||
Button("Done") { dismiss() }
|
||||
}
|
||||
.padding()
|
||||
TabView {
|
||||
MCPSettings(studio: studio).tabItem { Label("MCP Servers", systemImage: "wrench.and.screwdriver") }
|
||||
Picker("Toolbox section", selection: $section) {
|
||||
Text("MCP Servers").tag("servers")
|
||||
Text("Web Search & Retrieval").tag("web")
|
||||
}
|
||||
.pickerStyle(.segmented)
|
||||
.labelsHidden()
|
||||
.frame(maxWidth: .infinity)
|
||||
.padding([.horizontal, .bottom])
|
||||
Divider()
|
||||
if section == "servers" {
|
||||
MCPSettings(studio: studio)
|
||||
} else {
|
||||
WebToolsView(studio: studio, done: { dismiss() })
|
||||
.tabItem { Label("Web", systemImage: "globe") }
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1211,6 +1250,7 @@ struct KnowledgeStacksView: View {
|
||||
@State private var selected: UUID?
|
||||
@State private var name = ""
|
||||
@State private var documents: [LibraryDocument] = []
|
||||
@State private var vectorCount = 0
|
||||
@State private var importing = false
|
||||
@State private var busy = false
|
||||
@State private var removing = false
|
||||
@@ -1238,6 +1278,7 @@ struct KnowledgeStacksView: View {
|
||||
}
|
||||
if let selected {
|
||||
Section("Indexed Documents") {
|
||||
LabeledContent("Local vector index", value: "\(vectorCount) embedded passages")
|
||||
ForEach(documents) { document in
|
||||
HStack {
|
||||
Text(document.title)
|
||||
@@ -1279,7 +1320,10 @@ struct KnowledgeStacksView: View {
|
||||
}
|
||||
}
|
||||
|
||||
private func refresh() { documents = selected.map(studio.stackDocuments) ?? [] }
|
||||
private func refresh() {
|
||||
documents = selected.map(studio.stackDocuments) ?? []
|
||||
vectorCount = selected.map(studio.stackVectorCount) ?? 0
|
||||
}
|
||||
}
|
||||
|
||||
struct WorkspaceSnippetsView: View {
|
||||
@@ -1489,6 +1533,7 @@ struct StudioSettingsView: View {
|
||||
struct StudioAppearanceView: View {
|
||||
@AppStorage("studioTheme") private var theme = StudioTheme.system
|
||||
@AppStorage("studioAccent") private var accent = StudioAccent.storm
|
||||
@AppStorage("studioPalette") private var palette = StudioPalette.system
|
||||
@AppStorage("studioMode") private var mode = StudioMode.normal
|
||||
@AppStorage("studioChatFont") private var font = StudioFont.system
|
||||
@AppStorage("studioChatSize") private var size = 14
|
||||
@@ -1506,6 +1551,9 @@ struct StudioAppearanceView: View {
|
||||
Picker("Workspace mode", selection: $mode) {
|
||||
ForEach(StudioMode.allCases) { Text($0.rawValue).tag($0) }
|
||||
}.pickerStyle(.segmented)
|
||||
Picker("Theme palette", selection: $palette) {
|
||||
ForEach(StudioPalette.allCases) { entry in Text(entry.rawValue).tag(entry) }
|
||||
}
|
||||
Picker("Accent", selection: $accent) {
|
||||
ForEach(StudioAccent.allCases) { entry in
|
||||
Label(entry.rawValue, systemImage: "circle.fill").foregroundStyle(entry.color).tag(entry)
|
||||
@@ -1708,3 +1756,39 @@ struct WebToolsView: View {
|
||||
done()
|
||||
}
|
||||
}
|
||||
|
||||
enum StudioPalette: String, CaseIterable, Identifiable {
|
||||
case system = "System", storm = "Storm", ash = "Ash", carbon = "Carbon", dusk = "Dusk"
|
||||
case sage = "Sage", ocean = "Ocean", linen = "Linen", ember = "Ember"
|
||||
|
||||
var id: Self { self }
|
||||
|
||||
private var hue: Double {
|
||||
switch self {
|
||||
case .system: 0
|
||||
case .storm: 0.61
|
||||
case .ash: 0.55
|
||||
case .carbon: 0.68
|
||||
case .dusk: 0.75
|
||||
case .sage: 0.30
|
||||
case .ocean: 0.48
|
||||
case .linen: 0.10
|
||||
case .ember: 0.045
|
||||
}
|
||||
}
|
||||
|
||||
private var saturation: Double {
|
||||
switch self { case .system, .carbon: 0; case .ash, .linen: 0.18; default: 0.36 }
|
||||
}
|
||||
|
||||
func surface(dark: Bool) -> Color {
|
||||
if self == .system { return Color(nsColor: .windowBackgroundColor) }
|
||||
return Color(hue: hue, saturation: dark ? saturation : saturation * 0.34, brightness: dark ? 0.135 : 0.98)
|
||||
}
|
||||
|
||||
func message(dark: Bool, user: Bool) -> Color {
|
||||
if self == .system { return user ? .accentColor.opacity(0.08) : .secondary.opacity(0.06) }
|
||||
return Color(hue: hue, saturation: saturation * (user ? 1.1 : 0.60),
|
||||
brightness: dark ? (user ? 0.24 : 0.19) : (user ? 0.93 : 0.96))
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user