feat(saas): industry agent template assignment system
Some checks failed
CI / Lint & TypeCheck (push) Has been cancelled
CI / Unit Tests (push) Has been cancelled
CI / Build Frontend (push) Has been cancelled
CI / Rust Check (push) Has been cancelled
CI / Security Scan (push) Has been cancelled
CI / E2E Tests (push) Has been cancelled

Phase 1-8 of industry-agent-delivery plan:

- DB migration: accounts.assigned_template_id (ON DELETE SET NULL)
- SaaS API: 4 new endpoints (assign/get/unassign/create-agent)
- Service layer: assign_template_to_account, get_assigned_template, unassign_template, create_agent_from_template)
- Types: AssignTemplateRequest, AgentConfigFromTemplate (capabilities merged into tools)
- Frontend SaaS Client: assignTemplate, getAssignedTemplate, unassignTemplate, createAgentFromTemplate
- saasStore: assignedTemplate state + login auto-fetch + actions
- saas-relay-client: fix unused import and saasUrl reference error
- connectionStore: fix relayModel undefined error
- capabilities default to glm-4-flash

- Route registration: new template assignment routes

Cospec and handlers consolidated

Build: cargo check --workspace PASS, tsc --noEmit Pass
This commit is contained in:
iven
2026-04-03 13:31:58 +08:00
parent 5b1b747810
commit ea00c32c08
10 changed files with 618 additions and 16 deletions

View File

@@ -139,3 +139,52 @@ pub async fn archive_template(
Ok(Json(result))
}
// --- Template Assignment ---
/// POST /api/v1/accounts/me/assign-template — 分配行业模板到当前账户
pub async fn assign_template(
State(state): State<AppState>,
Extension(ctx): Extension<AuthContext>,
Json(req): Json<AssignTemplateRequest>,
) -> SaasResult<Json<AgentTemplateInfo>> {
check_permission(&ctx, "model:read")?;
let result = service::assign_template_to_account(
&state.db, &ctx.account_id, &req.template_id,
).await?;
log_operation(&state.db, &ctx.account_id, "account.assign_template", "agent_template", &req.template_id,
None, ctx.client_ip.as_deref()).await?;
Ok(Json(result))
}
/// GET /api/v1/accounts/me/assigned-template — 获取已分配的行业模板
pub async fn get_assigned_template(
State(state): State<AppState>,
Extension(ctx): Extension<AuthContext>,
) -> SaasResult<Json<Option<AgentTemplateInfo>>> {
check_permission(&ctx, "model:read")?;
Ok(Json(service::get_assigned_template(&state.db, &ctx.account_id).await?))
}
/// DELETE /api/v1/accounts/me/assigned-template — 取消行业模板分配
pub async fn unassign_template(
State(state): State<AppState>,
Extension(ctx): Extension<AuthContext>,
) -> SaasResult<Json<serde_json::Value>> {
check_permission(&ctx, "model:read")?;
service::unassign_template(&state.db, &ctx.account_id).await?;
Ok(Json(serde_json::json!({"ok": true})))
}
/// POST /api/v1/agent-templates/:id/create-agent — 从模板创建 Agent 配置
pub async fn create_agent_from_template(
State(state): State<AppState>,
Extension(ctx): Extension<AuthContext>,
Path(id): Path<String>,
) -> SaasResult<Json<AgentConfigFromTemplate>> {
check_permission(&ctx, "model:read")?;
Ok(Json(service::create_agent_from_template(&state.db, &id).await?))
}