(spec: WorkerAgentSpec)
| 2712 | } |
| 2713 | |
| 2714 | fn js_worker_agent_spec_to_rust(spec: WorkerAgentSpec) -> napi::Result<RustWorkerAgentSpec> { |
| 2715 | if spec.name.trim().is_empty() { |
| 2716 | return Err(napi::Error::from_reason("worker agent name is required")); |
| 2717 | } |
| 2718 | if spec.description.trim().is_empty() { |
| 2719 | return Err(napi::Error::from_reason( |
| 2720 | "worker agent description is required", |
| 2721 | )); |
| 2722 | } |
| 2723 | |
| 2724 | let kind = parse_worker_agent_kind(spec.kind.as_deref())?; |
| 2725 | let mut worker = RustWorkerAgentSpec::new(kind, spec.name, spec.description); |
| 2726 | if spec.hidden.unwrap_or(false) { |
| 2727 | worker = worker.hidden(true); |
| 2728 | } |
| 2729 | if let Some(policy) = spec.permissions { |
| 2730 | worker = worker.with_permissions(js_permission_policy_to_rust(policy)?); |
| 2731 | } |
| 2732 | if let Some(model) = spec.model { |
| 2733 | worker = worker.with_model(RustAgentModelConfig::from_model_ref(model)); |
| 2734 | } |
| 2735 | if let Some(prompt) = spec.prompt { |
| 2736 | worker = worker.with_prompt(prompt); |
| 2737 | } |
| 2738 | if let Some(max_steps) = spec.max_steps { |
| 2739 | worker = worker.with_max_steps(max_steps as usize); |
| 2740 | } |
| 2741 | if let Some(ci) = spec.confirmation_inheritance { |
| 2742 | worker = worker.with_confirmation(parse_confirmation_inheritance(&ci)?); |
| 2743 | } |
| 2744 | Ok(worker) |
| 2745 | } |
| 2746 | |
| 2747 | fn parse_worker_agent_kind(kind: Option<&str>) -> napi::Result<RustWorkerAgentKind> { |
| 2748 | kind.unwrap_or("custom") |
no test coverage detected