@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/CHANGELOG.md
CHANGED
|
@@ -5,6 +5,34 @@ All notable changes to the Declaw TypeScript / JavaScript SDK are documented in
|
|
|
5
5
|
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
|
|
6
6
|
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
7
7
|
|
|
8
|
+
## [1.1.3]
|
|
9
|
+
|
|
10
|
+
### Changed
|
|
11
|
+
|
|
12
|
+
- **Higher-concurrency HTTP dispatcher on Node.** The SDK now installs a
|
|
13
|
+
module-level `undici.Agent` (128 connections per origin, keep-alive
|
|
14
|
+
tuned) on first use under Node, so callers fanning out many concurrent
|
|
15
|
+
requests are no longer capped by undici's default 10 connections per
|
|
16
|
+
origin. On runtimes that don't ship `undici` (browsers, Cloudflare
|
|
17
|
+
Workers, Deno) the dynamic import silently no-ops and the platform's
|
|
18
|
+
native `fetch` is used unchanged. Opt out with
|
|
19
|
+
`DECLAW_SDK_DISABLE_DISPATCHER=1` if you bring your own dispatcher.
|
|
20
|
+
`undici` is declared as an `optionalDependency`.
|
|
21
|
+
|
|
22
|
+
## [1.1.2]
|
|
23
|
+
|
|
24
|
+
### Fixed
|
|
25
|
+
|
|
26
|
+
- **Binary-safe `files.read`.** `sandbox.files.read(path, { format: "bytes" })`
|
|
27
|
+
now returns a `Uint8Array` with the raw bytes. Previously the
|
|
28
|
+
`format` option was silently ignored: every read went through the
|
|
29
|
+
`text/plain` accept path and was UTF-8 decoded, so any byte with the
|
|
30
|
+
high bit set collapsed to the replacement character `U+FFFD` and the
|
|
31
|
+
buffer came back short of the real file length. Binary writes were
|
|
32
|
+
already routed through `PUT /files/raw` (1.0.1); this patch closes
|
|
33
|
+
the read side so PNGs, compressed archives, and other non-text blobs
|
|
34
|
+
round-trip unmodified.
|
|
35
|
+
|
|
8
36
|
## [1.1.1]
|
|
9
37
|
|
|
10
38
|
### Changed
|
package/dist/index.cjs
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
2
3
|
var __defProp = Object.defineProperty;
|
|
3
4
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
5
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
5
7
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
8
|
var __export = (target, all) => {
|
|
7
9
|
for (var name in all)
|
|
@@ -15,6 +17,14 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
15
17
|
}
|
|
16
18
|
return to;
|
|
17
19
|
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
18
28
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
29
|
|
|
20
30
|
// src/index.ts
|
|
@@ -223,6 +233,31 @@ var CommandExitError = class extends SandboxError {
|
|
|
223
233
|
};
|
|
224
234
|
|
|
225
235
|
// src/api/client.ts
|
|
236
|
+
var _dispatcherPromise;
|
|
237
|
+
function getDispatcher() {
|
|
238
|
+
if (_dispatcherPromise) return _dispatcherPromise;
|
|
239
|
+
_dispatcherPromise = (async () => {
|
|
240
|
+
try {
|
|
241
|
+
if (typeof process === "undefined" || !process.versions?.node) {
|
|
242
|
+
return void 0;
|
|
243
|
+
}
|
|
244
|
+
if (process.env.DECLAW_SDK_DISABLE_DISPATCHER) {
|
|
245
|
+
return void 0;
|
|
246
|
+
}
|
|
247
|
+
const undici = await import("undici");
|
|
248
|
+
return new undici.Agent({
|
|
249
|
+
connections: 128,
|
|
250
|
+
keepAliveTimeout: 3e4,
|
|
251
|
+
keepAliveMaxTimeout: 6e4,
|
|
252
|
+
pipelining: 1,
|
|
253
|
+
connect: { keepAlive: true, keepAliveInitialDelay: 5e3 }
|
|
254
|
+
});
|
|
255
|
+
} catch {
|
|
256
|
+
return void 0;
|
|
257
|
+
}
|
|
258
|
+
})();
|
|
259
|
+
return _dispatcherPromise;
|
|
260
|
+
}
|
|
226
261
|
var STATUS_ERROR_MAP = {
|
|
227
262
|
401: AuthenticationError,
|
|
228
263
|
403: AuthenticationError,
|
|
@@ -246,6 +281,12 @@ var ApiClient = class {
|
|
|
246
281
|
async get(path, opts) {
|
|
247
282
|
return this.requestWithRetry("GET", path, opts);
|
|
248
283
|
}
|
|
284
|
+
/** Send a GET request and return the response body as raw bytes. */
|
|
285
|
+
async getBytes(path, opts) {
|
|
286
|
+
const response = await this.requestWithRetry("GET", path, opts, true);
|
|
287
|
+
const buf = await response.arrayBuffer();
|
|
288
|
+
return new Uint8Array(buf);
|
|
289
|
+
}
|
|
249
290
|
/** Send a POST request and return parsed JSON. */
|
|
250
291
|
async post(path, opts) {
|
|
251
292
|
return this.requestWithRetry("POST", path, opts);
|
|
@@ -327,12 +368,15 @@ var ApiClient = class {
|
|
|
327
368
|
signals.push(AbortSignal.timeout(timeoutMs));
|
|
328
369
|
}
|
|
329
370
|
const signal = signals.length === 1 ? signals[0] : AbortSignal.any(signals);
|
|
330
|
-
const
|
|
371
|
+
const dispatcher = await getDispatcher();
|
|
372
|
+
const fetchOpts = {
|
|
331
373
|
method,
|
|
332
374
|
headers,
|
|
333
375
|
body: fetchBody,
|
|
334
376
|
signal
|
|
335
|
-
}
|
|
377
|
+
};
|
|
378
|
+
if (dispatcher) fetchOpts.dispatcher = dispatcher;
|
|
379
|
+
const response = await fetch(url, fetchOpts);
|
|
336
380
|
if (response.status >= 500 && attempt < this.maxRetries - 1) {
|
|
337
381
|
await this.delay(attempt);
|
|
338
382
|
continue;
|
|
@@ -1370,15 +1414,18 @@ var Filesystem = class {
|
|
|
1370
1414
|
this.sandboxId = sandboxId;
|
|
1371
1415
|
this.client = client;
|
|
1372
1416
|
}
|
|
1373
|
-
/**
|
|
1374
|
-
* Read a file's contents as a string.
|
|
1375
|
-
*
|
|
1376
|
-
* @param path - Absolute path to the file.
|
|
1377
|
-
* @param opts - Optional user and request timeout.
|
|
1378
|
-
* @returns The file contents as a string.
|
|
1379
|
-
*/
|
|
1380
1417
|
async read(path, opts) {
|
|
1381
1418
|
const user = opts?.user ?? DEFAULT_USER;
|
|
1419
|
+
if (opts?.format === "bytes") {
|
|
1420
|
+
return this.client.getBytes(
|
|
1421
|
+
`/sandboxes/${this.sandboxId}/files`,
|
|
1422
|
+
{
|
|
1423
|
+
params: { path, username: user },
|
|
1424
|
+
headers: { "Accept": "application/octet-stream" },
|
|
1425
|
+
timeout: opts?.requestTimeout
|
|
1426
|
+
}
|
|
1427
|
+
);
|
|
1428
|
+
}
|
|
1382
1429
|
const result = await this.client.get(
|
|
1383
1430
|
`/sandboxes/${this.sandboxId}/files`,
|
|
1384
1431
|
{
|