Complete workspace recovery, migration, and compatibility checks
This commit is contained in:
@@ -84,6 +84,10 @@ final class StudioModel: ObservableObject {
|
||||
catch { status = error.localizedDescription }
|
||||
}
|
||||
|
||||
func conversationMessages(_ id: UUID) -> [Message] {
|
||||
(try? store?.messages(in: id)) ?? []
|
||||
}
|
||||
|
||||
func searchConversations(_ term: String) -> [Conversation] {
|
||||
(try? store?.searchConversations(term)) ?? []
|
||||
}
|
||||
@@ -341,7 +345,29 @@ final class StudioModel: ObservableObject {
|
||||
}
|
||||
|
||||
static var workspaceDirectory: URL {
|
||||
URL.applicationSupportDirectory.appending(path: "AIStudio", directoryHint: .isDirectory)
|
||||
if let path = UserDefaults.standard.string(forKey: "workspaceLocation"), !path.isEmpty {
|
||||
return URL(fileURLWithPath: path, isDirectory: true)
|
||||
}
|
||||
return URL.applicationSupportDirectory.appending(path: "AIStudio", directoryHint: .isDirectory)
|
||||
}
|
||||
|
||||
func relocateWorkspace(to folder: URL, defaults: UserDefaults = .standard) throws {
|
||||
guard !running, !importingDocument else { throw StudioError("Wait for the current operation to finish.") }
|
||||
let url = folder.appending(path: "studio.sqlite")
|
||||
try database().exportWorkspace(to: url)
|
||||
let relocated = try Store(url: url)
|
||||
_ = try relocated.conversations()
|
||||
store = relocated
|
||||
defaults.set(folder.path, forKey: "workspaceLocation")
|
||||
try refreshWorkspace()
|
||||
}
|
||||
|
||||
func importMstyChats(from url: URL) throws -> Int {
|
||||
guard !running, !importingDocument else { throw StudioError("Wait for the current operation to finish.") }
|
||||
let count = try database().importMstyChats(from: url)
|
||||
conversations = try database().conversations()
|
||||
if selected == nil { selected = conversations.first?.id }
|
||||
return count
|
||||
}
|
||||
|
||||
func exportWorkspace(to url: URL) throws {
|
||||
@@ -412,9 +438,22 @@ final class StudioModel: ObservableObject {
|
||||
} catch { workspaceStatus = error.localizedDescription }
|
||||
}
|
||||
|
||||
func saveSnippet(id: UUID, kind: WorkspaceSnippet.Kind, title: String, content: String) {
|
||||
func promptVersions(_ id: UUID) -> [PromptVersion] {
|
||||
(try? database().promptVersions(id)) ?? []
|
||||
}
|
||||
|
||||
func saveSnippet(id: UUID, kind: WorkspaceSnippet.Kind, title: String, content: String,
|
||||
notes: String = "", tags: String = "") {
|
||||
do {
|
||||
try database().saveSnippet(id: id, kind: kind, title: String(title.prefix(100)), content: String(content.prefix(12000)))
|
||||
let store = try database()
|
||||
let title = String(title.prefix(100))
|
||||
let content = String(content.prefix(12000))
|
||||
if kind == .prompt {
|
||||
try store.savePrompt(id: id, title: title, content: content,
|
||||
notes: String(notes.prefix(1000)), tags: String(tags.prefix(250)))
|
||||
} else {
|
||||
try store.saveSnippet(id: id, kind: kind, title: title, content: content)
|
||||
}
|
||||
try refreshWorkspace()
|
||||
workspaceStatus = ""
|
||||
} catch { workspaceStatus = error.localizedDescription }
|
||||
|
||||
Reference in New Issue
Block a user