Files
agent-bounty-protocol/packages/agent-sdk/src/client.ts
OG T 752a4a45d7
Some checks failed
Deploy to 110 WOOO Server / deploy (push) Failing after 8s
feat: Enhance login page UI with delayed redirect instead of transparent 307
2026-06-08 18:37:35 +08:00

41 lines
1.2 KiB
TypeScript

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<string, string | number | boolean | undefined> | 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;
});
}
}