Skip to main content

FocusManager

Struct FocusManager 

Source
pub struct FocusManager {
    pub current_focus_id: Option<String>,
    pub foci: HashMap<String, FocusPoint>,
    pub focus_history: Vec<String>,
    pub config: FocusConfig,
    pub focus_stack: Vec<String>,
    pub active_foci: HashSet<String>,
    pub focus_graph: HashMap<String, Vec<(String, f32)>>,
    pub focus_tree: HashMap<String, Vec<String>>,
    pub relevance_cache: HashMap<String, HashMap<String, f32>>,
    pub cache_capacity: usize,
    pub hardcode_config: HardcodeConfig,
}
Expand description

聚焦点管理器

Fields§

§current_focus_id: Option<String>

当前活跃的聚焦点 ID

§foci: HashMap<String, FocusPoint>

所有聚焦点(ID -> FocusPoint)

§focus_history: Vec<String>

聚焦点历史(按时间排序)

§config: FocusConfig

配置

§focus_stack: Vec<String>

焦点栈(支持多焦点并行跟踪) 第一个元素是主焦点,后续是次要焦点

§active_foci: HashSet<String>

活跃焦点集合(当前正在处理的多个焦点)

§focus_graph: HashMap<String, Vec<(String, f32)>>

焦点关联图(知识图谱) key: focus_id, value: [(related_focus_id, strength)]

§focus_tree: HashMap<String, Vec<String>>

焦点树(层次化结构) key: parent_focus_id, value: children_focus_ids

§relevance_cache: HashMap<String, HashMap<String, f32>>

相关性缓存(LRU) key: user_input_hash, value: {focus_id: relevance}

§cache_capacity: usize

缓存最大容量

§hardcode_config: HardcodeConfig

硬编码配置

Implementations§

Source§

impl FocusManager

Source

pub fn new() -> Self

Source

pub fn current_focus(&self) -> Option<&FocusPoint>

获取当前聚焦点

Source

pub fn current_focus_mut(&mut self) -> Option<&mut FocusPoint>

获取当前聚焦点的可变引用

Source

pub fn add_focus(&mut self, focus: FocusPoint)

添加新聚焦点

Source

pub fn switch_focus(&mut self, focus_id: &str) -> Option<()>

切换聚焦点

Source

pub fn calculate_relevance(&self, user_input: &str) -> HashMap<String, f32>

计算用户输入与各聚焦点的相关性

Source

pub fn should_create_new_focus(&self, user_input: &str) -> bool

判断是否需要创建新聚焦点

Source

pub fn get_most_relevant_focus(&self, user_input: &str) -> Option<String>

获取最相关的聚���点

Source

pub fn update_focus_range(&mut self, focus_id: &str, message_index: usize)

更新聚焦点范围

Source

pub fn complete_focus(&mut self, focus_id: &str)

标记聚焦点为已完成

Source

pub fn create_focus_message(&self) -> Option<String>

生成聚焦点提示消息

Source

pub fn primary_focus(&self) -> Option<&FocusPoint>

获取焦点栈顶部的焦点(主焦点)

Source

pub fn get_active_foci(&self) -> Vec<&FocusPoint>

获取所有活跃焦点

Source

pub fn switch_to_previous_focus(&mut self) -> Option<()>

切换回上一个焦点

Source

pub fn activate_multiple_foci(&mut self, focus_ids: &[String])

并行激活多个焦点

Source

pub fn add_focus_transition( &mut self, from_id: &str, to_id: &str, strength: f32, )

添加焦点切换关联

唤醒相关焦点

获取最相关的焦点(根据关联图)

Source

pub fn split_focus(&mut self, parent_id: &str, child: FocusPoint)

分裂焦点(创建子焦点)

Source

pub fn merge_focus_to_parent(&mut self, parent_id: &str, child_id: &str)

合并子焦点到父焦点

Source

pub fn get_focus_tree_depth(&self, focus_id: &str) -> usize

获取焦点树深度

Source

pub fn record_negative_feedback(&mut self, focus_id: &str, message_index: usize)

记录负面反馈

Source

pub fn record_positive_feedback(&mut self, focus_id: &str, message_index: usize)

记录正面反馈

Source

pub fn predict_next_focus(&self) -> Option<String>

预测下一个焦点

Source

pub fn predict_by_keywords(&self, keywords: &[String]) -> Option<String>

基于关键词相似度预测焦点

Source

pub fn get_cached_relevance( &mut self, user_input: &str, ) -> Option<HashMap<String, f32>>

从缓存获取相关性

Source

pub fn cache_relevance( &mut self, user_input: &str, relevance: HashMap<String, f32>, )

缓存相关性计算结果

Source

pub fn update_active_relevance( &mut self, user_input: &str, ) -> HashMap<String, f32>

只更新活跃焦点的相关性

Source

pub fn calculate_relevance_with_decay( &self, user_input: &str, ) -> HashMap<String, f32>

使用有效重要性计算相关性(考虑时间衰减)

Trait Implementations§

Source§

impl Clone for FocusManager

Source§

fn clone(&self) -> FocusManager

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for FocusManager

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'de> Deserialize<'de> for FocusManager

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Serialize for FocusManager

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more