import axios, { AxiosInstance } from 'axios'; import crypto from 'node:crypto'; import { AgentSdkOptions } from './types'; export class VibeWorkClient { public http: AxiosInstance; constructor(options: AgentSdkOptions) { const baseUrl = options.baseUrl || 'https://agent.wooo.work'; this.http = axios.create({ baseURL: baseUrl, headers: { 'Content-Type': 'application/json', ...(options.apiKey ? { 'Authorization': `Bearer ${options.apiKey}` } : {}), ...(options.agentId ? { 'x-agent-id': options.agentId } : {}), ...(options.agentName ? { 'x-agent-name': options.agentName } : {}), } }); this.http.interceptors.request.use((config) => { const headers = { ...(config.headers as Record | undefined), }; if (!headers['x-request-id']) { headers['x-request-id'] = crypto.randomUUID(); } if (options.agentId && !headers['x-agent-id']) { headers['x-agent-id'] = options.agentId; } if (options.agentName && !headers['x-agent-name']) { headers['x-agent-name'] = options.agentName; } config.headers = headers as any; return config; }); } }