new features
This commit is contained in:
@@ -205,6 +205,7 @@ struct ChatView: View {
|
||||
@AppStorage("chatFileAccessFolder") private var chatFileScope = ""
|
||||
@AppStorage("chatFileWriteEnabled") private var chatFileWriteEnabled = false
|
||||
@State private var filePreview: ChatFilePreview?
|
||||
@State private var preparingFilePreview = false
|
||||
@State private var fileError = ""
|
||||
|
||||
var body: some View {
|
||||
@@ -289,14 +290,24 @@ struct ChatView: View {
|
||||
VStack(alignment: .leading, spacing: 12) {
|
||||
Text(preview.name).font(.headline)
|
||||
ScrollView {
|
||||
Text(preview.text).textSelection(.enabled)
|
||||
.frame(maxWidth: .infinity, alignment: .leading)
|
||||
if let data = preview.imagePNG, let image = NSImage(data: data) {
|
||||
Image(nsImage: image).resizable().scaledToFit()
|
||||
.frame(maxWidth: 520, maxHeight: 260)
|
||||
.accessibilityLabel("Attachment preview")
|
||||
}
|
||||
if preview.imagePNG == nil || chatModel.backend == .mlx {
|
||||
Text(preview.text.isEmpty && preview.imagePNG != nil
|
||||
? "No readable text detected. Choose a vision-capable model to analyze this image."
|
||||
: 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, isDocument: true)
|
||||
studio.attachToolResult(name: preview.name, output: preview.text,
|
||||
isDocument: true, isPDF: preview.isPDF, imagePNG: preview.imagePNG)
|
||||
filePreview = nil
|
||||
}.keyboardShortcut(.defaultAction)
|
||||
}
|
||||
@@ -465,14 +476,18 @@ struct ChatView: View {
|
||||
}
|
||||
if let attachment = studio.toolAttachment {
|
||||
HStack {
|
||||
Label("Attach \(attachment.name) result to next message", systemImage: "paperclip")
|
||||
Label("\(attachment.name) attached to next message", systemImage: "paperclip")
|
||||
if attachment.imagePNG != nil && chatModel.backend == .mlx {
|
||||
Text("Extracted text only").foregroundStyle(.secondary)
|
||||
}
|
||||
if chatModel.backend != .mlx { Text("Sent to \(backendName)").foregroundStyle(.secondary) }
|
||||
Spacer()
|
||||
Button("Remove", systemImage: "xmark.circle") { studio.removeToolAttachment() }
|
||||
}
|
||||
.font(.caption)
|
||||
}
|
||||
let activity = [fileError, showDebugOutput ? "" : studio.webStatus, studio.status].filter { !$0.isEmpty }
|
||||
let activity = [preparingFilePreview ? "Preparing attachment preview…" : fileError,
|
||||
showDebugOutput ? "" : studio.webStatus, studio.status].filter { !$0.isEmpty }
|
||||
if !activity.isEmpty {
|
||||
Text(activity.joined(separator: " · "))
|
||||
.font(.caption).foregroundStyle(.secondary).lineLimit(2).textSelection(.enabled)
|
||||
@@ -496,7 +511,8 @@ struct ChatView: View {
|
||||
.fixedSize()
|
||||
Button("Attach Files", systemImage: "paperclip", action: pickLocalFile)
|
||||
.labelStyle(.iconOnly).buttonStyle(.bordered)
|
||||
.help("Attach a local file or folder listing").disabled(studio.running)
|
||||
.help("Attach an image, PDF, text file, or folder listing")
|
||||
.disabled(studio.running || preparingFilePreview)
|
||||
Button("Web Search", systemImage: "magnifyingglass") {
|
||||
toolboxSection = .search
|
||||
showingToolbox = true
|
||||
@@ -565,9 +581,14 @@ struct ChatView: View {
|
||||
panel.begin { response in
|
||||
guard response == .OK, let url = panel.url else { return }
|
||||
Task { @MainActor in
|
||||
let conversation = studio.selected
|
||||
preparingFilePreview = true
|
||||
fileError = ""
|
||||
defer { preparingFilePreview = false }
|
||||
do {
|
||||
filePreview = try await Task.detached { try ChatFilePreview.read(url) }.value
|
||||
fileError = ""
|
||||
let preview = try await Task.detached { try ChatFilePreview.read(url) }.value
|
||||
guard studio.selected == conversation, !studio.running else { return }
|
||||
filePreview = preview
|
||||
} catch { fileError = error.localizedDescription }
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user