codetether_agent/a2a/
claim.rs1use crate::provenance::ClaimProvenance;
2use serde::{Deserialize, Serialize};
3
4#[derive(Debug, Deserialize, Serialize)]
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 #[serde(default)]
14 pub task_timeout_seconds: Option<u64>,
15 #[serde(default)]
16 pub provider_keys: Option<serde_json::Value>,
17 #[serde(default)]
18 pub provider_key_source: Option<String>,
19}
20
21impl TaskClaimResponse {
22 pub fn into_provenance(self) -> ClaimProvenance {
23 ClaimProvenance {
24 worker_id: self.worker_id,
25 task_id: self.task_id,
26 run_id: self.run_id,
27 attempt_id: self.attempt_id,
28 tenant_id: self.tenant_id,
29 agent_identity_id: self
30 .agent_identity_id
31 .or_else(|| self.user_id.map(|user_id| format!("user:{user_id}"))),
32 }
33 }
34}
35
36#[cfg(test)]
37mod tests {
38 use super::TaskClaimResponse;
39
40 #[test]
41 fn maps_user_id_into_agent_identity() {
42 let provenance = TaskClaimResponse {
43 task_id: "task-1".to_string(),
44 worker_id: "worker-1".to_string(),
45 run_id: Some("run-1".to_string()),
46 attempt_id: Some("run-1:attempt:2".to_string()),
47 tenant_id: Some("tenant-1".to_string()),
48 user_id: Some("user-1".to_string()),
49 agent_identity_id: None,
50 task_timeout_seconds: None,
51 provider_keys: None,
52 provider_key_source: None,
53 }
54 .into_provenance();
55 assert_eq!(provenance.agent_identity_id.as_deref(), Some("user:user-1"));
56 }
57}