package com.gzzm.lobster.tool;

import com.gzzm.lobster.common.LobsterException;
import com.gzzm.lobster.llm.CancelReason;

/**
 * ToolCancelledException —— 工具被取消 / Thrown when tool execution is cancelled.
 *
 * <p>两种触发源：
 * <ul>
 *   <li>run 级 {@link com.gzzm.lobster.runtime.RunContext#cancel cancel} 置位
 *       —— {@code ToolExecutorDispatcher} 在调度前或工具内部 poll 时检测</li>
 *   <li>工具本身执行超时 —— dispatcher 的 {@code Future.get(timeoutMs)} 触发</li>
 * </ul>
 *
 * <p>code 固定 {@code "tool.cancelled"}；携带 {@link CancelReason} 让 run 主循环
 * 能沿用原因分类决定要不要 fallback。
 */
public class ToolCancelledException extends LobsterException {

    private static final long serialVersionUID = 1L;

    private final CancelReason reason;

    public ToolCancelledException(CancelReason reason, String message) {
        super("tool.cancelled", message == null ? ("tool cancelled: " + reason) : message);
        this.reason = reason == null ? CancelReason.USER : reason;
    }

    public CancelReason getReason() { return reason; }
}
