Added skills, shortcuts, and bugifixes++
This commit is contained in:
@@ -23,6 +23,7 @@ class SettingsService {
|
||||
static let openaiAPIKey = "openaiAPIKey"
|
||||
static let googleAPIKey = "googleAPIKey"
|
||||
static let googleSearchEngineID = "googleSearchEngineID"
|
||||
static let anytypeMcpAPIKey = "anytypeMcpAPIKey"
|
||||
}
|
||||
|
||||
// Old keychain keys (for migration only)
|
||||
@@ -313,6 +314,120 @@ class SettingsService {
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - User Shortcuts (prompt template macros)
|
||||
|
||||
var userShortcuts: [Shortcut] {
|
||||
get {
|
||||
guard let json = cache["userShortcuts"],
|
||||
let data = json.data(using: .utf8) else { return [] }
|
||||
let decoder = JSONDecoder()
|
||||
decoder.dateDecodingStrategy = .iso8601
|
||||
return (try? decoder.decode([Shortcut].self, from: data)) ?? []
|
||||
}
|
||||
set {
|
||||
let encoder = JSONEncoder()
|
||||
encoder.dateEncodingStrategy = .iso8601
|
||||
if let data = try? encoder.encode(newValue),
|
||||
let json = String(data: data, encoding: .utf8) {
|
||||
cache["userShortcuts"] = json
|
||||
DatabaseService.shared.setSetting(key: "userShortcuts", value: json)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func addShortcut(_ shortcut: Shortcut) { userShortcuts = userShortcuts + [shortcut] }
|
||||
|
||||
func updateShortcut(_ shortcut: Shortcut) {
|
||||
userShortcuts = userShortcuts.map { $0.id == shortcut.id ? shortcut : $0 }
|
||||
}
|
||||
|
||||
func deleteShortcut(id: UUID) { userShortcuts = userShortcuts.filter { $0.id != id } }
|
||||
|
||||
// MARK: - Agent Skills (SKILL.md-style behavioral instructions)
|
||||
|
||||
var agentSkills: [AgentSkill] {
|
||||
get {
|
||||
guard let json = cache["agentSkills"],
|
||||
let data = json.data(using: .utf8) else { return [] }
|
||||
let decoder = JSONDecoder()
|
||||
decoder.dateDecodingStrategy = .iso8601
|
||||
return (try? decoder.decode([AgentSkill].self, from: data)) ?? []
|
||||
}
|
||||
set {
|
||||
let encoder = JSONEncoder()
|
||||
encoder.dateEncodingStrategy = .iso8601
|
||||
if let data = try? encoder.encode(newValue),
|
||||
let json = String(data: data, encoding: .utf8) {
|
||||
cache["agentSkills"] = json
|
||||
DatabaseService.shared.setSetting(key: "agentSkills", value: json)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func addAgentSkill(_ skill: AgentSkill) { agentSkills = agentSkills + [skill] }
|
||||
|
||||
func updateAgentSkill(_ skill: AgentSkill) {
|
||||
agentSkills = agentSkills.map { $0.id == skill.id ? skill : $0 }
|
||||
}
|
||||
|
||||
func deleteAgentSkill(id: UUID) {
|
||||
agentSkills = agentSkills.filter { $0.id != id }
|
||||
AgentSkillFilesService.shared.deleteAll(for: id)
|
||||
}
|
||||
|
||||
func toggleAgentSkill(id: UUID) {
|
||||
agentSkills = agentSkills.map { s in
|
||||
s.id == id ? AgentSkill(id: s.id, name: s.name, skillDescription: s.skillDescription,
|
||||
content: s.content, isActive: !s.isActive,
|
||||
createdAt: s.createdAt, updatedAt: Date()) : s
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - Anytype MCP Settings
|
||||
|
||||
var anytypeMcpEnabled: Bool {
|
||||
get { cache["anytypeMcpEnabled"] == "true" }
|
||||
set {
|
||||
cache["anytypeMcpEnabled"] = String(newValue)
|
||||
DatabaseService.shared.setSetting(key: "anytypeMcpEnabled", value: String(newValue))
|
||||
}
|
||||
}
|
||||
|
||||
var anytypeMcpURL: String {
|
||||
get { cache["anytypeMcpURL"] ?? "" }
|
||||
set {
|
||||
let trimmed = newValue.trimmingCharacters(in: .whitespaces)
|
||||
if trimmed.isEmpty {
|
||||
cache.removeValue(forKey: "anytypeMcpURL")
|
||||
DatabaseService.shared.deleteSetting(key: "anytypeMcpURL")
|
||||
} else {
|
||||
cache["anytypeMcpURL"] = trimmed
|
||||
DatabaseService.shared.setSetting(key: "anytypeMcpURL", value: trimmed)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var anytypeMcpEffectiveURL: String {
|
||||
let url = anytypeMcpURL
|
||||
return url.isEmpty ? "http://127.0.0.1:31009" : url
|
||||
}
|
||||
|
||||
var anytypeMcpAPIKey: String? {
|
||||
get { try? DatabaseService.shared.getEncryptedSetting(key: EncryptedKeys.anytypeMcpAPIKey) }
|
||||
set {
|
||||
if let value = newValue, !value.isEmpty {
|
||||
try? DatabaseService.shared.setEncryptedSetting(key: EncryptedKeys.anytypeMcpAPIKey, value: value)
|
||||
} else {
|
||||
DatabaseService.shared.deleteEncryptedSetting(key: EncryptedKeys.anytypeMcpAPIKey)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var anytypeMcpConfigured: Bool {
|
||||
guard let key = anytypeMcpAPIKey else { return false }
|
||||
return !key.isEmpty
|
||||
}
|
||||
|
||||
// MARK: - Search Settings
|
||||
|
||||
var searchProvider: Settings.SearchProvider {
|
||||
|
||||
Reference in New Issue
Block a user