@declaw/sdk 1.1.1 → 1.1.3
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/CHANGELOG.md +28 -0
- package/dist/index.cjs +56 -9
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +16 -3
- package/dist/index.d.ts +16 -3
- package/dist/index.js +46 -9
- package/dist/index.js.map +1 -1
- package/package.json +4 -1
package/dist/index.d.cts
CHANGED
|
@@ -55,6 +55,8 @@ declare class ApiClient {
|
|
|
55
55
|
});
|
|
56
56
|
/** Send a GET request and return parsed JSON. */
|
|
57
57
|
get(path: string, opts?: RequestOpts): Promise<unknown>;
|
|
58
|
+
/** Send a GET request and return the response body as raw bytes. */
|
|
59
|
+
getBytes(path: string, opts?: RequestOpts): Promise<Uint8Array>;
|
|
58
60
|
/** Send a POST request and return parsed JSON. */
|
|
59
61
|
post(path: string, opts?: RequestOpts): Promise<unknown>;
|
|
60
62
|
/** Send a PATCH request and return parsed JSON. */
|
|
@@ -697,16 +699,27 @@ declare class Filesystem {
|
|
|
697
699
|
private readonly client;
|
|
698
700
|
constructor(sandboxId: string, client: ApiClient);
|
|
699
701
|
/**
|
|
700
|
-
* Read a file's contents
|
|
702
|
+
* Read a file's contents.
|
|
703
|
+
*
|
|
704
|
+
* Default returns the content as a string. Pass `{ format: "bytes" }`
|
|
705
|
+
* to get a `Uint8Array` for binary-safe reads — the SDK negotiates
|
|
706
|
+
* `application/octet-stream` end-to-end so high-bit bytes survive the
|
|
707
|
+
* round trip.
|
|
701
708
|
*
|
|
702
709
|
* @param path - Absolute path to the file.
|
|
703
|
-
* @param opts - Optional user and request timeout.
|
|
704
|
-
* @returns The file contents as a string.
|
|
710
|
+
* @param opts - Optional format, user, and request timeout.
|
|
711
|
+
* @returns The file contents as a string, or Uint8Array when format="bytes".
|
|
705
712
|
*/
|
|
706
713
|
read(path: string, opts?: {
|
|
714
|
+
format?: 'text';
|
|
707
715
|
user?: string;
|
|
708
716
|
requestTimeout?: number;
|
|
709
717
|
}): Promise<string>;
|
|
718
|
+
read(path: string, opts: {
|
|
719
|
+
format: 'bytes';
|
|
720
|
+
user?: string;
|
|
721
|
+
requestTimeout?: number;
|
|
722
|
+
}): Promise<Uint8Array>;
|
|
710
723
|
/**
|
|
711
724
|
* Write data to a file.
|
|
712
725
|
*
|
package/dist/index.d.ts
CHANGED
|
@@ -55,6 +55,8 @@ declare class ApiClient {
|
|
|
55
55
|
});
|
|
56
56
|
/** Send a GET request and return parsed JSON. */
|
|
57
57
|
get(path: string, opts?: RequestOpts): Promise<unknown>;
|
|
58
|
+
/** Send a GET request and return the response body as raw bytes. */
|
|
59
|
+
getBytes(path: string, opts?: RequestOpts): Promise<Uint8Array>;
|
|
58
60
|
/** Send a POST request and return parsed JSON. */
|
|
59
61
|
post(path: string, opts?: RequestOpts): Promise<unknown>;
|
|
60
62
|
/** Send a PATCH request and return parsed JSON. */
|
|
@@ -697,16 +699,27 @@ declare class Filesystem {
|
|
|
697
699
|
private readonly client;
|
|
698
700
|
constructor(sandboxId: string, client: ApiClient);
|
|
699
701
|
/**
|
|
700
|
-
* Read a file's contents
|
|
702
|
+
* Read a file's contents.
|
|
703
|
+
*
|
|
704
|
+
* Default returns the content as a string. Pass `{ format: "bytes" }`
|
|
705
|
+
* to get a `Uint8Array` for binary-safe reads — the SDK negotiates
|
|
706
|
+
* `application/octet-stream` end-to-end so high-bit bytes survive the
|
|
707
|
+
* round trip.
|
|
701
708
|
*
|
|
702
709
|
* @param path - Absolute path to the file.
|
|
703
|
-
* @param opts - Optional user and request timeout.
|
|
704
|
-
* @returns The file contents as a string.
|
|
710
|
+
* @param opts - Optional format, user, and request timeout.
|
|
711
|
+
* @returns The file contents as a string, or Uint8Array when format="bytes".
|
|
705
712
|
*/
|
|
706
713
|
read(path: string, opts?: {
|
|
714
|
+
format?: 'text';
|
|
707
715
|
user?: string;
|
|
708
716
|
requestTimeout?: number;
|
|
709
717
|
}): Promise<string>;
|
|
718
|
+
read(path: string, opts: {
|
|
719
|
+
format: 'bytes';
|
|
720
|
+
user?: string;
|
|
721
|
+
requestTimeout?: number;
|
|
722
|
+
}): Promise<Uint8Array>;
|
|
710
723
|
/**
|
|
711
724
|
* Write data to a file.
|
|
712
725
|
*
|
package/dist/index.js
CHANGED
|
@@ -116,6 +116,31 @@ var CommandExitError = class extends SandboxError {
|
|
|
116
116
|
};
|
|
117
117
|
|
|
118
118
|
// src/api/client.ts
|
|
119
|
+
var _dispatcherPromise;
|
|
120
|
+
function getDispatcher() {
|
|
121
|
+
if (_dispatcherPromise) return _dispatcherPromise;
|
|
122
|
+
_dispatcherPromise = (async () => {
|
|
123
|
+
try {
|
|
124
|
+
if (typeof process === "undefined" || !process.versions?.node) {
|
|
125
|
+
return void 0;
|
|
126
|
+
}
|
|
127
|
+
if (process.env.DECLAW_SDK_DISABLE_DISPATCHER) {
|
|
128
|
+
return void 0;
|
|
129
|
+
}
|
|
130
|
+
const undici = await import("undici");
|
|
131
|
+
return new undici.Agent({
|
|
132
|
+
connections: 128,
|
|
133
|
+
keepAliveTimeout: 3e4,
|
|
134
|
+
keepAliveMaxTimeout: 6e4,
|
|
135
|
+
pipelining: 1,
|
|
136
|
+
connect: { keepAlive: true, keepAliveInitialDelay: 5e3 }
|
|
137
|
+
});
|
|
138
|
+
} catch {
|
|
139
|
+
return void 0;
|
|
140
|
+
}
|
|
141
|
+
})();
|
|
142
|
+
return _dispatcherPromise;
|
|
143
|
+
}
|
|
119
144
|
var STATUS_ERROR_MAP = {
|
|
120
145
|
401: AuthenticationError,
|
|
121
146
|
403: AuthenticationError,
|
|
@@ -139,6 +164,12 @@ var ApiClient = class {
|
|
|
139
164
|
async get(path, opts) {
|
|
140
165
|
return this.requestWithRetry("GET", path, opts);
|
|
141
166
|
}
|
|
167
|
+
/** Send a GET request and return the response body as raw bytes. */
|
|
168
|
+
async getBytes(path, opts) {
|
|
169
|
+
const response = await this.requestWithRetry("GET", path, opts, true);
|
|
170
|
+
const buf = await response.arrayBuffer();
|
|
171
|
+
return new Uint8Array(buf);
|
|
172
|
+
}
|
|
142
173
|
/** Send a POST request and return parsed JSON. */
|
|
143
174
|
async post(path, opts) {
|
|
144
175
|
return this.requestWithRetry("POST", path, opts);
|
|
@@ -220,12 +251,15 @@ var ApiClient = class {
|
|
|
220
251
|
signals.push(AbortSignal.timeout(timeoutMs));
|
|
221
252
|
}
|
|
222
253
|
const signal = signals.length === 1 ? signals[0] : AbortSignal.any(signals);
|
|
223
|
-
const
|
|
254
|
+
const dispatcher = await getDispatcher();
|
|
255
|
+
const fetchOpts = {
|
|
224
256
|
method,
|
|
225
257
|
headers,
|
|
226
258
|
body: fetchBody,
|
|
227
259
|
signal
|
|
228
|
-
}
|
|
260
|
+
};
|
|
261
|
+
if (dispatcher) fetchOpts.dispatcher = dispatcher;
|
|
262
|
+
const response = await fetch(url, fetchOpts);
|
|
229
263
|
if (response.status >= 500 && attempt < this.maxRetries - 1) {
|
|
230
264
|
await this.delay(attempt);
|
|
231
265
|
continue;
|
|
@@ -1263,15 +1297,18 @@ var Filesystem = class {
|
|
|
1263
1297
|
this.sandboxId = sandboxId;
|
|
1264
1298
|
this.client = client;
|
|
1265
1299
|
}
|
|
1266
|
-
/**
|
|
1267
|
-
* Read a file's contents as a string.
|
|
1268
|
-
*
|
|
1269
|
-
* @param path - Absolute path to the file.
|
|
1270
|
-
* @param opts - Optional user and request timeout.
|
|
1271
|
-
* @returns The file contents as a string.
|
|
1272
|
-
*/
|
|
1273
1300
|
async read(path, opts) {
|
|
1274
1301
|
const user = opts?.user ?? DEFAULT_USER;
|
|
1302
|
+
if (opts?.format === "bytes") {
|
|
1303
|
+
return this.client.getBytes(
|
|
1304
|
+
`/sandboxes/${this.sandboxId}/files`,
|
|
1305
|
+
{
|
|
1306
|
+
params: { path, username: user },
|
|
1307
|
+
headers: { "Accept": "application/octet-stream" },
|
|
1308
|
+
timeout: opts?.requestTimeout
|
|
1309
|
+
}
|
|
1310
|
+
);
|
|
1311
|
+
}
|
|
1275
1312
|
const result = await this.client.get(
|
|
1276
1313
|
`/sandboxes/${this.sandboxId}/files`,
|
|
1277
1314
|
{
|