fix: auto-start rpc worker for agent calls

This commit is contained in:
Peter Steinberger
2025-12-07 05:54:15 +01:00
parent 093e737af9
commit e70f8471a8
2 changed files with 15 additions and 5 deletions

View File

@@ -14,8 +14,10 @@ actor AgentRPC {
private struct RpcError: Error { let message: String }
func send(text: String, thinking: String?, session: String) async -> (ok: Bool, text: String?, error: String?) {
guard process?.isRunning == true else {
return (false, nil, "rpc worker not running")
if process?.isRunning != true {
do { try await ensureRunning() } catch {
return (false, nil, "rpc worker not running")
}
}
do {
let payload: [String: Any] = [
@@ -23,6 +25,7 @@ actor AgentRPC {
"text": text,
"session": session,
"thinking": thinking ?? "default",
"deliver": true,
]
let data = try JSONSerialization.data(withJSONObject: payload)
guard let stdinHandle else { throw RpcError(message: "stdin missing") }
@@ -56,8 +59,10 @@ actor AgentRPC {
}
func status() async -> (ok: Bool, error: String?) {
guard process?.isRunning == true else {
return (false, "rpc worker not running")
if process?.isRunning != true {
do { try await ensureRunning() } catch {
return (false, "rpc worker not running")
}
}
do {
let payload: [String: Any] = ["type": "status"]
@@ -114,6 +119,11 @@ actor AgentRPC {
}
}
private func ensureRunning() async throws {
if let process, process.isRunning { return }
try await start()
}
private func stop() async {
stdoutHandle?.readabilityHandler = nil
process?.terminate()

View File

@@ -24,7 +24,7 @@ let modelCatalogPathKey = "clawdis.modelCatalogPath"
let modelCatalogReloadKey = "clawdis.modelCatalogReload"
let voiceWakeSupported: Bool = ProcessInfo.processInfo.operatingSystemVersion.majorVersion >= 26
let cliHelperSearchPaths = ["/usr/local/bin", "/opt/homebrew/bin"]
let defaultVoiceWakeForwardCommand = "clawdis-mac agent --message \"${text}\" --thinking low"
let defaultVoiceWakeForwardCommand = "clawdis-mac agent --message \"${text}\" --thinking low --session main --deliver"
let defaultVoiceWakeForwardPort = 22
// Allow enough time for remote agent responses (LLM replies often take >10s).
let defaultVoiceWakeForwardTimeout: TimeInterval = 30