| 618 | } |
| 619 | |
| 620 | fn metadata_tools(metadata: &Value, kind: CustomAgentKind) -> Result<Option<Vec<String>>, String> { |
| 621 | let Some(value) = metadata.get("tools") else { |
| 622 | return Ok(None); |
| 623 | }; |
| 624 | |
| 625 | match value { |
| 626 | Value::String(raw) => Ok(Some( |
| 627 | raw.split(',') |
| 628 | .map(|item| item.trim().to_string()) |
| 629 | .filter(|item| !item.is_empty()) |
| 630 | .collect(), |
| 631 | )), |
| 632 | Value::Sequence(values) => { |
| 633 | let mut tools = Vec::new(); |
| 634 | for item in values { |
| 635 | let Some(tool) = item.as_str() else { |
| 636 | return Err(format!("Invalid tools field for {:?}", kind)); |
| 637 | }; |
| 638 | let tool = tool.trim(); |
| 639 | if !tool.is_empty() { |
| 640 | tools.push(tool.to_string()); |
| 641 | } |
| 642 | } |
| 643 | Ok(Some(tools)) |
| 644 | } |
| 645 | _ => Err(format!("Invalid tools field for {:?}", kind)), |
| 646 | } |
| 647 | } |
| 648 | |
| 649 | fn metadata_user_context_policy(metadata: &Value) -> Result<Option<UserContextPolicy>, String> { |
| 650 | let Some(value) = metadata.get("user_context_policy") else { |