Add custom MCP profiles and reusable workspace libraries

This commit is contained in:
Mark Gregory
2026-11-16 14:50:20 +00:00
parent bc2ae8ec02
commit 32c4b9f91c
12 changed files with 1398 additions and 76 deletions
+50
View File
@@ -1,5 +1,7 @@
import Foundation
import SwiftUI
import UniformTypeIdentifiers
import AppKit
struct CatalogModel: Identifiable, Hashable, Sendable {
let id: String
@@ -78,11 +80,40 @@ struct ModelCatalogView: View {
@AppStorage("mlxOnly") private var mlxOnly = false
@State private var operation: Task<Void, Never>?
@State private var active: CatalogModel?
@AppStorage("mlxRegisteredPaths") private var registered = Data()
@State private var pickingLibrary = false
@State private var libraryStatus = ""
private var library: [String] { (try? JSONDecoder().decode([String].self, from: registered)) ?? [] }
@State private var removing: CatalogModel?
@State private var status = ""
var body: some View {
Form {
Section("Model Library") {
Button("Register Model Folder…") { pickingLibrary = true }
.disabled(studio.running)
ForEach(library, id: \.self) { path in
HStack {
Text(URL(fileURLWithPath: path).lastPathComponent).help(path)
Spacer()
Button(mlxPath == path && mlxOnly ? "Selected" : "Use Model") {
mlxPath = path
mlxOnly = true
studio.unloadMLX()
}
.disabled(studio.running || !MLXLibrary.isModel(at: URL(fileURLWithPath: path)) ||
(mlxPath == path && mlxOnly))
Button("Reveal") {
NSWorkspace.shared.activateFileViewerSelecting([URL(fileURLWithPath: path)])
}
Button("Unregister") {
registered = (try? JSONEncoder().encode(library.filter { $0 != path })) ?? Data()
}.disabled(studio.running)
}
}
if !libraryStatus.isEmpty { Text(libraryStatus).foregroundStyle(.secondary) }
}
Section("Download for on-device inference") {
ForEach(CatalogModel.all) { model in
let installed = model.installed(at: model.localFolder)
@@ -122,6 +153,18 @@ struct ModelCatalogView: View {
}
}
.formStyle(.grouped)
.fileImporter(isPresented: $pickingLibrary, allowedContentTypes: [.folder]) { result in
do {
let url = try result.get().resolvingSymlinksInPath()
guard MLXLibrary.isModel(at: url) else {
throw StudioError("Choose an MLX folder with config.json and safetensors weights.")
}
if !library.contains(url.path) {
registered = try JSONEncoder().encode(library + [url.path])
}
libraryStatus = "Registered \(url.lastPathComponent)."
} catch { libraryStatus = error.localizedDescription }
}
.confirmationDialog("Remove downloaded model?", isPresented: Binding(
get: { removing != nil }, set: { if !$0 { removing = nil } }
), titleVisibility: .visible, presenting: removing) { model in
@@ -157,3 +200,10 @@ struct ModelCatalogView: View {
} catch { status = error.localizedDescription }
}
}
enum MLXLibrary {
static func isModel(at url: URL) -> Bool {
FileManager.default.fileExists(atPath: url.appending(path: "config.json").path) &&
((try? MLXRuntimeLimits.weightBytes(in: url)) ?? 0) > 0
}
}