mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-06 16:41:36 +00:00
agent: deliver via rpc and voice forward
This commit is contained in:
@@ -13,17 +13,25 @@ actor AgentRPC {
|
||||
|
||||
private struct RpcError: Error { let message: String }
|
||||
|
||||
func send(text: String, thinking: String?, session: String) async -> (ok: Bool, text: String?, error: String?) {
|
||||
func send(
|
||||
text: String,
|
||||
thinking: String?,
|
||||
session: String,
|
||||
deliver: Bool,
|
||||
to: String?) async -> (ok: Bool, text: String?, error: String?)
|
||||
{
|
||||
guard process?.isRunning == true else {
|
||||
return (false, nil, "rpc worker not running")
|
||||
}
|
||||
do {
|
||||
let payload: [String: Any] = [
|
||||
var payload: [String: Any] = [
|
||||
"type": "send",
|
||||
"text": text,
|
||||
"session": session,
|
||||
"thinking": thinking ?? "default",
|
||||
"deliver": deliver,
|
||||
]
|
||||
if let to { payload["to"] = to }
|
||||
let data = try JSONSerialization.data(withJSONObject: payload)
|
||||
guard let stdinHandle else { throw RpcError(message: "stdin missing") }
|
||||
stdinHandle.write(data)
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -72,14 +72,16 @@ final class ClawdisXPCService: NSObject, ClawdisXPCProtocol {
|
||||
}
|
||||
return await ShellRunner.run(command: command, cwd: cwd, env: env, timeout: timeoutSec)
|
||||
|
||||
case let .agent(message, thinking, session):
|
||||
case let .agent(message, thinking, session, deliver, to):
|
||||
let trimmed = message.trimmingCharacters(in: .whitespacesAndNewlines)
|
||||
guard !trimmed.isEmpty else { return Response(ok: false, message: "message empty") }
|
||||
let sessionKey = session ?? "main"
|
||||
let rpcResult = await AgentRPC.shared.send(
|
||||
text: trimmed,
|
||||
thinking: thinking,
|
||||
session: sessionKey)
|
||||
session: sessionKey,
|
||||
deliver: deliver,
|
||||
to: to)
|
||||
return rpcResult.ok
|
||||
? Response(ok: true, message: rpcResult.text ?? "sent")
|
||||
: Response(ok: false, message: rpcResult.error ?? "failed to send")
|
||||
@@ -89,12 +91,16 @@ final class ClawdisXPCService: NSObject, ClawdisXPCProtocol {
|
||||
private static func runAgentCLI(
|
||||
message: String,
|
||||
thinking: String?,
|
||||
session: String) async -> (ok: Bool, text: String?, error: String?)
|
||||
session: String,
|
||||
deliver: Bool,
|
||||
to: String?) async -> (ok: Bool, text: String?, error: String?)
|
||||
{
|
||||
let projectRoot = CommandResolver.projectRootPath()
|
||||
var command = CommandResolver.clawdisCommand(subcommand: "agent")
|
||||
command += ["--message", message, "--json"]
|
||||
if !session.isEmpty { command += ["--to", session] }
|
||||
if let to { command += ["--to", to] }
|
||||
if deliver { command += ["--deliver"] }
|
||||
if !session.isEmpty { command += ["--session-id", session] }
|
||||
if let thinking { command += ["--thinking", thinking] }
|
||||
|
||||
let process = Process()
|
||||
|
||||
Reference in New Issue
Block a user