Large World graph, agent platform, brain stack & dashboard rebuild
Frontend - Large World: collapse org/company/team tiers into one expandable React Flow hierarchy (WorldFlow) with per-click expand, persisted node positions, a compact tree sidebar, wrench multi-select delete across levels, and a sized right slide-out (phone/tablet/full) showing an agent summary + drill button. - Agent page: GitHub-style animated contribution grid (VitalsCard), collapsible System Prompt + Personality cards, restructured anatomy cards, bigger avatar with name/title header row, Markdown/JSON-aware rendering, brain registry + history, avatar generate/upload. - User-icon menu (Infrastructure/Brains/Tools/Profile/Credits) + ToolPanel; Master Planner deploy wizard (Specialists/Swarm/Scheduled/Triggered); Team Runs view; reap-progress modal; dashboard is the single live interface. Backend - cm-brain crate (.brain as the agent definition) + brain apply/history. - Hard-purge reap (FK-ordered) + sandbox release + SSE batch-delete. - Swarm self-verifying loop, mode-aware planner, web.search tool, webhooks (migration 0013), org/company/team delete endpoints, scheduler sweeps. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
This commit is contained in:
co-authored by
Claude Opus 4.8
parent
9f266d5806
commit
34f744734b
@@ -45,52 +45,49 @@ fn parse_kind(s: &str) -> Result<TopologyKind, ApiError> {
|
||||
serde_json::from_value(Value::String(s.to_string())).map_err(|_| ApiError::BadRequest)
|
||||
}
|
||||
|
||||
/// `POST /api/teams` — create a team: for each member create a claw + provision a
|
||||
/// runtime agent, build the baseline topology, bind node→claw, persist.
|
||||
pub async fn create_team(
|
||||
State(state): State<AppState>,
|
||||
Authed(user): Authed,
|
||||
Json(body): Json<CreateTeamRequest>,
|
||||
) -> Result<(StatusCode, Json<TeamCreated>), ApiError> {
|
||||
if body.members.is_empty() {
|
||||
/// Create a team end-to-end: for each member create a claw + provision a runtime
|
||||
/// agent, build the baseline topology, bind node→claw, persist. Returns the team
|
||||
/// id + the created claw ids (in member order) so callers (e.g. the Master
|
||||
/// Planner scaffold) can attach brains afterward.
|
||||
pub(crate) async fn build_team(
|
||||
state: &AppState,
|
||||
workspace_id: cm_domain::WorkspaceId,
|
||||
user_id: cm_domain::UserId,
|
||||
name: &str,
|
||||
kind_str: &str,
|
||||
members: &[TeamMemberInput],
|
||||
) -> Result<(Uuid, Vec<Uuid>), ApiError> {
|
||||
if members.is_empty() {
|
||||
return Err(ApiError::BadRequest);
|
||||
}
|
||||
let kind = parse_kind(&body.kind)?;
|
||||
let kind = parse_kind(kind_str)?;
|
||||
let provisioner = RuntimeProvisioner::from_env().ok_or(ApiError::Internal)?;
|
||||
|
||||
// 1. Create each claw (DB row) + provision it as a live runtime agent.
|
||||
let mut claw_ids: Vec<Uuid> = Vec::with_capacity(body.members.len());
|
||||
for m in &body.members {
|
||||
let mut claw_ids: Vec<Uuid> = Vec::with_capacity(members.len());
|
||||
for m in members {
|
||||
let agent = Agent {
|
||||
id: AgentId::new(),
|
||||
workspace_id: user.workspace_id,
|
||||
workspace_id,
|
||||
name: m.name.clone(),
|
||||
job_title: m.role.clone(),
|
||||
system_prompt: m.system_prompt.clone(),
|
||||
avatar: String::new(),
|
||||
accent: m.accent.clone(),
|
||||
wallpaper: String::new(),
|
||||
managed_by: user.user_id,
|
||||
managed_by: user_id,
|
||||
status: AgentStatus::Online,
|
||||
};
|
||||
cm_db::repo::agents::insert(&state.pool, &agent, &AccessPolicy::default()).await?;
|
||||
let claw_id = agent.id.as_uuid();
|
||||
// Provisioning failure rolls the team back at the runtime layer is best-
|
||||
// effort; the claw row stays (visible in the roster) so nothing is lost.
|
||||
provisioner
|
||||
.provision_claw(claw_id, &m.model)
|
||||
.await
|
||||
.map_err(|e| {
|
||||
eprintln!("teams: provision claw {claw_id} failed: {e}");
|
||||
ApiError::Internal
|
||||
})?;
|
||||
// Persist the model so the claw card / anatomy can show it later.
|
||||
provisioner.provision_claw(claw_id, &m.model).await.map_err(|e| {
|
||||
eprintln!("teams: provision claw {claw_id} failed: {e}");
|
||||
ApiError::Internal
|
||||
})?;
|
||||
cm_db::repo::agents::set_model_binding(&state.pool, agent.id, &m.model).await?;
|
||||
claw_ids.push(claw_id);
|
||||
}
|
||||
|
||||
// 2. Build the baseline topology and bind each node to its claw's runtime alias.
|
||||
let roles: Vec<&str> = body.members.iter().map(|m| m.role.as_str()).collect();
|
||||
let roles: Vec<&str> = members.iter().map(|m| m.role.as_str()).collect();
|
||||
let mut graph = build(kind, &roles).map_err(|_| ApiError::BadRequest)?;
|
||||
for (i, node) in graph.nodes.iter_mut().enumerate() {
|
||||
if let Some(cid) = claw_ids.get(i) {
|
||||
@@ -99,7 +96,78 @@ pub async fn create_team(
|
||||
}
|
||||
}
|
||||
|
||||
// 3. Persist team + node→claw bindings.
|
||||
let team_id = Uuid::now_v7();
|
||||
let graph_json = serde_json::to_value(&graph).map_err(|_| ApiError::Internal)?;
|
||||
cm_db::repo::teams::insert_team(&state.pool, team_id, workspace_id, name, kind.as_str(), &graph_json).await?;
|
||||
for (i, node) in graph.nodes.iter().enumerate() {
|
||||
if let Some(cid) = claw_ids.get(i) {
|
||||
cm_db::repo::teams::add_member(&state.pool, team_id, &node.id, *cid, &node.role).await?;
|
||||
}
|
||||
}
|
||||
Ok((team_id, claw_ids))
|
||||
}
|
||||
|
||||
/// `POST /api/teams` — create a team from explicit members.
|
||||
pub async fn create_team(
|
||||
State(state): State<AppState>,
|
||||
Authed(user): Authed,
|
||||
Json(body): Json<CreateTeamRequest>,
|
||||
) -> Result<(StatusCode, Json<TeamCreated>), ApiError> {
|
||||
let (team_id, _) = build_team(
|
||||
&state,
|
||||
user.workspace_id,
|
||||
user.user_id,
|
||||
&body.name,
|
||||
&body.kind,
|
||||
&body.members,
|
||||
)
|
||||
.await?;
|
||||
Ok((StatusCode::CREATED, Json(TeamCreated { team_id: team_id.to_string() })))
|
||||
}
|
||||
|
||||
#[derive(Deserialize)]
|
||||
pub struct ComposeTeamRequest {
|
||||
pub name: String,
|
||||
/// TopologyKind (snake_case); defaults to `hub_spoke` when omitted.
|
||||
#[serde(default)]
|
||||
pub kind: String,
|
||||
/// Existing claws (agents) to group into the new team.
|
||||
pub claw_ids: Vec<Uuid>,
|
||||
}
|
||||
|
||||
/// `POST /api/teams/from-claws` — create a team from EXISTING claws (no new
|
||||
/// provisioning): verify each claw is in the caller's workspace, build the
|
||||
/// baseline topology over their roles, bind node→claw, persist.
|
||||
pub async fn create_team_from_claws(
|
||||
State(state): State<AppState>,
|
||||
Authed(user): Authed,
|
||||
Json(body): Json<ComposeTeamRequest>,
|
||||
) -> Result<(StatusCode, Json<TeamCreated>), ApiError> {
|
||||
if body.claw_ids.is_empty() {
|
||||
return Err(ApiError::BadRequest);
|
||||
}
|
||||
let kind = parse_kind(if body.kind.is_empty() { "hub_spoke" } else { &body.kind })?;
|
||||
|
||||
// Resolve + authorize each claw, collecting its role for the topology.
|
||||
let mut roles: Vec<String> = Vec::with_capacity(body.claw_ids.len());
|
||||
for cid in &body.claw_ids {
|
||||
let agent = crate::routes::claws::workspace_agent(&state, &user, AgentId::from(*cid)).await?;
|
||||
roles.push(if agent.job_title.is_empty() {
|
||||
"claw".into()
|
||||
} else {
|
||||
agent.job_title
|
||||
});
|
||||
}
|
||||
|
||||
let role_refs: Vec<&str> = roles.iter().map(|s| s.as_str()).collect();
|
||||
let mut graph = build(kind, &role_refs).map_err(|_| ApiError::BadRequest)?;
|
||||
for (i, node) in graph.nodes.iter_mut().enumerate() {
|
||||
if let Some(cid) = body.claw_ids.get(i) {
|
||||
node.attrs.insert("agent".into(), claw_alias(*cid));
|
||||
node.attrs.insert("claw_id".into(), cid.to_string());
|
||||
}
|
||||
}
|
||||
|
||||
let team_id = Uuid::now_v7();
|
||||
let graph_json = serde_json::to_value(&graph).map_err(|_| ApiError::Internal)?;
|
||||
cm_db::repo::teams::insert_team(
|
||||
@@ -112,7 +180,7 @@ pub async fn create_team(
|
||||
)
|
||||
.await?;
|
||||
for (i, node) in graph.nodes.iter().enumerate() {
|
||||
if let Some(cid) = claw_ids.get(i) {
|
||||
if let Some(cid) = body.claw_ids.get(i) {
|
||||
cm_db::repo::teams::add_member(&state.pool, team_id, &node.id, *cid, &node.role)
|
||||
.await?;
|
||||
}
|
||||
@@ -198,6 +266,57 @@ pub async fn get_team(
|
||||
}))
|
||||
}
|
||||
|
||||
#[derive(Deserialize)]
|
||||
pub struct PatchTeamRequest {
|
||||
/// New TopologyKind (snake_case), e.g. "hierarchical", "hub_spoke".
|
||||
pub kind: String,
|
||||
}
|
||||
|
||||
/// `PATCH /api/teams/{id}` — change a team's topology: rebuild the graph over the
|
||||
/// existing members' roles (stable node ids keep the node→claw bindings valid)
|
||||
/// and persist the new kind + graph.
|
||||
pub async fn patch_team(
|
||||
State(state): State<AppState>,
|
||||
Authed(user): Authed,
|
||||
Path(id): Path<Uuid>,
|
||||
Json(body): Json<PatchTeamRequest>,
|
||||
) -> Result<StatusCode, ApiError> {
|
||||
let team = cm_db::repo::teams::get_team(&state.pool, id, user.workspace_id).await?;
|
||||
let kind = parse_kind(&body.kind)?;
|
||||
let members = cm_db::repo::teams::members_for_team(&state.pool, team.id).await?;
|
||||
|
||||
let by_node: std::collections::HashMap<String, (Uuid, String)> = members
|
||||
.into_iter()
|
||||
.map(|m| (m.node_id, (m.claw_id, m.role)))
|
||||
.collect();
|
||||
let n = by_node.len();
|
||||
let roles: Vec<String> = (0..n)
|
||||
.map(|i| by_node.get(&format!("n{i}")).map(|(_, r)| r.clone()).unwrap_or_else(|| "claw".into()))
|
||||
.collect();
|
||||
let role_refs: Vec<&str> = roles.iter().map(String::as_str).collect();
|
||||
let mut graph = build(kind, &role_refs).map_err(|_| ApiError::BadRequest)?;
|
||||
for node in graph.nodes.iter_mut() {
|
||||
if let Some((cid, _)) = by_node.get(&node.id) {
|
||||
node.attrs.insert("agent".into(), claw_alias(*cid));
|
||||
node.attrs.insert("claw_id".into(), cid.to_string());
|
||||
}
|
||||
}
|
||||
let graph_json = serde_json::to_value(&graph).map_err(|_| ApiError::Internal)?;
|
||||
cm_db::repo::teams::set_topology(&state.pool, team.id, user.workspace_id, kind.as_str(), &graph_json).await?;
|
||||
Ok(StatusCode::NO_CONTENT)
|
||||
}
|
||||
|
||||
/// `DELETE /api/teams/{id}` — remove a team and its node→claw bindings (the claws
|
||||
/// themselves remain in the workspace).
|
||||
pub async fn delete_team(
|
||||
State(state): State<AppState>,
|
||||
Authed(user): Authed,
|
||||
Path(id): Path<Uuid>,
|
||||
) -> Result<StatusCode, ApiError> {
|
||||
cm_db::repo::teams::delete_team(&state.pool, id, user.workspace_id).await?;
|
||||
Ok(StatusCode::NO_CONTENT)
|
||||
}
|
||||
|
||||
#[derive(Deserialize)]
|
||||
pub struct RunTeamRequest {
|
||||
pub task: String,
|
||||
|
||||
Reference in New Issue
Block a user