Add local file previews to chat and split the Toolbox layout

This commit is contained in:
Mark Gregory
2026-11-16 16:21:32 +00:00
parent 4ebf2b82be
commit 0f4b6b03e4
5 changed files with 107 additions and 15 deletions
+42 -2
View File
@@ -94,6 +94,9 @@ struct ChatView: View {
@State private var showingLibrary = false
@State private var useDocuments = false
@State private var filePreview: ChatFilePreview?
@State private var fileError = ""
var body: some View {
NavigationSplitView(columnVisibility: $columns) {
List(visibleChats, selection: $studio.selected) { chat in
@@ -142,8 +145,25 @@ struct ChatView: View {
.sheet(isPresented: $showingLibrary) { DocumentLibraryView(studio: studio) }
.sheet(isPresented: $showingPerformance) { PerformanceDashboard(studio: studio) }
.sheet(isPresented: $showingWorkspace) { WorkspaceResourcesView(studio: studio) }
.sheet(item: $filePreview) { preview in
VStack(alignment: .leading, spacing: 12) {
Text(preview.name).font(.headline)
ScrollView {
Text(preview.text).textSelection(.enabled)
.frame(maxWidth: .infinity, alignment: .leading)
}
HStack {
Spacer()
Button("Cancel") { filePreview = nil }.keyboardShortcut(.cancelAction)
Button("Attach to Next Message") {
studio.attachToolResult(name: preview.name, output: preview.text)
filePreview = nil
}.keyboardShortcut(.defaultAction)
}
}.padding().frame(width: 560, height: 360)
}
.sheet(isPresented: $showingToolbox) {
ToolboxSheet(studio: studio).frame(width: 650, height: 620)
ToolboxSheet(studio: studio).frame(width: 880, height: 620)
}
.sheet(isPresented: $showingPromptBuilder) {
PromptBuilder(customPrompt: $customPrompt) { instructions, global in
@@ -211,7 +231,7 @@ struct ChatView: View {
}
.font(.caption)
}
let activity = [studio.knowledgeStatus, studio.webStatus, studio.status].filter { !$0.isEmpty }
let activity = [fileError, studio.knowledgeStatus, studio.webStatus, studio.status].filter { !$0.isEmpty }
if !activity.isEmpty {
Text(activity.joined(separator: " · "))
.font(.caption).foregroundStyle(.secondary).lineLimit(2).textSelection(.enabled)
@@ -226,6 +246,9 @@ struct ChatView: View {
.background(.background, in: RoundedRectangle(cornerRadius: 8))
.overlay(RoundedRectangle(cornerRadius: 8).strokeBorder(.quaternary))
HStack {
Button("Attach Files", systemImage: "paperclip", action: pickLocalFile)
.labelStyle(.iconOnly).buttonStyle(.bordered)
.help("Attach a local file or folder listing").disabled(studio.running)
Button {
showingToolbox = true
} label: {
@@ -266,6 +289,23 @@ struct ChatView: View {
}
.padding(16)
}
private func pickLocalFile() {
let panel = NSOpenPanel()
panel.canChooseFiles = true
panel.canChooseDirectories = true
panel.allowsMultipleSelection = false
panel.prompt = "Preview"
panel.begin { response in
guard response == .OK, let url = panel.url else { return }
Task { @MainActor in
do {
filePreview = try await Task.detached { try ChatFilePreview.read(url) }.value
fileError = ""
} catch { fileError = error.localizedDescription }
}
}
}
private func sendMessage() {
studio.send(endpoint: activeEndpoint, model: activeModel, mlxPath: mlxPath, thinking: thinking,
failover: failover, mlxOnly: mlxOnly, compatible: compatibleEnabled, recall: recall, useDocuments: useDocuments,