Add editable themes and make web diagnostics visible

This commit is contained in:
Mark Gregory
2026-11-16 16:57:00 +00:00
parent de18d95741
commit 74c726e2d5
3 changed files with 175 additions and 21 deletions
+8 -7
View File
@@ -279,7 +279,8 @@ enum ChatWebLookup {
let text = message.trimmingCharacters(in: .whitespacesAndNewlines)
let prefixes = ["/search ", "can you search the web for ", "please search the web for ",
"search the web for ", "search online for ", "look up online ", "web search for ",
"find documentation for ", "find online ", "browse the web for "]
"find documentation for ", "find online ", "browse the web for ",
"can you look up ", "please look up ", "look up ", "search for "]
if let prefix = prefixes.first(where: { text.lowercased().hasPrefix($0) }) {
let query = String(text.dropFirst(prefix.count)).trimmingCharacters(in: .whitespacesAndNewlines)
if !query.isEmpty { self = .search(query); return }
@@ -319,15 +320,15 @@ enum ChatWebLookup {
failures.append(error.localizedDescription)
choices = []
}
if choices.isEmpty {
if failures.isEmpty { failures.append("No usable search results.") }
var browser = URLComponents(string: "https://duckduckgo.com/")
browser?.queryItems = [.init(name: "q", value: query)]
browserFallback = browser?.url
}
if choices.isEmpty && failures.isEmpty { failures.append("No usable search results.") }
}
let primary = try await Self.fetch(choices)
failures += primary.failures
if primary.pages.isEmpty, case .search(let query) = self {
var browser = URLComponents(string: "https://duckduckgo.com/")
browser?.queryItems = [.init(name: "q", value: query)]
browserFallback = browser?.url
}
var seen = Set(choices + primary.pages.map(\.url))
let terms = Set(LibraryImport.matchQuery(topic).components(separatedBy: " OR ")
.map { $0.trimmingCharacters(in: CharacterSet(charactersIn: "\"")) }.filter { !$0.isEmpty })