mirror of
https://github.com/hanzoai/bot.git
synced 2026-10-30 17:24:26 +00:00
Complete rename of all OpenClaw/OPENCLAW/openclaw references to Hanzo Bot/BOT/bot naming convention: - Env vars: OPENCLAW_* → BOT_* (18 patterns) - Config: ~/.openclaw/ → ~/.bot/, openclaw.json → bot.json - Packages: @openclaw/* → @hanzo/bot-* - Domains: openclaw.ai → hanzo.bot - Mobile: OpenClawKit → BotKit, bundle IDs ai.openclaw → ai.hanzo.bot - mDNS: _openclaw-gw._tcp → _bot-gw._tcp - Docker: CMD hanzo-bot.mjs, BOT_PREFER_PNPM, BOT_DOCKER_APT_PACKAGES - CI: docker-release.yml adds :latest tag on main branch
74 lines
2.5 KiB
Swift
74 lines
2.5 KiB
Swift
import Foundation
|
|
import OSLog
|
|
|
|
enum VoiceWakeForwarder {
|
|
private static let logger = Logger(subsystem: "ai.hanzo.bot", category: "voicewake.forward")
|
|
|
|
static func prefixedTranscript(_ transcript: String, machineName: String? = nil) -> String {
|
|
let resolvedMachine = machineName
|
|
.flatMap { name -> String? in
|
|
let trimmed = name.trimmingCharacters(in: .whitespacesAndNewlines)
|
|
return trimmed.isEmpty ? nil : trimmed
|
|
}
|
|
?? Host.current().localizedName
|
|
?? ProcessInfo.processInfo.hostName
|
|
|
|
let safeMachine = resolvedMachine.isEmpty ? "this Mac" : resolvedMachine
|
|
return """
|
|
User talked via voice recognition on \(safeMachine) - repeat prompt first \
|
|
+ remember some words might be incorrectly transcribed.
|
|
|
|
\(transcript)
|
|
"""
|
|
}
|
|
|
|
enum VoiceWakeForwardError: LocalizedError, Equatable {
|
|
case rpcFailed(String)
|
|
|
|
var errorDescription: String? {
|
|
switch self {
|
|
case let .rpcFailed(message): message
|
|
}
|
|
}
|
|
}
|
|
|
|
struct ForwardOptions: Sendable {
|
|
var sessionKey: String = "main"
|
|
var thinking: String = "low"
|
|
var deliver: Bool = true
|
|
var to: String?
|
|
var channel: GatewayAgentChannel = .last
|
|
}
|
|
|
|
@discardableResult
|
|
static func forward(
|
|
transcript: String,
|
|
options: ForwardOptions = ForwardOptions()) async -> Result<Void, VoiceWakeForwardError>
|
|
{
|
|
let payload = Self.prefixedTranscript(transcript)
|
|
let deliver = options.channel.shouldDeliver(options.deliver)
|
|
let result = await GatewayConnection.shared.sendAgent(GatewayAgentInvocation(
|
|
message: payload,
|
|
sessionKey: options.sessionKey,
|
|
thinking: options.thinking,
|
|
deliver: deliver,
|
|
to: options.to,
|
|
channel: options.channel))
|
|
|
|
if result.ok {
|
|
self.logger.info("voice wake forward ok")
|
|
return .success(())
|
|
}
|
|
|
|
let message = result.error ?? "agent rpc unavailable"
|
|
self.logger.error("voice wake forward failed: \(message, privacy: .public)")
|
|
return .failure(.rpcFailed(message))
|
|
}
|
|
|
|
static func checkConnection() async -> Result<Void, VoiceWakeForwardError> {
|
|
let status = await GatewayConnection.shared.status()
|
|
if status.ok { return .success(()) }
|
|
return .failure(.rpcFailed(status.error ?? "agent rpc unreachable"))
|
|
}
|
|
}
|