refactor(#2569): rename hive-agent-sock to hive-core-agent-sock
This commit is contained in:
parent
84b750fba5
commit
795dd882bb
26 changed files with 184 additions and 161 deletions
|
|
@ -121,9 +121,10 @@ impl AgentServer {
|
|||
/// covers both.
|
||||
async fn dispatch(
|
||||
&self,
|
||||
req: hive_agent_sock::Request,
|
||||
) -> (Result<hive_agent_sock::Response, anyhow::Error>, u32) {
|
||||
match client::request_retried::<_, hive_agent_sock::Response>(&self.socket, &req).await {
|
||||
req: hive_core_agent_sock::Request,
|
||||
) -> (Result<hive_core_agent_sock::Response, anyhow::Error>, u32) {
|
||||
match client::request_retried::<_, hive_core_agent_sock::Response>(&self.socket, &req).await
|
||||
{
|
||||
Ok((r, n)) => (Ok(r), n),
|
||||
Err(e) => (Err(e), 0),
|
||||
}
|
||||
|
|
@ -150,7 +151,7 @@ impl AgentServer {
|
|||
}
|
||||
run_tool_envelope("send", log, async move {
|
||||
let (resp, retries) = self
|
||||
.dispatch(hive_agent_sock::Request::Send {
|
||||
.dispatch(hive_core_agent_sock::Request::Send {
|
||||
to: args.to,
|
||||
body: args.body,
|
||||
in_reply_to: args.in_reply_to,
|
||||
|
|
@ -181,7 +182,7 @@ impl AgentServer {
|
|||
let log = format!("{args:?}");
|
||||
run_tool_envelope("ask", log, async move {
|
||||
let (resp, retries) = self
|
||||
.dispatch(hive_agent_sock::Request::Ask {
|
||||
.dispatch(hive_core_agent_sock::Request::Ask {
|
||||
question: args.question,
|
||||
options: args.options,
|
||||
multi: args.multi,
|
||||
|
|
@ -190,7 +191,7 @@ impl AgentServer {
|
|||
})
|
||||
.await;
|
||||
let s = match resp {
|
||||
Ok(hive_agent_sock::Response::QuestionQueued { id }) => format!(
|
||||
Ok(hive_core_agent_sock::Response::QuestionQueued { id }) => format!(
|
||||
"question queued (id={id}); answer will arrive as a system \
|
||||
`question_answered` event in your inbox"
|
||||
),
|
||||
|
|
@ -215,7 +216,7 @@ impl AgentServer {
|
|||
let id = args.id;
|
||||
run_tool_envelope("answer", log, async move {
|
||||
let (resp, retries) = self
|
||||
.dispatch(hive_agent_sock::Request::Answer {
|
||||
.dispatch(hive_core_agent_sock::Request::Answer {
|
||||
id,
|
||||
answer: args.answer,
|
||||
})
|
||||
|
|
@ -253,7 +254,7 @@ impl AgentServer {
|
|||
run_tool_envelope("recv", log, async move {
|
||||
let waited = args.wait_seconds.is_some_and(|w| w > 0);
|
||||
let (resp, retries) = self
|
||||
.dispatch(hive_agent_sock::Request::Recv {
|
||||
.dispatch(hive_core_agent_sock::Request::Recv {
|
||||
wait_seconds: args.wait_seconds,
|
||||
max: args.max,
|
||||
})
|
||||
|
|
@ -278,10 +279,10 @@ impl AgentServer {
|
|||
let log = format!("{args:?}");
|
||||
run_tool_envelope("ack_until", log, async move {
|
||||
let (resp, retries) = self
|
||||
.dispatch(hive_agent_sock::Request::AckUntil { up_to: args.up_to })
|
||||
.dispatch(hive_core_agent_sock::Request::AckUntil { up_to: args.up_to })
|
||||
.await;
|
||||
let rendered = match resp {
|
||||
Ok(hive_agent_sock::Response::Acked { count }) => {
|
||||
Ok(hive_core_agent_sock::Response::Acked { count }) => {
|
||||
format!("acked {count} message(s) up to id {}", args.up_to)
|
||||
}
|
||||
other => reply_err(other, "ack_until"),
|
||||
|
|
@ -310,11 +311,11 @@ impl AgentServer {
|
|||
run_tool_envelope("get_loose_ends", String::new(), async move {
|
||||
let is_self_query = args.agent.is_none();
|
||||
let (resp, retries) = self
|
||||
.dispatch(hive_agent_sock::Request::GetLooseEnds { agent: args.agent })
|
||||
.dispatch(hive_core_agent_sock::Request::GetLooseEnds { agent: args.agent })
|
||||
.await;
|
||||
// Extract the vec so we can augment before rendering.
|
||||
let mut loose_ends = match resp {
|
||||
Ok(hive_agent_sock::Response::LooseEnds { loose_ends }) => loose_ends,
|
||||
Ok(hive_core_agent_sock::Response::LooseEnds { loose_ends }) => loose_ends,
|
||||
other => return annotate_retries(reply_err(other, "get_loose_ends"), retries),
|
||||
};
|
||||
// Prepend matrix unread entry for self-queries only (can't
|
||||
|
|
@ -363,7 +364,7 @@ impl AgentServer {
|
|||
return e;
|
||||
}
|
||||
let (resp, retries) = self
|
||||
.dispatch(hive_agent_sock::Request::SetStatus { text: args.text })
|
||||
.dispatch(hive_core_agent_sock::Request::SetStatus { text: args.text })
|
||||
.await;
|
||||
annotate_retries(
|
||||
format_ack(resp, "set_status", "status updated".to_owned()),
|
||||
|
|
@ -395,7 +396,7 @@ impl AgentServer {
|
|||
let log = args.name.clone().unwrap_or_else(|| "<self>".to_owned());
|
||||
run_tool_envelope("get_agent_meta", log, async move {
|
||||
let (resp, retries) = self
|
||||
.dispatch(hive_agent_sock::Request::GetAgentMeta { name: args.name })
|
||||
.dispatch(hive_core_agent_sock::Request::GetAgentMeta { name: args.name })
|
||||
.await;
|
||||
annotate_retries(format_agent_meta(resp), retries)
|
||||
})
|
||||
|
|
@ -423,7 +424,7 @@ impl AgentServer {
|
|||
};
|
||||
let kind_label = loose_end_kind_label(kind);
|
||||
let (resp, retries) = self
|
||||
.dispatch(hive_agent_sock::Request::CancelLooseEnd { kind, id })
|
||||
.dispatch(hive_core_agent_sock::Request::CancelLooseEnd { kind, id })
|
||||
.await;
|
||||
annotate_retries(
|
||||
format_ack(
|
||||
|
|
@ -450,10 +451,10 @@ impl AgentServer {
|
|||
let log = format!("{args:?}");
|
||||
run_tool_envelope("create_repo", log, async move {
|
||||
let (resp, retries) = self
|
||||
.dispatch(hive_agent_sock::Request::CreateRepo { repo: args.repo })
|
||||
.dispatch(hive_core_agent_sock::Request::CreateRepo { repo: args.repo })
|
||||
.await;
|
||||
let s = match resp {
|
||||
Ok(hive_agent_sock::Response::RepoCreated {
|
||||
Ok(hive_core_agent_sock::Response::RepoCreated {
|
||||
full_name,
|
||||
clone_url,
|
||||
}) => format!("created repo {full_name} — clone: {clone_url}"),
|
||||
|
|
@ -493,7 +494,7 @@ impl AgentServer {
|
|||
(None, Some(t)) => hive_sh4re::ReminderTiming::At { unix_timestamp: t },
|
||||
};
|
||||
let (resp, retries) = self
|
||||
.dispatch(hive_agent_sock::Request::Remind {
|
||||
.dispatch(hive_core_agent_sock::Request::Remind {
|
||||
message: args.message,
|
||||
timing,
|
||||
file_path: args.file_path,
|
||||
|
|
@ -547,7 +548,7 @@ impl AgentServer {
|
|||
let name = args.name.clone();
|
||||
run_tool_envelope("restart", log, async move {
|
||||
let (resp, retries) = self
|
||||
.dispatch(hive_agent_sock::Request::Restart { name: args.name })
|
||||
.dispatch(hive_core_agent_sock::Request::Restart { name: args.name })
|
||||
.await;
|
||||
annotate_retries(
|
||||
format_ack(resp, "restart", format!("restarted {name}")),
|
||||
|
|
@ -569,7 +570,7 @@ impl AgentServer {
|
|||
let name = args.name.clone();
|
||||
run_tool_envelope("kill", log, async move {
|
||||
let (resp, retries) = self
|
||||
.dispatch(hive_agent_sock::Request::Kill { name: args.name })
|
||||
.dispatch(hive_core_agent_sock::Request::Kill { name: args.name })
|
||||
.await;
|
||||
annotate_retries(format_ack(resp, "kill", format!("killed {name}")), retries)
|
||||
})
|
||||
|
|
@ -590,7 +591,7 @@ impl AgentServer {
|
|||
let name = args.name.clone();
|
||||
run_tool_envelope("update", log, async move {
|
||||
let (resp, retries) = self
|
||||
.dispatch(hive_agent_sock::Request::Update { name: args.name })
|
||||
.dispatch(hive_core_agent_sock::Request::Update { name: args.name })
|
||||
.await;
|
||||
annotate_retries(
|
||||
format_ack(resp, "update", format!("updated {name}")),
|
||||
|
|
@ -613,10 +614,10 @@ impl AgentServer {
|
|||
async fn list_containers(&self) -> String {
|
||||
run_tool_envelope("list_containers", String::new(), async move {
|
||||
let (resp, retries) = self
|
||||
.dispatch(hive_agent_sock::Request::ListDescendants)
|
||||
.dispatch(hive_core_agent_sock::Request::ListDescendants)
|
||||
.await;
|
||||
let body = match resp {
|
||||
Ok(hive_agent_sock::Response::Containers { containers }) => {
|
||||
Ok(hive_core_agent_sock::Response::Containers { containers }) => {
|
||||
if containers.is_empty() {
|
||||
"no descendant containers".to_owned()
|
||||
} else {
|
||||
|
|
@ -659,7 +660,7 @@ impl AgentServer {
|
|||
let log = format!("{args:?}");
|
||||
run_tool_envelope("get_host_journal", log, async move {
|
||||
let (resp, retries) = self
|
||||
.dispatch(hive_agent_sock::Request::GetHostJournal {
|
||||
.dispatch(hive_core_agent_sock::Request::GetHostJournal {
|
||||
unit: args.unit,
|
||||
container: args.container,
|
||||
lines: args.lines,
|
||||
|
|
@ -670,7 +671,7 @@ impl AgentServer {
|
|||
})
|
||||
.await;
|
||||
let result = match resp {
|
||||
Ok(hive_agent_sock::Response::HostJournal { content }) => content,
|
||||
Ok(hive_core_agent_sock::Response::HostJournal { content }) => content,
|
||||
other => reply_err(other, "get_host_journal"),
|
||||
};
|
||||
annotate_retries(result, retries)
|
||||
|
|
@ -699,7 +700,7 @@ impl AgentServer {
|
|||
let name = args.name.clone();
|
||||
run_tool_envelope("request_init_config", log, async move {
|
||||
let (resp, retries) = self
|
||||
.dispatch(hive_agent_sock::Request::RequestInitConfig {
|
||||
.dispatch(hive_core_agent_sock::Request::RequestInitConfig {
|
||||
name: args.name,
|
||||
description: args.description,
|
||||
})
|
||||
|
|
@ -727,7 +728,7 @@ impl AgentServer {
|
|||
let name = args.name.clone();
|
||||
run_tool_envelope("start", log, async move {
|
||||
let (resp, retries) = self
|
||||
.dispatch(hive_agent_sock::Request::Start { name: args.name })
|
||||
.dispatch(hive_core_agent_sock::Request::Start { name: args.name })
|
||||
.await;
|
||||
annotate_retries(
|
||||
format_ack(resp, "start", format!("started {name}")),
|
||||
|
|
@ -750,13 +751,13 @@ impl AgentServer {
|
|||
run_tool_envelope("get_logs", log, async move {
|
||||
let lines = args.lines.map(|n| n.min(500));
|
||||
let (resp, retries) = self
|
||||
.dispatch(hive_agent_sock::Request::GetLogs {
|
||||
.dispatch(hive_core_agent_sock::Request::GetLogs {
|
||||
agent: agent.clone(),
|
||||
lines,
|
||||
})
|
||||
.await;
|
||||
let s = match resp {
|
||||
Ok(hive_agent_sock::Response::Logs { content }) => {
|
||||
Ok(hive_core_agent_sock::Response::Logs { content }) => {
|
||||
if content.is_empty() {
|
||||
format!("(no journal output for {agent})")
|
||||
} else {
|
||||
|
|
@ -790,7 +791,7 @@ impl AgentServer {
|
|||
args.inputs.join(", ")
|
||||
};
|
||||
let (resp, retries) = self
|
||||
.dispatch(hive_agent_sock::Request::RequestUpdateMetaInputs {
|
||||
.dispatch(hive_core_agent_sock::Request::RequestUpdateMetaInputs {
|
||||
inputs: args.inputs,
|
||||
description: args.description,
|
||||
})
|
||||
|
|
@ -829,7 +830,7 @@ impl AgentServer {
|
|||
run_tool_envelope("request_schedule_prompt", log, async move {
|
||||
let target_count = args.targets.len();
|
||||
let (resp, retries) = self
|
||||
.dispatch(hive_agent_sock::Request::RequestSchedulePrompt(
|
||||
.dispatch(hive_core_agent_sock::Request::RequestSchedulePrompt(
|
||||
hive_sh4re::SchedulePromptPayload {
|
||||
targets: args.targets,
|
||||
body: args.body,
|
||||
|
|
@ -865,7 +866,7 @@ impl AgentServer {
|
|||
run_tool_envelope("fire_schedule_now", log, async move {
|
||||
let id = args.id;
|
||||
let (resp, retries) = self
|
||||
.dispatch(hive_agent_sock::Request::FireScheduleNow { id })
|
||||
.dispatch(hive_core_agent_sock::Request::FireScheduleNow { id })
|
||||
.await;
|
||||
annotate_retries(
|
||||
format_ack(resp, "fire_schedule_now", format!("fired #{id} now")),
|
||||
|
|
@ -888,7 +889,7 @@ impl AgentServer {
|
|||
run_tool_envelope("cancel_schedule", log, async move {
|
||||
let id = args.id;
|
||||
let (resp, retries) = self
|
||||
.dispatch(hive_agent_sock::Request::CancelSchedule {
|
||||
.dispatch(hive_core_agent_sock::Request::CancelSchedule {
|
||||
id: args.id,
|
||||
targets: args.targets,
|
||||
})
|
||||
|
|
@ -920,7 +921,7 @@ impl AgentServer {
|
|||
run_tool_envelope("edit_schedule", log, async move {
|
||||
let id = args.id;
|
||||
let (resp, retries) = self
|
||||
.dispatch(hive_agent_sock::Request::EditSchedule {
|
||||
.dispatch(hive_core_agent_sock::Request::EditSchedule {
|
||||
id: args.id,
|
||||
body: args.body,
|
||||
description: args.description.map(Some),
|
||||
|
|
@ -947,9 +948,11 @@ impl AgentServer {
|
|||
)]
|
||||
async fn list_schedules(&self) -> String {
|
||||
run_tool_envelope("list_schedules", String::new(), async move {
|
||||
let (resp, retries) = self.dispatch(hive_agent_sock::Request::ListSchedules).await;
|
||||
let (resp, retries) = self
|
||||
.dispatch(hive_core_agent_sock::Request::ListSchedules)
|
||||
.await;
|
||||
let body = match resp {
|
||||
Ok(hive_agent_sock::Response::Schedules { schedules }) => {
|
||||
Ok(hive_core_agent_sock::Response::Schedules { schedules }) => {
|
||||
serde_json::to_string(&schedules)
|
||||
.unwrap_or_else(|e| format!("list_schedules: serialise: {e:#}"))
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue