@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.cjs
CHANGED
|
@@ -72,15 +72,18 @@ var HTTPClient = class {
|
|
|
72
72
|
headers;
|
|
73
73
|
timeout;
|
|
74
74
|
maxRetries;
|
|
75
|
+
fetchFn;
|
|
75
76
|
constructor(options) {
|
|
76
77
|
this.baseUrl = options.baseUrl.replace(/\/$/, "");
|
|
77
78
|
this.headers = {
|
|
78
79
|
Authorization: `Bearer ${options.apiKey}`,
|
|
79
80
|
"Content-Type": "application/json",
|
|
80
|
-
"User-Agent": "sonzai-typescript/1.0
|
|
81
|
+
"User-Agent": "sonzai-typescript/1.1.0",
|
|
82
|
+
...options.defaultHeaders
|
|
81
83
|
};
|
|
82
84
|
this.timeout = options.timeout;
|
|
83
85
|
this.maxRetries = options.maxRetries;
|
|
86
|
+
this.fetchFn = options.customFetch ?? fetch;
|
|
84
87
|
}
|
|
85
88
|
async request(method, path, options) {
|
|
86
89
|
const url = this.buildUrl(path, options?.params);
|
|
@@ -90,7 +93,7 @@ var HTTPClient = class {
|
|
|
90
93
|
const controller = new AbortController();
|
|
91
94
|
const timer = setTimeout(() => controller.abort(), this.timeout);
|
|
92
95
|
try {
|
|
93
|
-
const response = await
|
|
96
|
+
const response = await this.fetchFn(url, {
|
|
94
97
|
method,
|
|
95
98
|
headers: this.headers,
|
|
96
99
|
body: options?.body ? JSON.stringify(options.body) : void 0,
|
|
@@ -155,7 +158,7 @@ var HTTPClient = class {
|
|
|
155
158
|
blob = new Blob([data], { type: contentType });
|
|
156
159
|
}
|
|
157
160
|
formData.append("file", blob, fileName);
|
|
158
|
-
const response = await
|
|
161
|
+
const response = await this.fetchFn(url, {
|
|
159
162
|
method: "POST",
|
|
160
163
|
headers: {
|
|
161
164
|
Authorization: this.headers["Authorization"],
|
|
@@ -175,7 +178,7 @@ var HTTPClient = class {
|
|
|
175
178
|
const controller = new AbortController();
|
|
176
179
|
const timer = setTimeout(() => controller.abort(), this.timeout * 10);
|
|
177
180
|
try {
|
|
178
|
-
const response = await
|
|
181
|
+
const response = await this.fetchFn(url, {
|
|
179
182
|
method,
|
|
180
183
|
headers: {
|
|
181
184
|
...this.headers,
|
|
@@ -2335,7 +2338,9 @@ var Sonzai = class {
|
|
|
2335
2338
|
baseUrl,
|
|
2336
2339
|
apiKey,
|
|
2337
2340
|
timeout: config?.timeout ?? DEFAULT_TIMEOUT,
|
|
2338
|
-
maxRetries: config?.maxRetries ?? DEFAULT_MAX_RETRIES
|
|
2341
|
+
maxRetries: config?.maxRetries ?? DEFAULT_MAX_RETRIES,
|
|
2342
|
+
defaultHeaders: config?.defaultHeaders,
|
|
2343
|
+
customFetch: config?.customFetch
|
|
2339
2344
|
});
|
|
2340
2345
|
this.agents = new Agents(this.http);
|
|
2341
2346
|
this.knowledge = new Knowledge(this.http);
|