001/*
002 *  Copyright (c) 2023-2026, Agents-Flex (fuhai999@gmail.com).
003 *  <p>
004 *  Licensed under the Apache License, Version 2.0 (the "License");
005 *  you may not use this file except in compliance with the License.
006 *  You may obtain a copy of the License at
007 *  <p>
008 *  http://www.apache.org/licenses/LICENSE-2.0
009 *  <p>
010 *  Unless required by applicable law or agreed to in writing, software
011 *  distributed under the License is distributed on an "AS IS" BASIS,
012 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 *  See the License for the specific language governing permissions and
014 *  limitations under the License.
015 */
016package com.agentsflex.core.model.chat.tool;
017
018import java.util.ArrayList;
019import java.util.Collections;
020import java.util.List;
021
022/**
023 * 全局函数调用拦截器注册中心。
024 * <p>
025 * 所有通过 {@link #addInterceptor(ToolInterceptor)} 注册的拦截器,
026 * 将自动应用于所有 {@link ToolExecutor} 实例。
027 */
028public final class GlobalToolInterceptors {
029
030    private static final List<ToolInterceptor> GLOBAL_INTERCEPTORS = new ArrayList<>();
031
032    private GlobalToolInterceptors() {
033    }
034
035    public static void addInterceptor(ToolInterceptor interceptor) {
036        if (interceptor == null) {
037            throw new IllegalArgumentException("Interceptor must not be null");
038        }
039        GLOBAL_INTERCEPTORS.add(interceptor);
040    }
041
042    public static List<ToolInterceptor> getInterceptors() {
043        return Collections.unmodifiableList(GLOBAL_INTERCEPTORS);
044    }
045
046    public static void clear() {
047        GLOBAL_INTERCEPTORS.clear();
048    }
049}