qualia_core_db/identity/profiles.rs
1use crate::llm_agent::AgentBackend;
2use crate::webizen::SlgOpcode;
3
4/// A declarative allow-list that constrains what the LLM and Webizen VM
5/// are permitted to do within a given session or resource context.
6///
7/// Profiles are identified by a q_hash of their logical name
8/// (e.g. `q_hash("profile:health")`) and are referenced from
9/// `McpIntentFrame::active_profile_id`.
10#[derive(Debug, Clone)]
11pub struct CapabilityProfile {
12 /// Stable identity hash — e.g. `q_hash("profile:phi3-mini-edge")`.
13 pub profile_id: u64,
14
15 /// If non-empty, acts as an allow-list mask over `CAPABILITY_DESCRIPTORS`.
16 /// Only the listed `SlgOpcode` variants may be dispatched in this session.
17 /// An empty vec means no engine restrictions apply at the profile layer.
18 pub active_engines: Vec<SlgOpcode>,
19
20 /// Ontology namespace hashes actively mapped into the LLM context window
21 /// (e.g. `q_hash("namespace:Bio2RDF")`).
22 pub loaded_ontologies: Vec<u64>,
23
24 /// Preferred inference backend for this profile.
25 pub preferred_backend: AgentBackend,
26
27 /// If non-empty, any LLM intent declared outside this set is instantly
28 /// denied by the Webizen VM before the model is invoked.
29 pub permitted_intent_frames: Vec<u64>,
30}
31
32impl CapabilityProfile {
33 /// Returns `true` if `opcode` is permitted by this profile's engine allow-list.
34 pub fn allows_engine(&self, opcode: &SlgOpcode) -> bool {
35 if self.active_engines.is_empty() {
36 return true;
37 }
38 self.active_engines.contains(opcode)
39 }
40
41 /// Returns `true` if `intent_hash` is an allowed intent frame.
42 pub fn allows_intent(&self, intent_hash: u64) -> bool {
43 if self.permitted_intent_frames.is_empty() {
44 return true;
45 }
46 self.permitted_intent_frames.contains(&intent_hash)
47 }
48
49 /// Returns `true` if the requested ontology namespace is actively loaded.
50 pub fn has_ontology(&self, namespace_hash: u64) -> bool {
51 self.loaded_ontologies.contains(&namespace_hash)
52 }
53}