Repository navigation
Expand file tree
/
Copy pathplugin.ts
More file actions
851 lines (768 loc) · 26.9 KB
/
Copy pathplugin.ts
File metadata and controls
851 lines (768 loc) · 26.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
/**
* blomp-swift — OpenClaw plugin for Blomp Cloud Storage (OpenStack Swift)
*
* Blomp specifics:
* - Auth: Keystone v2 → https://authenticate.blomp.com/v2.0/tokens
* - Tenant: storage (fixed for all Blomp accounts)
* - SLO: segments stored inside the same container under .file-segments/
* (Blomp does NOT allow creating extra containers)
*
* Config keys expected in openclaw.config.json ➜ plugins.blomp-swift:
* username string Your Blomp account e-mail
* password string Your Blomp account password
*
* Tools registered:
* blomp_list – list containers, or objects inside a container
* blomp_upload – upload a local file (auto-SLO for files ≥ 1 GiB)
* blomp_download – download an object to a local path
* blomp_delete – delete an object or an entire container
* blomp_upload_slo – explicitly upload as a Static Large Object (chunked)
*/
import * as fs from "fs";
import * as path from "path";
import * as https from "https";
import { IncomingMessage } from "http";
// ─── Types ──────────────────────────────────────────────────────────────────
interface BlompConfig {
username: string;
password: string;
}
interface AuthToken {
token: string;
storageUrl: string;
expiresAt: number; // epoch ms
}
interface ToolResult {
success: boolean;
message: string;
data?: unknown;
}
// ─── Constants ───────────────────────────────────────────────────────────────
const AUTH_URL = "https://authenticate.blomp.com/v2.0/tokens";
const TENANT_NAME = "storage";
const SLO_SEGMENT_SIZE = 1_073_741_824; // 1 GiB per segment
const SLO_AUTO_THRESHOLD = 1_073_741_824; // auto-SLO for files ≥ 1 GiB
const SEGMENT_PREFIX = ".file-segments"; // Blomp stores SLO chunks here
const AUTH_MAX_RETRIES = 4; // total attempts (1 initial + 3 retries)
const AUTH_RETRY_BASE_MS = 500; // base delay for exponential back-off
const HTTP_TIMEOUT_MS = 30_000; // socket inactivity timeout per attempt
const HTTP_MAX_RETRIES = 4; // total attempts for general HTTP calls
const HTTP_RETRY_BASE_MS = 300; // base delay: 300 ms, 600 ms, 1.2 s, …
const DELETE_CONCURRENCY = 16; // max parallel DELETE requests in flight
// ─── Auth cache (in-process, refreshed when within 5 min of expiry) ──────────
let _authCache: AuthToken | null = null;
/** Resolves after `ms` milliseconds. */
function sleep(ms: number): Promise<void> {
return new Promise((resolve) => setTimeout(resolve, ms));
}
/**
* Obtain a valid Keystone v2 token, using the in-process cache when possible.
* On network/server errors the POST is retried up to AUTH_MAX_RETRIES times
* with exponential back-off (500 ms, 1 s, 2 s, …).
* 4xx responses (bad credentials, etc.) are NOT retried — they are re-thrown
* immediately so the caller receives a clear error.
*/
async function getAuth(cfg: BlompConfig): Promise<AuthToken> {
const now = Date.now();
if (_authCache && _authCache.expiresAt - now > 5 * 60 * 1000) {
return _authCache;
}
const body = JSON.stringify({
auth: {
tenantName: TENANT_NAME,
passwordCredentials: {
username: cfg.username,
password: cfg.password,
},
},
});
let lastError: Error | null = null;
for (let attempt = 0; attempt < AUTH_MAX_RETRIES; attempt++) {
if (attempt > 0) {
const delay = AUTH_RETRY_BASE_MS * Math.pow(2, attempt - 1); // 500, 1000, 2000 ms
console.warn(
`[blomp-swift] Auth attempt ${attempt + 1}/${AUTH_MAX_RETRIES} after ${delay} ms (last error: ${lastError?.message})`
);
await sleep(delay);
}
try {
const raw = await httpPost(AUTH_URL, body, {
"Content-Type": "application/json",
});
const json = JSON.parse(raw) as {
access: {
token: { id: string; expires: string };
serviceCatalog: Array<{
type: string;
endpoints: Array<{ publicURL: string }>;
}>;
};
};
const tokenId = json.access.token.id;
const expiresAt = new Date(json.access.token.expires).getTime();
const objectStore = json.access.serviceCatalog.find(
(s) => s.type === "object-store"
);
if (!objectStore || !objectStore.endpoints[0]) {
throw new Error("No object-store endpoint in Blomp service catalog.");
}
const storageUrl = objectStore.endpoints[0].publicURL;
_authCache = { token: tokenId, storageUrl, expiresAt };
return _authCache;
} catch (err) {
const error = err as Error;
// 4xx errors indicate bad credentials or a misconfiguration — no point retrying.
if (error.message.startsWith("HTTP 4")) {
throw new Error(`[blomp-swift] Auth failed (not retrying): ${error.message}`);
}
lastError = error;
// 5xx / network errors fall through to the next retry iteration.
}
}
throw new Error(
`[blomp-swift] Auth failed after ${AUTH_MAX_RETRIES} attempts. Last error: ${lastError?.message}`
);
}
// ─── HTTP helpers ─────────────────────────────────────────────────────────────────────────────
/**
* Returns true for errors worth retrying (network glitches, 5xx).
* 4xx errors mean the request is broken — no retrying will fix them.
*/
function isRetryable(err: Error): boolean {
return !err.message.startsWith("HTTP 4");
}
/**
* Run `fn` up to `maxAttempts` times with exponential back-off.
* Non-retryable (4xx) errors are re-thrown immediately.
*/
async function withRetry<T>(
fn: () => Promise<T>,
maxAttempts: number,
baseDelayMs: number,
label: string
): Promise<T> {
let lastError: Error | null = null;
for (let attempt = 0; attempt < maxAttempts; attempt++) {
if (attempt > 0) {
const delay = baseDelayMs * Math.pow(2, attempt - 1);
console.warn(
`[blomp-swift] ${label}: retry ${attempt}/${maxAttempts - 1} in ${delay} ms (${lastError?.message})`
);
await sleep(delay);
}
try {
return await fn();
} catch (err) {
lastError = err as Error;
if (!isRetryable(lastError)) throw lastError;
}
}
throw new Error(
`[blomp-swift] ${label} failed after ${maxAttempts} attempts: ${lastError?.message}`
);
}
/**
* Single-attempt POST. Rejects on HTTP 4xx/5xx or timeout.
* getAuth supplies its own retry loop on top of this.
*/
function httpPostOnce(
url: string,
body: string,
headers: Record<string, string>
): Promise<string> {
return new Promise((resolve, reject) => {
const u = new URL(url);
const req = https.request(
{
hostname: u.hostname,
port: u.port || 443,
path: u.pathname + u.search,
method: "POST",
headers: { ...headers, "Content-Length": Buffer.byteLength(body) },
timeout: HTTP_TIMEOUT_MS,
},
(res: IncomingMessage) => {
let data = "";
res.on("data", (chunk: Buffer) => (data += chunk));
res.on("end", () => {
if (res.statusCode && res.statusCode >= 400) {
reject(new Error(`HTTP ${res.statusCode}: ${data}`));
} else {
resolve(data);
}
});
}
);
req.on("timeout", () => { req.destroy(new Error("HTTP_TIMEOUT")); });
req.on("error", reject);
req.write(body);
req.end();
});
}
/** POST with automatic retry. */
function httpPost(
url: string,
body: string,
headers: Record<string, string>
): Promise<string> {
return withRetry(
() => httpPostOnce(url, body, headers),
HTTP_MAX_RETRIES,
HTTP_RETRY_BASE_MS,
`POST ${url}`
);
}
/**
* Single-attempt request for small payloads (GET, DELETE, manifest PUT).
* Always resolves — callers inspect res.status. Rejects on network/timeout only.
*/
function httpRequestOnce(
method: string,
url: string,
headers: Record<string, string>,
bodyBuffer?: Buffer
): Promise<{ status: number; body: string; headers: Record<string, string> }> {
return new Promise((resolve, reject) => {
const u = new URL(url);
const req = https.request(
{
hostname: u.hostname,
port: u.port || 443,
path: u.pathname + u.search,
method,
headers: {
...headers,
...(bodyBuffer ? { "Content-Length": bodyBuffer.length.toString() } : {}),
},
timeout: HTTP_TIMEOUT_MS,
},
(res: IncomingMessage) => {
let data = "";
res.on("data", (chunk: Buffer) => (data += chunk));
res.on("end", () => {
resolve({
status: res.statusCode ?? 0,
body: data,
headers: res.headers as Record<string, string>,
});
});
res.on("error", reject);
}
);
req.on("timeout", () => { req.destroy(new Error("HTTP_TIMEOUT")); });
req.on("error", reject);
if (bodyBuffer) req.write(bodyBuffer);
req.end();
});
}
/**
* httpRequest with retry. 5xx responses are thrown so withRetry can catch them;
* 4xx pass through as resolved values so callers handle them without surprises.
*/
async function httpRequest(
method: string,
url: string,
headers: Record<string, string>,
bodyBuffer?: Buffer
): Promise<{ status: number; body: string; headers: Record<string, string> }> {
return withRetry(
async () => {
const res = await httpRequestOnce(method, url, headers, bodyBuffer);
if (res.status >= 500) throw new Error(`HTTP ${res.status}: ${res.body}`);
return res;
},
HTTP_MAX_RETRIES,
HTTP_RETRY_BASE_MS,
`${method} ${url}`
);
}
/**
* Concurrency-limited parallel task runner (zero external dependencies).
* Dispatches up to `limit` tasks simultaneously; collects all results in order,
* wrapping each as { ok: true, value } or { ok: false, error }.
*/
async function pLimit<T>(
tasks: Array<() => Promise<T>>,
limit: number
): Promise<Array<{ ok: true; value: T } | { ok: false; error: Error }>> {
const results: Array<{ ok: true; value: T } | { ok: false; error: Error }> =
new Array(tasks.length);
let nextIndex = 0;
async function worker() {
while (nextIndex < tasks.length) {
const i = nextIndex++;
try {
results[i] = { ok: true, value: await tasks[i]() };
} catch (err) {
results[i] = { ok: false, error: err as Error };
}
}
}
await Promise.all(
Array.from({ length: Math.min(limit, tasks.length) }, worker)
);
return results;
}
function swiftHeaders(token: string, extra: Record<string, string> = {}) {
return { "X-Auth-Token": token, ...extra };
}
/**
* Single-attempt streaming PUT. Pipes `readable` directly into the request
* so no body data is buffered in memory. Rejects on network/timeout errors;
* always resolves on a completed HTTP exchange regardless of status code.
*
* NOTE: Because the readable is consumed on the first attempt, streaming PUTs
* are NOT retried automatically — the caller must recreate the stream if it
* wishes to retry (blompUpload and blompUploadSlo do this via fresh
* fs.createReadStream calls for each segment).
*/
function httpPutStream(
url: string,
headers: Record<string, string>,
readable: NodeJS.ReadableStream
): Promise<{ status: number; etag: string; body: string }> {
return new Promise((resolve, reject) => {
const u = new URL(url);
const req = https.request(
{
hostname: u.hostname,
port: u.port || 443,
path: u.pathname + u.search,
method: "PUT",
headers,
timeout: HTTP_TIMEOUT_MS,
},
(res: IncomingMessage) => {
let body = "";
res.on("data", (chunk: Buffer) => (body += chunk));
res.on("end", () => {
resolve({
status: res.statusCode ?? 0,
etag: (res.headers["etag"] ?? "").replace(/"/g, ""),
body,
});
});
res.on("error", reject);
}
);
req.on("timeout", () => { req.destroy(new Error("HTTP_TIMEOUT")); });
req.on("error", reject);
readable.on("error", reject);
readable.pipe(req);
});
}
// ─── Tool implementations ────────────────────────────────────────────────────
/**
* List containers (no args) or objects inside a container.
*/
async function blompList(
cfg: BlompConfig,
container?: string,
prefix?: string
): Promise<ToolResult> {
const auth = await getAuth(cfg);
const base = container
? `${auth.storageUrl}/${encodeURIComponent(container)}`
: auth.storageUrl;
const qs = new URLSearchParams({ format: "json" });
if (prefix) qs.set("prefix", prefix);
const res = await httpRequest(
"GET",
`${base}?${qs}`,
swiftHeaders(auth.token)
);
if (res.status !== 200) {
return { success: false, message: `List failed: HTTP ${res.status}` };
}
const items = JSON.parse(res.body) as unknown[];
return {
success: true,
message: `Found ${items.length} ${container ? "object(s)" : "container(s)"}.`,
data: items,
};
}
/**
* Upload a local file, streaming directly from disk.
* Automatically promotes to SLO for files ≥ 1 GiB.
*/
async function blompUpload(
cfg: BlompConfig,
localPath: string,
container: string,
objectName?: string
): Promise<ToolResult> {
const resolvedName = objectName ?? path.basename(localPath);
const stat = fs.statSync(localPath);
if (stat.size >= SLO_AUTO_THRESHOLD) {
return blompUploadSlo(cfg, localPath, container, resolvedName);
}
const auth = await getAuth(cfg);
const url = `${auth.storageUrl}/${encodeURIComponent(container)}/${encodeURIComponent(resolvedName)}`;
const res = await httpPutStream(
url,
swiftHeaders(auth.token, {
"Content-Type": "application/octet-stream",
"Content-Length": stat.size.toString(),
}),
fs.createReadStream(localPath)
);
if (res.status === 201 || res.status === 200) {
return {
success: true,
message: `Uploaded '${resolvedName}' to container '${container}' (${stat.size} bytes).`,
};
}
return {
success: false,
message: `Upload failed: HTTP ${res.status} — ${res.body}`,
};
}
/**
* Explicitly upload as a Static Large Object, streaming each segment from disk.
* A ReadStream with start/end byte offsets is used per segment so only one
* segment's worth of data is in flight at a time — no full-file buffer needed.
* Segments are placed in <container>/.file-segments/<objectName>/<partN>
* (Blomp does not allow creating additional containers.)
*/
async function blompUploadSlo(
cfg: BlompConfig,
localPath: string,
container: string,
objectName?: string
): Promise<ToolResult> {
const resolvedName = objectName ?? path.basename(localPath);
const auth = await getAuth(cfg);
const stat = fs.statSync(localPath);
const totalSize = stat.size;
const numSegments = Math.ceil(totalSize / SLO_SEGMENT_SIZE);
const manifest: Array<{ path: string; etag: string; size_bytes: number }> = [];
for (let i = 0; i < numSegments; i++) {
const start = i * SLO_SEGMENT_SIZE;
const end = Math.min(start + SLO_SEGMENT_SIZE, totalSize) - 1; // inclusive
const segSize = end - start + 1;
const segName = `${SEGMENT_PREFIX}/${resolvedName}/${String(i).padStart(8, "0")}`;
const segUrl = `${auth.storageUrl}/${encodeURIComponent(container)}/${encodeURIComponent(segName)}`;
const segStream = fs.createReadStream(localPath, { start, end });
const segRes = await httpPutStream(
segUrl,
swiftHeaders(auth.token, {
"Content-Type": "application/octet-stream",
"Content-Length": segSize.toString(),
}),
segStream
);
if (segRes.status !== 201 && segRes.status !== 200) {
return {
success: false,
message: `Segment ${i} upload failed: HTTP ${segRes.status} — ${segRes.body}`,
};
}
manifest.push({
path: `/${container}/${segName}`,
etag: segRes.etag,
size_bytes: segSize,
});
}
// PUT the SLO manifest (small JSON — keeping as buffer is fine here)
const manifestUrl = `${auth.storageUrl}/${encodeURIComponent(container)}/${encodeURIComponent(resolvedName)}?multipart-manifest=put`;
const manifestBody = Buffer.from(JSON.stringify(manifest));
const mRes = await httpRequest(
"PUT",
manifestUrl,
swiftHeaders(auth.token, {
"Content-Type": "application/json",
"X-Static-Large-Object": "true",
}),
manifestBody
);
if (mRes.status === 201 || mRes.status === 200) {
return {
success: true,
message: `Uploaded '${resolvedName}' as SLO (${numSegments} segments, ${totalSize} bytes total).`,
};
}
return {
success: false,
message: `SLO manifest PUT failed: HTTP ${mRes.status} — ${mRes.body}`,
};
}
/**
* Download an object, streaming directly to disk without buffering in memory.
* Creates any missing parent directories before writing.
*/
async function blompDownload(
cfg: BlompConfig,
container: string,
objectName: string,
localPath: string
): Promise<ToolResult> {
const auth = await getAuth(cfg);
const url = `${auth.storageUrl}/${encodeURIComponent(container)}/${encodeURIComponent(objectName)}`;
const destPath = path.isAbsolute(localPath)
? localPath
: path.join(process.cwd(), localPath);
fs.mkdirSync(path.dirname(destPath), { recursive: true });
return new Promise((resolve) => {
const u = new URL(url);
const options = {
hostname: u.hostname,
port: u.port || 443,
path: u.pathname + u.search,
method: "GET",
headers: swiftHeaders(auth.token),
};
const req = https.request(options, (res: IncomingMessage) => {
if (res.statusCode !== 200) {
// Drain and discard the response body so the socket is released cleanly.
res.resume();
resolve({
success: false,
message: `Download failed: HTTP ${res.statusCode}`,
});
return;
}
const fileStream = fs.createWriteStream(destPath);
res.pipe(fileStream);
fileStream.on("finish", () => {
const bytes = fs.statSync(destPath).size;
resolve({
success: true,
message: `Downloaded '${objectName}' from '${container}' to '${destPath}' (${bytes} bytes).`,
});
});
fileStream.on("error", (err: Error) => {
resolve({
success: false,
message: `Failed to write to '${destPath}': ${err.message}`,
});
});
res.on("error", (err: Error) => {
resolve({
success: false,
message: `Stream error while downloading '${objectName}': ${err.message}`,
});
});
});
req.on("error", (err: Error) => {
resolve({
success: false,
message: `Request error for '${objectName}': ${err.message}`,
});
});
req.end();
});
}
/**
* Delete a single object, or all objects in a container in parallel then
* delete the container itself.
*
* Object deletes run DELETE_CONCURRENCY at a time. Any individual failures
* are collected and reported without aborting the rest of the batch.
*/
async function blompDelete(
cfg: BlompConfig,
container: string,
objectName?: string
): Promise<ToolResult> {
const auth = await getAuth(cfg);
if (objectName) {
const url = `${auth.storageUrl}/${encodeURIComponent(container)}/${encodeURIComponent(objectName)}`;
const res = await httpRequest("DELETE", url, swiftHeaders(auth.token));
if (res.status === 204 || res.status === 200) {
return { success: true, message: `Deleted '${objectName}' from '${container}'.` };
}
return { success: false, message: `Delete failed: HTTP ${res.status}` };
}
// ── Container delete: list → parallel-delete objects → delete container ──
const listRes = await blompList(cfg, container);
if (!listRes.success) return listRes;
const objects = listRes.data as Array<{ name: string }>;
if (objects.length > 0) {
const tasks = objects.map((obj) => () => {
const url = `${auth.storageUrl}/${encodeURIComponent(container)}/${encodeURIComponent(obj.name)}`;
return httpRequest("DELETE", url, swiftHeaders(auth.token));
});
const results = await pLimit(tasks, DELETE_CONCURRENCY);
const failures = results
.map((r, i) => ({ r, name: objects[i].name }))
.filter(({ r }) => {
if (!r.ok) return true;
const status = (r as { ok: true; value: { status: number } }).value.status;
return status !== 204 && status !== 200;
})
.map(({ name, r }) => {
const detail = r.ok
? `HTTP ${(r as { ok: true; value: { status: number } }).value.status}`
: (r as { ok: false; error: Error }).error.message;
return `${name} (${detail})`;
});
if (failures.length > 0) {
return {
success: false,
message:
`Deleted ${objects.length - failures.length}/${objects.length} objects, ` +
`but ${failures.length} failed: ${failures.join(", ")}`,
};
}
}
const containerUrl = `${auth.storageUrl}/${encodeURIComponent(container)}`;
const delRes = await httpRequest("DELETE", containerUrl, swiftHeaders(auth.token));
if (delRes.status === 204 || delRes.status === 200) {
return {
success: true,
message: `Deleted container '${container}' and all ${objects.length} object(s).`,
};
}
return {
success: false,
message: `Objects deleted but container DELETE failed: HTTP ${delRes.status}`,
};
}
// ─── OpenClaw plugin entry point ─────────────────────────────────────────────
export default function register(openclaw: {
config: { plugins?: { "blomp-swift"?: BlompConfig } };
registerTool: (
name: string,
description: string,
schema: object,
handler: (args: Record<string, string>) => Promise<string>
) => void;
}) {
const cfg = openclaw.config?.plugins?.["blomp-swift"];
if (!cfg?.username || !cfg?.password) {
console.warn(
"[blomp-swift] Missing credentials in openclaw.config.json → plugins[\"blomp-swift\"]. Plugin disabled."
);
return;
}
// ── blomp_list ──────────────────────────────────────────────────────────────
openclaw.registerTool(
"blomp_list",
"List Blomp containers or objects inside a container.",
{
type: "object",
properties: {
container: {
type: "string",
description: "Container name. Omit to list all containers.",
},
prefix: {
type: "string",
description:
"Optional object name prefix filter (only used when container is given).",
},
},
},
async (args) => {
const result = await blompList(cfg, args.container, args.prefix);
return JSON.stringify(result, null, 2);
}
);
// ── blomp_upload ────────────────────────────────────────────────────────────
openclaw.registerTool(
"blomp_upload",
"Upload a local file to a Blomp container. Automatically uses SLO for files ≥ 1 GiB.",
{
type: "object",
required: ["local_path", "container"],
properties: {
local_path: { type: "string", description: "Absolute local file path." },
container: {
type: "string",
description: "Target Blomp container name.",
},
object_name: {
type: "string",
description:
"Object name in the container. Defaults to the file's basename.",
},
},
},
async (args) => {
const result = await blompUpload(
cfg,
args.local_path,
args.container,
args.object_name
);
return JSON.stringify(result, null, 2);
}
);
// ── blomp_upload_slo ────────────────────────────────────────────────────────
openclaw.registerTool(
"blomp_upload_slo",
"Explicitly upload a file to Blomp as a Static Large Object (1 GiB segments). " +
"Segments are stored under <container>/.file-segments/<objectName>/.",
{
type: "object",
required: ["local_path", "container"],
properties: {
local_path: { type: "string", description: "Absolute local file path." },
container: {
type: "string",
description: "Target Blomp container name.",
},
object_name: {
type: "string",
description: "Object name. Defaults to the file's basename.",
},
},
},
async (args) => {
const result = await blompUploadSlo(
cfg,
args.local_path,
args.container,
args.object_name
);
return JSON.stringify(result, null, 2);
}
);
// ── blomp_download ──────────────────────────────────────────────────────────
openclaw.registerTool(
"blomp_download",
"Download an object from a Blomp container to a local path.",
{
type: "object",
required: ["container", "object_name", "local_path"],
properties: {
container: { type: "string", description: "Source container name." },
object_name: { type: "string", description: "Object name to download." },
local_path: {
type: "string",
description: "Destination local file path.",
},
},
},
async (args) => {
const result = await blompDownload(
cfg,
args.container,
args.object_name,
args.local_path
);
return JSON.stringify(result, null, 2);
}
);
// ── blomp_delete ────────────────────────────────────────────────────────────
openclaw.registerTool(
"blomp_delete",
"Delete an object from Blomp, or delete an entire container and all its objects.",
{
type: "object",
required: ["container"],
properties: {
container: { type: "string", description: "Container name." },
object_name: {
type: "string",
description:
"Object to delete. Omit to delete the entire container (and all objects within it).",
},
},
},
async (args) => {
const result = await blompDelete(cfg, args.container, args.object_name);
return JSON.stringify(result, null, 2);
}
);
}