chore: cargo fmt --all — clean up a2a merge's fmt violations
The a2a merge (d0d8e7f) landed with a handful of pre-existing rustfmt
diffs that were failing `cargo fmt --all --check` in CI. Pure whitespace
reformatting from `cargo fmt --all`; no semantic changes. Files touched:
mcp_door.rs, quota.rs, routes/a2a.rs, routes/world.rs, runtime_provision.rs,
chat_repos.rs test, and tools/chat.rs.
This commit is contained in:
@@ -244,7 +244,10 @@ async fn caller_agent(
|
|||||||
user: &cm_auth::AuthedUser,
|
user: &cm_auth::AuthedUser,
|
||||||
headers: &HeaderMap,
|
headers: &HeaderMap,
|
||||||
) -> Result<cm_domain::AgentId, String> {
|
) -> Result<cm_domain::AgentId, String> {
|
||||||
if let Some(alias) = headers.get("x-zeroclaw-agent").and_then(|v| v.to_str().ok()) {
|
if let Some(alias) = headers
|
||||||
|
.get("x-zeroclaw-agent")
|
||||||
|
.and_then(|v| v.to_str().ok())
|
||||||
|
{
|
||||||
if let Some(hex) = alias.strip_prefix("claw_") {
|
if let Some(hex) = alias.strip_prefix("claw_") {
|
||||||
if let Ok(uuid) = uuid::Uuid::parse_str(hex) {
|
if let Ok(uuid) = uuid::Uuid::parse_str(hex) {
|
||||||
let agent_id = cm_domain::AgentId::from(uuid);
|
let agent_id = cm_domain::AgentId::from(uuid);
|
||||||
@@ -277,10 +280,18 @@ async fn delegate_call(
|
|||||||
args: &Value,
|
args: &Value,
|
||||||
id: Option<Value>,
|
id: Option<Value>,
|
||||||
) -> Json<Value> {
|
) -> Json<Value> {
|
||||||
let Some(to) = args.get("to").and_then(|v| v.as_str()).filter(|s| !s.is_empty()) else {
|
let Some(to) = args
|
||||||
|
.get("to")
|
||||||
|
.and_then(|v| v.as_str())
|
||||||
|
.filter(|s| !s.is_empty())
|
||||||
|
else {
|
||||||
return tool_result(id, true, "delegate: missing 'to' (target claw name)".into());
|
return tool_result(id, true, "delegate: missing 'to' (target claw name)".into());
|
||||||
};
|
};
|
||||||
let Some(task) = args.get("task").and_then(|v| v.as_str()).filter(|s| !s.is_empty()) else {
|
let Some(task) = args
|
||||||
|
.get("task")
|
||||||
|
.and_then(|v| v.as_str())
|
||||||
|
.filter(|s| !s.is_empty())
|
||||||
|
else {
|
||||||
return tool_result(id, true, "delegate: missing 'task'".into());
|
return tool_result(id, true, "delegate: missing 'task'".into());
|
||||||
};
|
};
|
||||||
let context: Vec<String> = args
|
let context: Vec<String> = args
|
||||||
@@ -296,10 +307,20 @@ async fn delegate_call(
|
|||||||
// Resolve the target claw by name within the workspace.
|
// Resolve the target claw by name within the workspace.
|
||||||
let target = match cm_db::repo::agents::roster(&state.pool, user.workspace_id).await {
|
let target = match cm_db::repo::agents::roster(&state.pool, user.workspace_id).await {
|
||||||
Ok(roster) => roster.into_iter().find(|a| a.name.eq_ignore_ascii_case(to)),
|
Ok(roster) => roster.into_iter().find(|a| a.name.eq_ignore_ascii_case(to)),
|
||||||
Err(_) => return tool_result(id, true, "delegate: failed to resolve workspace roster".into()),
|
Err(_) => {
|
||||||
|
return tool_result(
|
||||||
|
id,
|
||||||
|
true,
|
||||||
|
"delegate: failed to resolve workspace roster".into(),
|
||||||
|
)
|
||||||
|
}
|
||||||
};
|
};
|
||||||
let Some(target) = target else {
|
let Some(target) = target else {
|
||||||
return tool_result(id, true, format!("delegate: no claw named {to:?} in this workspace"));
|
return tool_result(
|
||||||
|
id,
|
||||||
|
true,
|
||||||
|
format!("delegate: no claw named {to:?} in this workspace"),
|
||||||
|
);
|
||||||
};
|
};
|
||||||
if target.id == caller {
|
if target.id == caller {
|
||||||
return tool_result(id, true, "delegate: cannot delegate to yourself".into());
|
return tool_result(id, true, "delegate: cannot delegate to yourself".into());
|
||||||
|
|||||||
@@ -69,10 +69,7 @@ pub async fn enforce_new_agent(
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Reject enqueueing another topology run if the workspace is at its plan cap.
|
/// Reject enqueueing another topology run if the workspace is at its plan cap.
|
||||||
pub async fn enforce_new_run(
|
pub async fn enforce_new_run(state: &AppState, workspace_id: WorkspaceId) -> Result<(), ApiError> {
|
||||||
state: &AppState,
|
|
||||||
workspace_id: WorkspaceId,
|
|
||||||
) -> Result<(), ApiError> {
|
|
||||||
let plan = plan_of(state, workspace_id).await?;
|
let plan = plan_of(state, workspace_id).await?;
|
||||||
let quota = plan_quota(&plan);
|
let quota = plan_quota(&plan);
|
||||||
let used = cm_db::repo::topology_runs::count_active(&state.pool, workspace_id).await?;
|
let used = cm_db::repo::topology_runs::count_active(&state.pool, workspace_id).await?;
|
||||||
|
|||||||
@@ -23,8 +23,12 @@ use crate::{ApiError, AppState, Authed};
|
|||||||
/// The internal daemon base URL + bearer (single daemon today; a per-workspace
|
/// The internal daemon base URL + bearer (single daemon today; a per-workspace
|
||||||
/// resolver slots in here when multi-daemon lands).
|
/// resolver slots in here when multi-daemon lands).
|
||||||
fn daemon(_workspace: Uuid) -> Option<(String, String)> {
|
fn daemon(_workspace: Uuid) -> Option<(String, String)> {
|
||||||
let url = std::env::var("ZEROCLAW_GATEWAY_URL").ok().filter(|u| !u.is_empty())?;
|
let url = std::env::var("ZEROCLAW_GATEWAY_URL")
|
||||||
let token = std::env::var("ZEROCLAW_TOKEN").ok().filter(|t| !t.is_empty())?;
|
.ok()
|
||||||
|
.filter(|u| !u.is_empty())?;
|
||||||
|
let token = std::env::var("ZEROCLAW_TOKEN")
|
||||||
|
.ok()
|
||||||
|
.filter(|t| !t.is_empty())?;
|
||||||
Some((url, token))
|
Some((url, token))
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -78,7 +82,9 @@ pub async fn settings(
|
|||||||
// runtime is momentarily unreachable).
|
// runtime is momentarily unreachable).
|
||||||
if body.enabled {
|
if body.enabled {
|
||||||
if let Some(p) = RuntimeProvisioner::from_env() {
|
if let Some(p) = RuntimeProvisioner::from_env() {
|
||||||
p.enable_a2a_server(&base).await.map_err(|_| ApiError::Internal)?;
|
p.enable_a2a_server(&base)
|
||||||
|
.await
|
||||||
|
.map_err(|_| ApiError::Internal)?;
|
||||||
for entry in &body.publish {
|
for entry in &body.publish {
|
||||||
// Scope: each claw must be in the caller's workspace.
|
// Scope: each claw must be in the caller's workspace.
|
||||||
let agent = cm_db::repo::agents::get(&state.pool, entry.claw_id.into())
|
let agent = cm_db::repo::agents::get(&state.pool, entry.claw_id.into())
|
||||||
@@ -93,7 +99,9 @@ pub async fn settings(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Ok(Json(json!({ "enabled": body.enabled, "publicBaseUrl": base })))
|
Ok(Json(
|
||||||
|
json!({ "enabled": body.enabled, "publicBaseUrl": base }),
|
||||||
|
))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// GET /api/a2a/settings — current A2A opt-in state for the workspace.
|
/// GET /api/a2a/settings — current A2A opt-in state for the workspace.
|
||||||
@@ -157,7 +165,16 @@ pub async fn list_tokens(
|
|||||||
State(state): State<AppState>,
|
State(state): State<AppState>,
|
||||||
Authed(user): Authed,
|
Authed(user): Authed,
|
||||||
) -> Result<Json<Value>, ApiError> {
|
) -> Result<Json<Value>, ApiError> {
|
||||||
let rows = sqlx::query_as::<_, (Uuid, Option<String>, bool, Option<String>, Option<time::OffsetDateTime>)>(
|
let rows = sqlx::query_as::<
|
||||||
|
_,
|
||||||
|
(
|
||||||
|
Uuid,
|
||||||
|
Option<String>,
|
||||||
|
bool,
|
||||||
|
Option<String>,
|
||||||
|
Option<time::OffsetDateTime>,
|
||||||
|
),
|
||||||
|
>(
|
||||||
"SELECT id, alias, enabled, label, last_used_at FROM a2a_tokens
|
"SELECT id, alias, enabled, label, last_used_at FROM a2a_tokens
|
||||||
WHERE workspace_id = $1 ORDER BY created_at DESC",
|
WHERE workspace_id = $1 ORDER BY created_at DESC",
|
||||||
)
|
)
|
||||||
@@ -186,9 +203,8 @@ pub async fn revoke_token(
|
|||||||
Authed(user): Authed,
|
Authed(user): Authed,
|
||||||
Path(id): Path<Uuid>,
|
Path(id): Path<Uuid>,
|
||||||
) -> Result<Json<Value>, ApiError> {
|
) -> Result<Json<Value>, ApiError> {
|
||||||
let res = sqlx::query(
|
let res =
|
||||||
"UPDATE a2a_tokens SET enabled = false WHERE id = $1 AND workspace_id = $2",
|
sqlx::query("UPDATE a2a_tokens SET enabled = false WHERE id = $1 AND workspace_id = $2")
|
||||||
)
|
|
||||||
.bind(id)
|
.bind(id)
|
||||||
.bind(user.workspace_id.as_uuid())
|
.bind(user.workspace_id.as_uuid())
|
||||||
.execute(&state.pool)
|
.execute(&state.pool)
|
||||||
@@ -220,7 +236,11 @@ fn rewrite_card(card: &str, daemon_base: &str, edge_base: &str) -> String {
|
|||||||
card.replace(daemon_base, edge_base.trim_end_matches('/'))
|
card.replace(daemon_base, edge_base.trim_end_matches('/'))
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn proxy_card(state: &AppState, workspace: Uuid, path: &str) -> Result<Json<Value>, StatusCode> {
|
async fn proxy_card(
|
||||||
|
state: &AppState,
|
||||||
|
workspace: Uuid,
|
||||||
|
path: &str,
|
||||||
|
) -> Result<Json<Value>, StatusCode> {
|
||||||
if !workspace_enabled(state, workspace).await {
|
if !workspace_enabled(state, workspace).await {
|
||||||
return Err(StatusCode::NOT_FOUND);
|
return Err(StatusCode::NOT_FOUND);
|
||||||
}
|
}
|
||||||
@@ -253,7 +273,12 @@ pub async fn discovery_card(
|
|||||||
State(state): State<AppState>,
|
State(state): State<AppState>,
|
||||||
Path((workspace, alias)): Path<(Uuid, String)>,
|
Path((workspace, alias)): Path<(Uuid, String)>,
|
||||||
) -> Result<Json<Value>, StatusCode> {
|
) -> Result<Json<Value>, StatusCode> {
|
||||||
proxy_card(&state, workspace, &format!("/a2a/{alias}/.well-known/agent-card.json")).await
|
proxy_card(
|
||||||
|
&state,
|
||||||
|
workspace,
|
||||||
|
&format!("/a2a/{alias}/.well-known/agent-card.json"),
|
||||||
|
)
|
||||||
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
/// POST /api/a2a/{workspace}/{alias} — authenticated task invocation. Verifies
|
/// POST /api/a2a/{workspace}/{alias} — authenticated task invocation. Verifies
|
||||||
@@ -372,7 +397,14 @@ async fn synthesize_run(
|
|||||||
let run_id = cm_db::repo::runs::create(&state.pool, session.id)
|
let run_id = cm_db::repo::runs::create(&state.pool, session.id)
|
||||||
.await
|
.await
|
||||||
.map_err(|_| ())?;
|
.map_err(|_| ())?;
|
||||||
let _ = cm_db::repo::run_events::append(&state.pool, run_id, 1, "run_started", json!({ "run_id": run_id })).await;
|
let _ = cm_db::repo::run_events::append(
|
||||||
|
&state.pool,
|
||||||
|
run_id,
|
||||||
|
1,
|
||||||
|
"run_started",
|
||||||
|
json!({ "run_id": run_id }),
|
||||||
|
)
|
||||||
|
.await;
|
||||||
let _ = cm_db::repo::run_events::append(
|
let _ = cm_db::repo::run_events::append(
|
||||||
&state.pool,
|
&state.pool,
|
||||||
run_id,
|
run_id,
|
||||||
@@ -381,7 +413,15 @@ async fn synthesize_run(
|
|||||||
json!({ "alias": alias }),
|
json!({ "alias": alias }),
|
||||||
)
|
)
|
||||||
.await;
|
.await;
|
||||||
let _ = cm_db::repo::run_events::append(&state.pool, run_id, 3, "run_completed", json!({ "message_id": "" })).await;
|
let _ = cm_db::repo::run_events::append(
|
||||||
let _ = cm_db::repo::runs::set_state(&state.pool, run_id, cm_domain::RunState::Completed, None).await;
|
&state.pool,
|
||||||
|
run_id,
|
||||||
|
3,
|
||||||
|
"run_completed",
|
||||||
|
json!({ "message_id": "" }),
|
||||||
|
)
|
||||||
|
.await;
|
||||||
|
let _ = cm_db::repo::runs::set_state(&state.pool, run_id, cm_domain::RunState::Completed, None)
|
||||||
|
.await;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -182,10 +182,7 @@ fn normalize_run_event(
|
|||||||
}
|
}
|
||||||
"a2a_invoked" => {
|
"a2a_invoked" => {
|
||||||
// An external A2A caller started a turn on this agent (a new ingress).
|
// An external A2A caller started a turn on this agent (a new ingress).
|
||||||
out.push((
|
out.push(("a2a.invoked", json!({ "agentId": agent_id })));
|
||||||
"a2a.invoked",
|
|
||||||
json!({ "agentId": agent_id }),
|
|
||||||
));
|
|
||||||
}
|
}
|
||||||
_ => {}
|
_ => {}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -135,7 +135,11 @@ impl RuntimeProvisioner {
|
|||||||
|
|
||||||
/// Publish a claw as an A2A agent, advertising only `exposed_skills`. Opt-in
|
/// Publish a claw as an A2A agent, advertising only `exposed_skills`. Opt-in
|
||||||
/// (not part of `provision_claw`).
|
/// (not part of `provision_claw`).
|
||||||
pub async fn publish_claw(&self, claw_id: Uuid, exposed_skills: &[String]) -> Result<(), String> {
|
pub async fn publish_claw(
|
||||||
|
&self,
|
||||||
|
claw_id: Uuid,
|
||||||
|
exposed_skills: &[String],
|
||||||
|
) -> Result<(), String> {
|
||||||
let alias = claw_alias(claw_id);
|
let alias = claw_alias(claw_id);
|
||||||
self.set_prop(
|
self.set_prop(
|
||||||
&format!("agents.{alias}.a2a.published"),
|
&format!("agents.{alias}.a2a.published"),
|
||||||
|
|||||||
@@ -1,4 +1,6 @@
|
|||||||
use cm_db::repo::{agents, messages, run_events, runs, sessions, steps, threads, users, workspaces};
|
use cm_db::repo::{
|
||||||
|
agents, messages, run_events, runs, sessions, steps, threads, users, workspaces,
|
||||||
|
};
|
||||||
use cm_db::DbError;
|
use cm_db::DbError;
|
||||||
use cm_domain::{
|
use cm_domain::{
|
||||||
AccessPolicy, Agent, AgentId, AgentStatus, MessageRole, Role, RunState, Session, SessionId,
|
AccessPolicy, Agent, AgentId, AgentStatus, MessageRole, Role, RunState, Session, SessionId,
|
||||||
@@ -296,7 +298,9 @@ async fn leaving_a_room_hides_it_but_keeps_history() {
|
|||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
threads::remove_participant(&pool, room, b.id).await.unwrap();
|
threads::remove_participant(&pool, room, b.id)
|
||||||
|
.await
|
||||||
|
.unwrap();
|
||||||
assert!(
|
assert!(
|
||||||
!threads::list_for_agent(&pool, b.id)
|
!threads::list_for_agent(&pool, b.id)
|
||||||
.await
|
.await
|
||||||
@@ -314,7 +318,10 @@ async fn leaving_a_room_hides_it_but_keeps_history() {
|
|||||||
assert_eq!(msgs.len(), 1);
|
assert_eq!(msgs.len(), 1);
|
||||||
assert_eq!(msgs[0].from_agent, b.id.as_uuid());
|
assert_eq!(msgs[0].from_agent, b.id.as_uuid());
|
||||||
// And a is still in.
|
// And a is still in.
|
||||||
assert_eq!(threads::participants(&pool, room).await.unwrap(), vec![a.id.as_uuid()]);
|
assert_eq!(
|
||||||
|
threads::participants(&pool, room).await.unwrap(),
|
||||||
|
vec![a.id.as_uuid()]
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
|
|||||||
@@ -235,8 +235,7 @@ impl Tool for RoomInvite {
|
|||||||
fn descriptor(&self) -> ToolDescriptor {
|
fn descriptor(&self) -> ToolDescriptor {
|
||||||
ToolDescriptor {
|
ToolDescriptor {
|
||||||
name: "room.invite".into(),
|
name: "room.invite".into(),
|
||||||
description: "Invites another claw into a group room you belong to."
|
description: "Invites another claw into a group room you belong to.".into(),
|
||||||
.into(),
|
|
||||||
input_schema: json!({
|
input_schema: json!({
|
||||||
"type": "object",
|
"type": "object",
|
||||||
"properties": {
|
"properties": {
|
||||||
@@ -282,8 +281,7 @@ impl Tool for RoomLeave {
|
|||||||
fn descriptor(&self) -> ToolDescriptor {
|
fn descriptor(&self) -> ToolDescriptor {
|
||||||
ToolDescriptor {
|
ToolDescriptor {
|
||||||
name: "room.leave".into(),
|
name: "room.leave".into(),
|
||||||
description: "Leaves a group room. Your past messages stay visible."
|
description: "Leaves a group room. Your past messages stay visible.".into(),
|
||||||
.into(),
|
|
||||||
input_schema: json!({
|
input_schema: json!({
|
||||||
"type": "object",
|
"type": "object",
|
||||||
"properties": {"room": {"type": "string", "description": "room id"}},
|
"properties": {"room": {"type": "string", "description": "room id"}},
|
||||||
|
|||||||
Reference in New Issue
Block a user