1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
use ;
use crateAutoApprove;
use crateProvider;
use crate;
use Path;
use Arc;
/// Build the worker's tool registry for the current workspace and approval mode.
///
/// # Arguments
///
/// * `provider` - The provider used by model-backed tools.
/// * `model` - The resolved model identifier.
/// * `auto_approve` - The active worker approval mode.
/// * `workspace_dir` - The workspace root the tools should operate inside.
/// * `completion_callback` - Optional callback for background tool completion.
///
/// # Returns
///
/// Returns a [`ToolRegistry`] scoped to the worker policy and workspace root.
///
/// # Examples
///
/// ```rust
/// use anyhow::Result;
/// use async_trait::async_trait;
/// use codetether_agent::a2a::worker::AutoApprove;
/// use codetether_agent::a2a::worker_tool_registry::create_filtered_registry;
/// use codetether_agent::provider::{
/// CompletionRequest, CompletionResponse, FinishReason, ModelInfo, Provider, StreamChunk, Usage,
/// };
/// use futures::stream::{self, BoxStream};
/// use std::sync::Arc;
///
/// struct ExampleProvider;
///
/// #[async_trait]
/// impl Provider for ExampleProvider {
/// fn name(&self) -> &str { "example" }
/// async fn list_models(&self) -> Result<Vec<ModelInfo>> { Ok(vec![]) }
/// async fn complete(&self, _request: CompletionRequest) -> Result<CompletionResponse> {
/// Ok(CompletionResponse {
/// message: codetether_agent::provider::Message {
/// role: codetether_agent::provider::Role::Assistant,
/// content: vec![],
/// },
/// usage: Usage::default(),
/// finish_reason: FinishReason::Stop,
/// })
/// }
/// async fn complete_stream(
/// &self,
/// _request: CompletionRequest,
/// ) -> Result<BoxStream<'static, StreamChunk>> {
/// Ok(Box::pin(stream::empty()))
/// }
/// }
///
/// let registry = create_filtered_registry(
/// Arc::new(ExampleProvider),
/// "example/model".to_string(),
/// AutoApprove::Safe,
/// std::path::Path::new("."),
/// None,
/// );
///
/// assert!(registry.contains("read"));
/// assert!(!registry.contains("write"));
/// ```