UNPKG

@coze/taro-api

Version:

Official Coze Taro SDK for seamless AI integration into your applications | 扣子官方 Taro SDK,助您轻松集成 AI 能力到应用中

21 lines (20 loc) 702 B
import axios from 'axios'; import { CozeAPI as InnerCozeAPI } from '@coze/api'; export class CozeAPI extends InnerCozeAPI { options; constructor(options) { super({ ...options }); this.options = options; this.axiosInstance = axios.create(); this.axiosInstance.interceptors.request.use(async (config) => { if (this.options.onBeforeAPICall) { const res = (await this.options.onBeforeAPICall(config)) ?? {}; if (res.token) { this.token = res.token; config.headers.Authorization = `Bearer ${res.token}`; } } return config; }); } }