@sonzai-labs/agents 1.0.13 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +10 -5
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +5 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.js +10 -5
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.cts
CHANGED
|
@@ -3,12 +3,15 @@ interface HTTPClientOptions {
|
|
|
3
3
|
apiKey: string;
|
|
4
4
|
timeout: number;
|
|
5
5
|
maxRetries: number;
|
|
6
|
+
defaultHeaders?: Record<string, string>;
|
|
7
|
+
customFetch?: typeof fetch;
|
|
6
8
|
}
|
|
7
9
|
declare class HTTPClient {
|
|
8
10
|
private readonly baseUrl;
|
|
9
11
|
private readonly headers;
|
|
10
12
|
private readonly timeout;
|
|
11
13
|
private readonly maxRetries;
|
|
14
|
+
private readonly fetchFn;
|
|
12
15
|
constructor(options: HTTPClientOptions);
|
|
13
16
|
request<T = unknown>(method: string, path: string, options?: {
|
|
14
17
|
body?: Record<string, unknown>;
|
|
@@ -1297,6 +1300,8 @@ interface SonzaiConfig {
|
|
|
1297
1300
|
baseUrl?: string;
|
|
1298
1301
|
timeout?: number;
|
|
1299
1302
|
maxRetries?: number;
|
|
1303
|
+
defaultHeaders?: Record<string, string>;
|
|
1304
|
+
customFetch?: typeof fetch;
|
|
1300
1305
|
}
|
|
1301
1306
|
interface AgentListOptions {
|
|
1302
1307
|
pageSize?: number;
|
package/dist/index.d.ts
CHANGED
|
@@ -3,12 +3,15 @@ interface HTTPClientOptions {
|
|
|
3
3
|
apiKey: string;
|
|
4
4
|
timeout: number;
|
|
5
5
|
maxRetries: number;
|
|
6
|
+
defaultHeaders?: Record<string, string>;
|
|
7
|
+
customFetch?: typeof fetch;
|
|
6
8
|
}
|
|
7
9
|
declare class HTTPClient {
|
|
8
10
|
private readonly baseUrl;
|
|
9
11
|
private readonly headers;
|
|
10
12
|
private readonly timeout;
|
|
11
13
|
private readonly maxRetries;
|
|
14
|
+
private readonly fetchFn;
|
|
12
15
|
constructor(options: HTTPClientOptions);
|
|
13
16
|
request<T = unknown>(method: string, path: string, options?: {
|
|
14
17
|
body?: Record<string, unknown>;
|
|
@@ -1297,6 +1300,8 @@ interface SonzaiConfig {
|
|
|
1297
1300
|
baseUrl?: string;
|
|
1298
1301
|
timeout?: number;
|
|
1299
1302
|
maxRetries?: number;
|
|
1303
|
+
defaultHeaders?: Record<string, string>;
|
|
1304
|
+
customFetch?: typeof fetch;
|
|
1300
1305
|
}
|
|
1301
1306
|
interface AgentListOptions {
|
|
1302
1307
|
pageSize?: number;
|
package/dist/index.js
CHANGED
|
@@ -70,15 +70,18 @@ var HTTPClient = class {
|
|
|
70
70
|
headers;
|
|
71
71
|
timeout;
|
|
72
72
|
maxRetries;
|
|
73
|
+
fetchFn;
|
|
73
74
|
constructor(options) {
|
|
74
75
|
this.baseUrl = options.baseUrl.replace(/\/$/, "");
|
|
75
76
|
this.headers = {
|
|
76
77
|
Authorization: `Bearer ${options.apiKey}`,
|
|
77
78
|
"Content-Type": "application/json",
|
|
78
|
-
"User-Agent": "sonzai-typescript/1.0
|
|
79
|
+
"User-Agent": "sonzai-typescript/1.1.0",
|
|
80
|
+
...options.defaultHeaders
|
|
79
81
|
};
|
|
80
82
|
this.timeout = options.timeout;
|
|
81
83
|
this.maxRetries = options.maxRetries;
|
|
84
|
+
this.fetchFn = options.customFetch ?? fetch;
|
|
82
85
|
}
|
|
83
86
|
async request(method, path, options) {
|
|
84
87
|
const url = this.buildUrl(path, options?.params);
|
|
@@ -88,7 +91,7 @@ var HTTPClient = class {
|
|
|
88
91
|
const controller = new AbortController();
|
|
89
92
|
const timer = setTimeout(() => controller.abort(), this.timeout);
|
|
90
93
|
try {
|
|
91
|
-
const response = await
|
|
94
|
+
const response = await this.fetchFn(url, {
|
|
92
95
|
method,
|
|
93
96
|
headers: this.headers,
|
|
94
97
|
body: options?.body ? JSON.stringify(options.body) : void 0,
|
|
@@ -153,7 +156,7 @@ var HTTPClient = class {
|
|
|
153
156
|
blob = new Blob([data], { type: contentType });
|
|
154
157
|
}
|
|
155
158
|
formData.append("file", blob, fileName);
|
|
156
|
-
const response = await
|
|
159
|
+
const response = await this.fetchFn(url, {
|
|
157
160
|
method: "POST",
|
|
158
161
|
headers: {
|
|
159
162
|
Authorization: this.headers["Authorization"],
|
|
@@ -173,7 +176,7 @@ var HTTPClient = class {
|
|
|
173
176
|
const controller = new AbortController();
|
|
174
177
|
const timer = setTimeout(() => controller.abort(), this.timeout * 10);
|
|
175
178
|
try {
|
|
176
|
-
const response = await
|
|
179
|
+
const response = await this.fetchFn(url, {
|
|
177
180
|
method,
|
|
178
181
|
headers: {
|
|
179
182
|
...this.headers,
|
|
@@ -2333,7 +2336,9 @@ var Sonzai = class {
|
|
|
2333
2336
|
baseUrl,
|
|
2334
2337
|
apiKey,
|
|
2335
2338
|
timeout: config?.timeout ?? DEFAULT_TIMEOUT,
|
|
2336
|
-
maxRetries: config?.maxRetries ?? DEFAULT_MAX_RETRIES
|
|
2339
|
+
maxRetries: config?.maxRetries ?? DEFAULT_MAX_RETRIES,
|
|
2340
|
+
defaultHeaders: config?.defaultHeaders,
|
|
2341
|
+
customFetch: config?.customFetch
|
|
2337
2342
|
});
|
|
2338
2343
|
this.agents = new Agents(this.http);
|
|
2339
2344
|
this.knowledge = new Knowledge(this.http);
|