codetether_agent/a2a/
claim.rs1use crate::provenance::ClaimProvenance;
2use serde::Deserialize;
3
4#[derive(Debug, Deserialize)]
5pub struct TaskClaimResponse {
6 pub task_id: String,
7 pub worker_id: String,
8 pub run_id: Option<String>,
9 pub attempt_id: Option<String>,
10 pub tenant_id: Option<String>,
11 pub user_id: Option<String>,
12 pub agent_identity_id: Option<String>,
13}
14
15impl TaskClaimResponse {
16 pub fn into_provenance(self) -> ClaimProvenance {
17 ClaimProvenance {
18 worker_id: self.worker_id,
19 task_id: self.task_id,
20 run_id: self.run_id,
21 attempt_id: self.attempt_id,
22 tenant_id: self.tenant_id,
23 agent_identity_id: self
24 .agent_identity_id
25 .or_else(|| self.user_id.map(|user_id| format!("user:{user_id}"))),
26 }
27 }
28}
29
30#[cfg(test)]
31mod tests {
32 use super::TaskClaimResponse;
33
34 #[test]
35 fn maps_user_id_into_agent_identity() {
36 let provenance = TaskClaimResponse {
37 task_id: "task-1".to_string(),
38 worker_id: "worker-1".to_string(),
39 run_id: Some("run-1".to_string()),
40 attempt_id: Some("run-1:attempt:2".to_string()),
41 tenant_id: Some("tenant-1".to_string()),
42 user_id: Some("user-1".to_string()),
43 agent_identity_id: None,
44 }
45 .into_provenance();
46 assert_eq!(provenance.agent_identity_id.as_deref(), Some("user:user-1"));
47 }
48}