chore: format wake gate + chat theme

main
Peter Steinberger 2025-12-23 01:41:13 +01:00
parent abfb6832c3
commit 926b6d9464
2 changed files with 15 additions and 15 deletions

View File

@ -13,7 +13,7 @@ public struct WakeWordSegment: Sendable, Equatable {
self.range = range self.range = range
} }
public var end: TimeInterval { start + duration } public var end: TimeInterval { self.start + self.duration }
} }
public struct WakeWordGateConfig: Sendable, Equatable { public struct WakeWordGateConfig: Sendable, Equatable {
@ -62,10 +62,10 @@ public enum WakeWordGate {
segments: [WakeWordSegment], segments: [WakeWordSegment],
config: WakeWordGateConfig) config: WakeWordGateConfig)
-> WakeWordGateMatch? { -> WakeWordGateMatch? {
let triggerTokens = normalizeTriggers(config.triggers) let triggerTokens = self.normalizeTriggers(config.triggers)
guard !triggerTokens.isEmpty else { return nil } guard !triggerTokens.isEmpty else { return nil }
let tokens = normalizeSegments(segments) let tokens = self.normalizeSegments(segments)
guard !tokens.isEmpty else { return nil } guard !tokens.isEmpty else { return nil }
var bestIndex: Int? var bestIndex: Int?
@ -99,7 +99,7 @@ public enum WakeWordGate {
} }
guard let bestIndex else { return nil } guard let bestIndex else { return nil }
let command = commandText(transcript: transcript, segments: segments, triggerEndTime: bestTriggerEnd) let command = self.commandText(transcript: transcript, segments: segments, triggerEndTime: bestTriggerEnd)
.trimmingCharacters(in: Self.whitespaceAndPunctuation) .trimmingCharacters(in: Self.whitespaceAndPunctuation)
guard command.count >= config.minCommandLength else { return nil } guard command.count >= config.minCommandLength else { return nil }
return WakeWordGateMatch(triggerEndTime: bestTriggerEnd, postGap: bestGap, command: command) return WakeWordGateMatch(triggerEndTime: bestTriggerEnd, postGap: bestGap, command: command)
@ -121,8 +121,8 @@ public enum WakeWordGate {
} }
let text = segments let text = segments
.filter { $0.start >= threshold && !normalizeToken($0.text).isEmpty } .filter { $0.start >= threshold && !self.normalizeToken($0.text).isEmpty }
.map { $0.text } .map(\.text)
.joined(separator: " ") .joined(separator: " ")
return text.trimmingCharacters(in: Self.whitespaceAndPunctuation) return text.trimmingCharacters(in: Self.whitespaceAndPunctuation)
} }
@ -131,7 +131,7 @@ public enum WakeWordGate {
guard !text.isEmpty else { return false } guard !text.isEmpty else { return false }
let normalized = text.lowercased() let normalized = text.lowercased()
for trigger in triggers { for trigger in triggers {
let token = trigger.trimmingCharacters(in: whitespaceAndPunctuation).lowercased() let token = trigger.trimmingCharacters(in: self.whitespaceAndPunctuation).lowercased()
if token.isEmpty { continue } if token.isEmpty { continue }
if normalized.contains(token) { return true } if normalized.contains(token) { return true }
} }
@ -141,11 +141,11 @@ public enum WakeWordGate {
public static func stripWake(text: String, triggers: [String]) -> String { public static func stripWake(text: String, triggers: [String]) -> String {
var out = text var out = text
for trigger in triggers { for trigger in triggers {
let token = trigger.trimmingCharacters(in: whitespaceAndPunctuation) let token = trigger.trimmingCharacters(in: self.whitespaceAndPunctuation)
guard !token.isEmpty else { continue } guard !token.isEmpty else { continue }
out = out.replacingOccurrences(of: token, with: "", options: [.caseInsensitive]) out = out.replacingOccurrences(of: token, with: "", options: [.caseInsensitive])
} }
return out.trimmingCharacters(in: whitespaceAndPunctuation) return out.trimmingCharacters(in: self.whitespaceAndPunctuation)
} }
private static func normalizeTriggers(_ triggers: [String]) -> [TriggerTokens] { private static func normalizeTriggers(_ triggers: [String]) -> [TriggerTokens] {
@ -153,7 +153,7 @@ public enum WakeWordGate {
for trigger in triggers { for trigger in triggers {
let tokens = trigger let tokens = trigger
.split(whereSeparator: { $0.isWhitespace }) .split(whereSeparator: { $0.isWhitespace })
.map { normalizeToken(String($0)) } .map { self.normalizeToken(String($0)) }
.filter { !$0.isEmpty } .filter { !$0.isEmpty }
if tokens.isEmpty { continue } if tokens.isEmpty { continue }
output.append(TriggerTokens(tokens: tokens)) output.append(TriggerTokens(tokens: tokens))
@ -163,7 +163,7 @@ public enum WakeWordGate {
private static func normalizeSegments(_ segments: [WakeWordSegment]) -> [Token] { private static func normalizeSegments(_ segments: [WakeWordSegment]) -> [Token] {
segments.compactMap { segment in segments.compactMap { segment in
let normalized = normalizeToken(segment.text) let normalized = self.normalizeToken(segment.text)
guard !normalized.isEmpty else { return nil } guard !normalized.isEmpty else { return nil }
return Token( return Token(
normalized: normalized, normalized: normalized,
@ -176,7 +176,7 @@ public enum WakeWordGate {
private static func normalizeToken(_ token: String) -> String { private static func normalizeToken(_ token: String) -> String {
token token
.trimmingCharacters(in: whitespaceAndPunctuation) .trimmingCharacters(in: self.whitespaceAndPunctuation)
.lowercased() .lowercased()
} }

View File

@ -22,14 +22,14 @@ enum ClawdisChatTheme {
LinearGradient( LinearGradient(
colors: [ colors: [
Color(nsColor: .windowBackgroundColor).opacity(0.85), Color(nsColor: .windowBackgroundColor).opacity(0.85),
Color.black.opacity(0.92) Color.black.opacity(0.92),
], ],
startPoint: .topLeading, startPoint: .topLeading,
endPoint: .bottomTrailing) endPoint: .bottomTrailing)
RadialGradient( RadialGradient(
colors: [ colors: [
Color(nsColor: .systemOrange).opacity(0.18), Color(nsColor: .systemOrange).opacity(0.18),
.clear .clear,
], ],
center: .topLeading, center: .topLeading,
startRadius: 40, startRadius: 40,
@ -37,7 +37,7 @@ enum ClawdisChatTheme {
RadialGradient( RadialGradient(
colors: [ colors: [
Color(nsColor: .systemTeal).opacity(0.16), Color(nsColor: .systemTeal).opacity(0.16),
.clear .clear,
], ],
center: .topTrailing, center: .topTrailing,
startRadius: 40, startRadius: 40,