feat(grid-agent): add chat and IM interactions (#123)
This commit is contained in:
@@ -831,6 +831,27 @@ impl PolicyGateway {
|
||||
|
||||
#[must_use]
|
||||
pub fn tools_for(&self, context: &PolicyRequestContext, now: u64) -> Vec<ToolDefinition> {
|
||||
self.tools_for_capabilities(context, now, None)
|
||||
}
|
||||
|
||||
/// Returns only origin-allowed tools whose capability is in `capabilities`.
|
||||
/// An empty set exposes no tools; filtering can never broaden policy access.
|
||||
#[must_use]
|
||||
pub fn tools_for_capability_set(
|
||||
&self,
|
||||
context: &PolicyRequestContext,
|
||||
now: u64,
|
||||
capabilities: &BTreeSet<Capability>,
|
||||
) -> Vec<ToolDefinition> {
|
||||
self.tools_for_capabilities(context, now, Some(capabilities))
|
||||
}
|
||||
|
||||
fn tools_for_capabilities(
|
||||
&self,
|
||||
context: &PolicyRequestContext,
|
||||
now: u64,
|
||||
capabilities: Option<&BTreeSet<Capability>>,
|
||||
) -> Vec<ToolDefinition> {
|
||||
if let OriginKind::InternalScheduler(id) = &context.origin.0 {
|
||||
let state = lock(&self.state);
|
||||
let Some(grant) = state.scheduler_grants.get(id) else {
|
||||
@@ -845,7 +866,10 @@ impl PolicyGateway {
|
||||
return self
|
||||
.tools
|
||||
.get(&grant.tool)
|
||||
.filter(|tool| origin_allows(tool, OriginClass::InternalScheduler))
|
||||
.filter(|tool| {
|
||||
origin_allows(tool, OriginClass::InternalScheduler)
|
||||
&& capabilities.is_none_or(|allowed| allowed.contains(&tool.capability))
|
||||
})
|
||||
.map(|tool| vec![tool.definition.clone()])
|
||||
.unwrap_or_default();
|
||||
}
|
||||
@@ -854,7 +878,10 @@ impl PolicyGateway {
|
||||
};
|
||||
self.tools
|
||||
.values()
|
||||
.filter(|tool| origin_allows(tool, classified.origin))
|
||||
.filter(|tool| {
|
||||
origin_allows(tool, classified.origin)
|
||||
&& capabilities.is_none_or(|allowed| allowed.contains(&tool.capability))
|
||||
})
|
||||
.map(|tool| tool.definition.clone())
|
||||
.collect()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user