import axios, { AxiosResponse, InternalAxiosRequestConfig } from 'axios';
import { getToken } from '@/utils/auth';

// 创建 axios 实例
const service = axios.create({
  baseURL: '/aiChat',
  timeout: 1000 * 60 * 10,
  transitional: {
    // 超时错误更明确
    clarifyTimeoutError: true
  }
});

service.interceptors.request.use((config: InternalAxiosRequestConfig) => {
  if (getToken()) {
    config.headers['Authorization'] = 'Bearer ' + getToken();
  }
  config.headers['clientid'] = import.meta.env.VITE_APP_CLIENT_ID;
  return config;
});

// 导出 axios 实例
export default service;
