@openclaw/cloudflare 2026.10.5-beta.4 → 2026.10.10-beta.1
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/s3-backend.js +66 -9
- package/package.json +4 -4
package/dist/s3-backend.js
CHANGED
|
@@ -3,7 +3,27 @@ import { AbortMultipartUploadCommand, CompleteMultipartUploadCommand, CreateMult
|
|
|
3
3
|
//#region extensions/cloudflare/s3-backend.ts
|
|
4
4
|
const PART_BYTES = 67108864;
|
|
5
5
|
const MAX_PARTS = 1e4;
|
|
6
|
+
const DOWNLOAD_RETRIES_PER_PART = 8;
|
|
6
7
|
var R2StorageError = class extends Error {};
|
|
8
|
+
function downloadRetryReason(error) {
|
|
9
|
+
if (error instanceof S3ServiceException) {
|
|
10
|
+
const code = error.$metadata.httpStatusCode;
|
|
11
|
+
return code === 500 || code === 502 || code === 503 || code === 504 ? `HTTP ${code}` : void 0;
|
|
12
|
+
}
|
|
13
|
+
if (error instanceof Error) {
|
|
14
|
+
const code = "code" in error ? error.code : error.name;
|
|
15
|
+
if (typeof code === "string" && [
|
|
16
|
+
"ECONNRESET",
|
|
17
|
+
"ETIMEDOUT",
|
|
18
|
+
"ESOCKETTIMEDOUT",
|
|
19
|
+
"ECONNABORTED",
|
|
20
|
+
"EPIPE",
|
|
21
|
+
"ERR_STREAM_PREMATURE_CLOSE",
|
|
22
|
+
"TimeoutError",
|
|
23
|
+
"RequestTimeout"
|
|
24
|
+
].includes(code)) return code;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
7
27
|
function missingObject(error) {
|
|
8
28
|
return error instanceof S3ServiceException && error.name !== "NoSuchBucket" && (error.$metadata.httpStatusCode === 404 || error.name === "NoSuchKey" || error.name === "NotFound");
|
|
9
29
|
}
|
|
@@ -163,26 +183,63 @@ function createR2Backend(settings, client) {
|
|
|
163
183
|
}
|
|
164
184
|
},
|
|
165
185
|
async getObject(key, opts) {
|
|
186
|
+
let offset = 0;
|
|
187
|
+
let size;
|
|
188
|
+
const failed = (error) => {
|
|
189
|
+
const failure = storageError(error, settings, "download");
|
|
190
|
+
const reason = downloadRetryReason(error);
|
|
191
|
+
failure.message += ` Download stopped after ${offset} of ${size ?? "unknown"} bytes (next offset ${offset}${reason ? `; ${reason}` : ""}).`;
|
|
192
|
+
return failure;
|
|
193
|
+
};
|
|
166
194
|
try {
|
|
167
|
-
const
|
|
195
|
+
const target = {
|
|
168
196
|
Bucket: settings.bucket,
|
|
169
197
|
Key: keyFor(key)
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
|
|
198
|
+
};
|
|
199
|
+
const { ETag, ContentLength } = await client.send(new HeadObjectCommand(target), { abortSignal: opts?.signal });
|
|
200
|
+
size = ContentLength;
|
|
201
|
+
if (!ETag || size === void 0 || !Number.isSafeInteger(size) || size < 0) throw new R2StorageError("R2 returned no valid object size or ETag; retry the download.");
|
|
202
|
+
const totalBytes = size;
|
|
173
203
|
return (async function* () {
|
|
174
204
|
try {
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
205
|
+
while (offset < totalBytes) {
|
|
206
|
+
const end = Math.min(offset + PART_BYTES, totalBytes) - 1;
|
|
207
|
+
let retries = 0;
|
|
208
|
+
while (offset <= end) {
|
|
209
|
+
opts?.signal?.throwIfAborted();
|
|
210
|
+
try {
|
|
211
|
+
const result = await client.send(new GetObjectCommand({
|
|
212
|
+
...target,
|
|
213
|
+
Range: `bytes=${offset}-${end}`,
|
|
214
|
+
IfMatch: ETag
|
|
215
|
+
}), { abortSignal: opts?.signal });
|
|
216
|
+
opts?.signal?.throwIfAborted();
|
|
217
|
+
if (!result.Body) throw new R2StorageError("R2 returned no object body; retry the download.");
|
|
218
|
+
const stream = result.Body.transformToWebStream();
|
|
219
|
+
if (result.ETag !== ETag || result.ContentRange !== `bytes ${offset}-${end}/${totalBytes}`) {
|
|
220
|
+
await stream.cancel();
|
|
221
|
+
throw new R2StorageError(result.ETag !== ETag ? "R2 object changed during download; restart the download." : "R2 returned an unexpected byte range; retry the download.");
|
|
222
|
+
}
|
|
223
|
+
for await (const chunk of stream) {
|
|
224
|
+
opts?.signal?.throwIfAborted();
|
|
225
|
+
if (offset + chunk.byteLength > end + 1) throw new R2StorageError("R2 returned more bytes than requested; retry the download.");
|
|
226
|
+
offset += chunk.byteLength;
|
|
227
|
+
yield chunk;
|
|
228
|
+
}
|
|
229
|
+
if (offset <= end) throw Object.assign(/* @__PURE__ */ new Error("Incomplete R2 range"), { code: "ERR_STREAM_PREMATURE_CLOSE" });
|
|
230
|
+
} catch (error) {
|
|
231
|
+
if (error instanceof S3ServiceException && error.$metadata.httpStatusCode === 412) throw new R2StorageError("R2 object changed during download; restart the download.");
|
|
232
|
+
if (opts?.signal?.aborted || !downloadRetryReason(error) || retries++ >= DOWNLOAD_RETRIES_PER_PART) throw error;
|
|
233
|
+
}
|
|
234
|
+
}
|
|
178
235
|
}
|
|
179
236
|
} catch (error) {
|
|
180
|
-
throw
|
|
237
|
+
throw failed(error);
|
|
181
238
|
}
|
|
182
239
|
})();
|
|
183
240
|
} catch (error) {
|
|
184
241
|
if (missingObject(error)) return;
|
|
185
|
-
throw
|
|
242
|
+
throw failed(error);
|
|
186
243
|
}
|
|
187
244
|
},
|
|
188
245
|
async statObject(key, opts) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@openclaw/cloudflare",
|
|
3
|
-
"version": "2026.10.
|
|
3
|
+
"version": "2026.10.10-beta.1",
|
|
4
4
|
"description": "Cloudflare R2 storage provider for OpenClaw.",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -21,10 +21,10 @@
|
|
|
21
21
|
"minHostVersion": ">=2026.9.7"
|
|
22
22
|
},
|
|
23
23
|
"compat": {
|
|
24
|
-
"pluginApi": ">=2026.10.
|
|
24
|
+
"pluginApi": ">=2026.10.10-beta.1"
|
|
25
25
|
},
|
|
26
26
|
"build": {
|
|
27
|
-
"openclawVersion": "2026.10.
|
|
27
|
+
"openclawVersion": "2026.10.10-beta.1"
|
|
28
28
|
},
|
|
29
29
|
"release": {
|
|
30
30
|
"publishToClawHub": true,
|
|
@@ -42,7 +42,7 @@
|
|
|
42
42
|
"assets/activity.svg"
|
|
43
43
|
],
|
|
44
44
|
"peerDependencies": {
|
|
45
|
-
"openclaw": ">=2026.10.
|
|
45
|
+
"openclaw": ">=2026.10.10-beta.1"
|
|
46
46
|
},
|
|
47
47
|
"peerDependenciesMeta": {
|
|
48
48
|
"openclaw": {
|