类 GlobalChatInterceptors

java.lang.Object
com.agentsflex.core.model.chat.GlobalChatInterceptors

public final class GlobalChatInterceptors extends Object
全局聊天拦截器管理器。

该类提供静态方法,用于注册和管理应用于所有 BaseChatModel 实例的全局拦截器。 全局拦截器会在实例级拦截器之前执行,适用于统一的日志、安全、监控等横切关注点。

使用建议

  • 在应用启动阶段(如 Spring 的 @PostConstruct 或 main 方法)注册全局拦截器
  • 避免在运行时动态修改,以确保线程安全和行为一致性
  • 字段详细资料

  • 构造器详细资料

  • 方法详细资料

    • addInterceptor

      public static void addInterceptor(ChatInterceptor interceptor)
      注册一个全局拦截器。

      该拦截器将应用于所有后续创建的 BaseChatModel 实例。

      参数:
      interceptor - 要注册的拦截器,不能为 null
      抛出:
      IllegalArgumentException - 如果 interceptor 为 null
    • addInterceptors

      public static void addInterceptors(List<ChatInterceptor> interceptors)
      批量注册多个全局拦截器。

      拦截器将按列表顺序添加,并在执行时按相同顺序调用。

      参数:
      interceptors - 拦截器列表,不能为 null;列表中元素不能为 null
      抛出:
      IllegalArgumentException - 如果 interceptors 为 null 或包含 null 元素
    • getInterceptors

      获取当前注册的全局拦截器列表的不可变视图。

      该方法供 BaseChatModel 内部使用,返回值不应被外部修改。

      返回:
      不可变的全局拦截器列表
    • clear

      public static void clear()
      清空所有全局拦截器。

      仅用于测试环境,生产环境应避免调用。

    • size

      public static int size()
      获取当前全局拦截器的数量。

      用于诊断或监控。

      返回:
      拦截器数量