@openclaw/openshell-sandbox 2026.7.2-beta.7 → 2026.7.33
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/README.md +0 -8
- package/dist/index.js +46 -143
- package/openclaw.plugin.json +0 -10
- package/package.json +4 -6
- package/node_modules/p-limit/index.d.ts +0 -136
- package/node_modules/p-limit/index.js +0 -127
- package/node_modules/p-limit/license +0 -9
- package/node_modules/p-limit/node_modules/yocto-queue/index.d.ts +0 -75
- package/node_modules/p-limit/node_modules/yocto-queue/index.js +0 -90
- package/node_modules/p-limit/node_modules/yocto-queue/license +0 -9
- package/node_modules/p-limit/node_modules/yocto-queue/package.json +0 -48
- package/node_modules/p-limit/node_modules/yocto-queue/readme.md +0 -80
- package/node_modules/p-limit/package.json +0 -58
- package/node_modules/p-limit/readme.md +0 -173
package/README.md
CHANGED
|
@@ -4,14 +4,6 @@ Official NVIDIA OpenShell sandbox backend for OpenClaw.
|
|
|
4
4
|
|
|
5
5
|
This plugin lets OpenClaw use OpenShell-managed sandboxes with mirrored local workspaces and SSH command execution.
|
|
6
6
|
|
|
7
|
-
Configuring an OpenShell workspace requires OpenShell `v0.0.88` or newer. The
|
|
8
|
-
plugin supports OpenShell control-plane workspaces through
|
|
9
|
-
`plugins.entries.openshell.config.workspace`; this is separate from OpenClaw's
|
|
10
|
-
local/remote filesystem workspace mode. The setting applies to the whole plugin
|
|
11
|
-
instance, not individual agents or sessions. When unset, the plugin preserves
|
|
12
|
-
the OpenShell CLI's ambient `OPENSHELL_WORKSPACE` selection, or its `default`
|
|
13
|
-
fallback when no ambient selection exists.
|
|
14
|
-
|
|
15
7
|
## Install
|
|
16
8
|
|
|
17
9
|
```bash
|
package/dist/index.js
CHANGED
|
@@ -3,20 +3,21 @@ import { buildRemoteWorkdirValidationCommand, buildValidatedExecRemoteCommand, c
|
|
|
3
3
|
import { createHash } from "node:crypto";
|
|
4
4
|
import fsPromises from "node:fs/promises";
|
|
5
5
|
import path from "node:path";
|
|
6
|
-
import { normalizeLowercaseStringOrEmpty } from "openclaw/plugin-sdk/string-coerce-runtime";
|
|
7
6
|
import { buildPluginConfigSchema } from "openclaw/plugin-sdk/core";
|
|
8
7
|
import { formatPluginConfigIssue, mapPluginConfigIssues } from "openclaw/plugin-sdk/extension-shared";
|
|
9
8
|
import { MAX_TIMER_TIMEOUT_SECONDS } from "openclaw/plugin-sdk/number-runtime";
|
|
10
9
|
import { z } from "zod";
|
|
11
10
|
import { root } from "openclaw/plugin-sdk/file-access-runtime";
|
|
12
11
|
import { FsSafeError, isPathInside, movePathWithCopyFallback } from "openclaw/plugin-sdk/security-runtime";
|
|
13
|
-
import
|
|
12
|
+
import { normalizeLowercaseStringOrEmpty } from "openclaw/plugin-sdk/string-coerce-runtime";
|
|
14
13
|
//#region extensions/openshell/src/cli.ts
|
|
14
|
+
function resolveOpenShellCommand(command) {
|
|
15
|
+
return command;
|
|
16
|
+
}
|
|
15
17
|
function buildOpenShellBaseArgv(config) {
|
|
16
|
-
const argv = [config.command];
|
|
18
|
+
const argv = [resolveOpenShellCommand(config.command)];
|
|
17
19
|
if (config.gateway) argv.push("--gateway", config.gateway);
|
|
18
20
|
if (config.gatewayEndpoint) argv.push("--gateway-endpoint", config.gatewayEndpoint);
|
|
19
|
-
if (config.workspace) argv.push("--workspace", config.workspace);
|
|
20
21
|
return argv;
|
|
21
22
|
}
|
|
22
23
|
function buildRemoteCommand(argv) {
|
|
@@ -75,13 +76,11 @@ function normalizeProviders(value) {
|
|
|
75
76
|
return providers;
|
|
76
77
|
}
|
|
77
78
|
const nonEmptyTrimmedString = (message) => z.string({ error: message }).trim().min(1, { error: message });
|
|
78
|
-
const openShellWorkspaceName = z.string({ error: "workspace must be a valid OpenShell workspace name" }).trim().min(1, { error: "workspace must be a valid OpenShell workspace name" }).max(19, { error: "workspace must be at most 19 characters" }).regex(/^[a-z0-9]+(?:-[a-z0-9]+)*$/, { error: "workspace must contain lowercase alphanumeric characters or single hyphens and must not start or end with a hyphen" });
|
|
79
79
|
const OpenShellPluginConfigSchema = z.strictObject({
|
|
80
80
|
mode: z.enum(["mirror", "remote"], { error: "mode must be one of mirror, remote" }).optional(),
|
|
81
81
|
command: nonEmptyTrimmedString("command must be a non-empty string").optional(),
|
|
82
82
|
gateway: nonEmptyTrimmedString("gateway must be a non-empty string").optional(),
|
|
83
83
|
gatewayEndpoint: nonEmptyTrimmedString("gatewayEndpoint must be a non-empty string").optional(),
|
|
84
|
-
workspace: openShellWorkspaceName.optional(),
|
|
85
84
|
from: nonEmptyTrimmedString("from must be a non-empty string").optional(),
|
|
86
85
|
policy: nonEmptyTrimmedString("policy must be a non-empty string").optional(),
|
|
87
86
|
providers: z.array(z.string({ error: "providers must be an array of strings" }).trim().min(1, { error: "providers must be an array of strings" }), { error: "providers must be an array of strings" }).optional(),
|
|
@@ -124,7 +123,6 @@ function resolveOpenShellPluginConfig(value) {
|
|
|
124
123
|
command: DEFAULT_COMMAND,
|
|
125
124
|
gateway: void 0,
|
|
126
125
|
gatewayEndpoint: void 0,
|
|
127
|
-
workspace: void 0,
|
|
128
126
|
from: DEFAULT_SOURCE,
|
|
129
127
|
policy: void 0,
|
|
130
128
|
providers: [],
|
|
@@ -145,7 +143,6 @@ function resolveOpenShellPluginConfig(value) {
|
|
|
145
143
|
command: cfg.command ?? DEFAULT_COMMAND,
|
|
146
144
|
gateway: cfg.gateway,
|
|
147
145
|
gatewayEndpoint: cfg.gatewayEndpoint,
|
|
148
|
-
workspace: cfg.workspace,
|
|
149
146
|
from: cfg.from ?? DEFAULT_SOURCE,
|
|
150
147
|
policy: cfg.policy,
|
|
151
148
|
providers: normalizeProviders(cfg.providers),
|
|
@@ -191,12 +188,7 @@ var OpenShellFsBridge = class {
|
|
|
191
188
|
allowMissingLeaf: false,
|
|
192
189
|
allowFinalSymlinkForUnlink: false
|
|
193
190
|
});
|
|
194
|
-
|
|
195
|
-
if (params.maxBytes !== void 0) return (await root$1.read(path.relative(target.mountHostRoot, hostPath), {
|
|
196
|
-
hardlinks: "reject",
|
|
197
|
-
maxBytes: params.maxBytes
|
|
198
|
-
})).buffer;
|
|
199
|
-
opened = await root$1.open(path.relative(target.mountHostRoot, hostPath), { hardlinks: "reject" });
|
|
191
|
+
opened = await (await root(target.mountHostRoot)).open(path.relative(target.mountHostRoot, hostPath), { hardlinks: "reject" });
|
|
200
192
|
try {
|
|
201
193
|
return await opened.handle.readFile();
|
|
202
194
|
} finally {
|
|
@@ -220,27 +212,6 @@ var OpenShellFsBridge = class {
|
|
|
220
212
|
await (await root(target.mountHostRoot)).write(path.relative(target.mountHostRoot, hostPath), buffer, { mkdir: params.mkdir });
|
|
221
213
|
await this.backend.syncLocalPathToRemote(hostPath, target.containerPath);
|
|
222
214
|
}
|
|
223
|
-
async createFileExclusive(params) {
|
|
224
|
-
const target = this.resolveTarget(params);
|
|
225
|
-
const hostPath = this.requireHostPath(target);
|
|
226
|
-
this.ensureWritable(target, "create files");
|
|
227
|
-
await assertLocalPathSafety({
|
|
228
|
-
target,
|
|
229
|
-
root: target.mountHostRoot,
|
|
230
|
-
allowMissingLeaf: true,
|
|
231
|
-
allowFinalSymlinkForUnlink: false
|
|
232
|
-
});
|
|
233
|
-
const buffer = Buffer.isBuffer(params.data) ? params.data : Buffer.from(params.data, params.encoding ?? "utf8");
|
|
234
|
-
const root$2 = await root(target.mountHostRoot);
|
|
235
|
-
try {
|
|
236
|
-
await root$2.create(path.relative(target.mountHostRoot, hostPath), buffer, { mkdir: params.mkdir !== false });
|
|
237
|
-
} catch (error) {
|
|
238
|
-
if (error instanceof FsSafeError && error.code === "already-exists") return "exists";
|
|
239
|
-
throw error;
|
|
240
|
-
}
|
|
241
|
-
await this.backend.syncLocalPathToRemote(hostPath, target.containerPath);
|
|
242
|
-
return "created";
|
|
243
|
-
}
|
|
244
215
|
async mkdirp(params) {
|
|
245
216
|
const target = this.resolveTarget(params);
|
|
246
217
|
const hostPath = this.requireHostPath(target);
|
|
@@ -427,7 +398,7 @@ async function mkdirLocalRootPath(params) {
|
|
|
427
398
|
await (await root(params.target.mountHostRoot)).mkdir(relativePath);
|
|
428
399
|
}
|
|
429
400
|
async function removeLocalRootPath(params) {
|
|
430
|
-
const root$
|
|
401
|
+
const root$1 = await root(params.target.mountHostRoot);
|
|
431
402
|
const relativePath = relativeToRoot(params.target, params.hostPath);
|
|
432
403
|
try {
|
|
433
404
|
if (params.force === false) await fsPromises.lstat(params.hostPath);
|
|
@@ -436,13 +407,13 @@ async function removeLocalRootPath(params) {
|
|
|
436
407
|
if (isNotFoundError(err)) return null;
|
|
437
408
|
throw err;
|
|
438
409
|
}))?.isSymbolicLink()) {
|
|
439
|
-
await root$
|
|
410
|
+
await root$1.remove(relativePath);
|
|
440
411
|
return;
|
|
441
412
|
}
|
|
442
|
-
await removeRootTree(root$
|
|
413
|
+
await removeRootTree(root$1, relativePath);
|
|
443
414
|
return;
|
|
444
415
|
}
|
|
445
|
-
await root$
|
|
416
|
+
await root$1.remove(relativePath);
|
|
446
417
|
} catch (err) {
|
|
447
418
|
if (params.force !== false && isNotFoundError(err)) return;
|
|
448
419
|
throw err;
|
|
@@ -458,11 +429,11 @@ async function removeRootTree(root, relativePath, knownStats) {
|
|
|
458
429
|
await root.remove(relativePath);
|
|
459
430
|
}
|
|
460
431
|
async function moveLocalRootPath(params) {
|
|
461
|
-
const root$
|
|
432
|
+
const root$2 = await root(params.from.mountHostRoot);
|
|
462
433
|
const fromRelativePath = relativeToRoot(params.from, params.fromHostPath);
|
|
463
434
|
const toRelativePath = relativeToRoot(params.to, params.toHostPath);
|
|
464
|
-
await mkdirParentPath(root$
|
|
465
|
-
await root$
|
|
435
|
+
await mkdirParentPath(root$2, toRelativePath);
|
|
436
|
+
await root$2.move(fromRelativePath, toRelativePath, { overwrite: true });
|
|
466
437
|
}
|
|
467
438
|
async function mkdirParentPath(root, relativePath) {
|
|
468
439
|
const parentPath = path.dirname(relativePath);
|
|
@@ -543,11 +514,13 @@ async function assertLocalPathSafety(params) {
|
|
|
543
514
|
if (!params.target.hostPath) throw new Error(`Missing local host path for ${params.target.containerPath}`);
|
|
544
515
|
const canonicalRoot = await fsPromises.realpath(params.root).catch(() => path.resolve(params.root));
|
|
545
516
|
const targetStats = await fsPromises.lstat(params.target.hostPath).catch(() => null);
|
|
546
|
-
|
|
547
|
-
|
|
517
|
+
const candidate = params.allowFinalSymlinkForUnlink && targetStats?.isSymbolicLink() ? path.resolve(canonicalRoot, path.relative(params.root, params.target.hostPath)) : await resolveCanonicalCandidate(params.target.hostPath);
|
|
518
|
+
if (!isPathInside(canonicalRoot, candidate)) throw new Error(`Sandbox path escapes allowed mounts; cannot access: ${params.target.containerPath}`);
|
|
519
|
+
const relative = path.relative(params.root, params.target.hostPath);
|
|
520
|
+
const segments = relative.split(path.sep).filter(Boolean).slice(0, Math.max(0, relative.split(path.sep).filter(Boolean).length));
|
|
548
521
|
let cursor = params.root;
|
|
549
|
-
for (
|
|
550
|
-
cursor = path.join(cursor,
|
|
522
|
+
for (let index = 0; index < segments.length; index += 1) {
|
|
523
|
+
cursor = path.join(cursor, segments[index]);
|
|
551
524
|
const stats = await fsPromises.lstat(cursor).catch(() => null);
|
|
552
525
|
if (!stats) {
|
|
553
526
|
if (index === segments.length - 1 && params.allowMissingLeaf) return;
|
|
@@ -583,7 +556,26 @@ function createExcludeMatcher(excludeDirs) {
|
|
|
583
556
|
const excluded = new Set((excludeDirs ?? []).map((d) => normalizeLowercaseStringOrEmpty(d)));
|
|
584
557
|
return (name) => excluded.has(normalizeLowercaseStringOrEmpty(name));
|
|
585
558
|
}
|
|
586
|
-
|
|
559
|
+
function createConcurrencyLimiter(limit) {
|
|
560
|
+
let active = 0;
|
|
561
|
+
const queue = [];
|
|
562
|
+
const release = () => {
|
|
563
|
+
active -= 1;
|
|
564
|
+
queue.shift()?.();
|
|
565
|
+
};
|
|
566
|
+
return async (task) => {
|
|
567
|
+
if (active >= limit) await new Promise((resolve) => {
|
|
568
|
+
queue.push(resolve);
|
|
569
|
+
});
|
|
570
|
+
active += 1;
|
|
571
|
+
try {
|
|
572
|
+
return await task();
|
|
573
|
+
} finally {
|
|
574
|
+
release();
|
|
575
|
+
}
|
|
576
|
+
};
|
|
577
|
+
}
|
|
578
|
+
const runLimitedFs = createConcurrencyLimiter(COPY_TREE_FS_CONCURRENCY);
|
|
587
579
|
async function lstatIfExists(targetPath) {
|
|
588
580
|
return await runLimitedFs(async () => await fsPromises.lstat(targetPath)).catch(() => null);
|
|
589
581
|
}
|
|
@@ -593,7 +585,7 @@ async function copyTreeWithoutSymlinks(params) {
|
|
|
593
585
|
const targetStats = await lstatIfExists(params.targetPath);
|
|
594
586
|
if (params.preserveTargetSymlinks && targetStats?.isSymbolicLink()) return;
|
|
595
587
|
if (stats.isDirectory()) {
|
|
596
|
-
await runLimitedFs(fsPromises.mkdir
|
|
588
|
+
await runLimitedFs(async () => await fsPromises.mkdir(params.targetPath, { recursive: true }));
|
|
597
589
|
const entries = await runLimitedFs(async () => await fsPromises.readdir(params.sourcePath));
|
|
598
590
|
await Promise.all(entries.map(async (entry) => {
|
|
599
591
|
await copyTreeWithoutSymlinks({
|
|
@@ -605,7 +597,7 @@ async function copyTreeWithoutSymlinks(params) {
|
|
|
605
597
|
return;
|
|
606
598
|
}
|
|
607
599
|
if (stats.isFile()) {
|
|
608
|
-
await runLimitedFs(fsPromises.mkdir
|
|
600
|
+
await runLimitedFs(async () => await fsPromises.mkdir(path.dirname(params.targetPath), { recursive: true }));
|
|
609
601
|
await runLimitedFs(async () => await fsPromises.copyFile(params.sourcePath, params.targetPath));
|
|
610
602
|
}
|
|
611
603
|
}
|
|
@@ -616,10 +608,10 @@ async function replaceDirectoryContents(params) {
|
|
|
616
608
|
await Promise.all(existing.filter((entry) => !isExcluded(entry)).map(async (entry) => {
|
|
617
609
|
const targetPath = path.join(params.targetDir, entry);
|
|
618
610
|
if ((await lstatIfExists(targetPath))?.isSymbolicLink()) return;
|
|
619
|
-
await runLimitedFs(fsPromises.rm
|
|
611
|
+
await runLimitedFs(async () => await fsPromises.rm(targetPath, {
|
|
620
612
|
recursive: true,
|
|
621
613
|
force: true
|
|
622
|
-
});
|
|
614
|
+
}));
|
|
623
615
|
}));
|
|
624
616
|
const sourceEntries = await fsPromises.readdir(params.sourceDir);
|
|
625
617
|
for (const entry of sourceEntries) {
|
|
@@ -845,11 +837,7 @@ function createOpenShellSandboxBackendManager(params) {
|
|
|
845
837
|
}
|
|
846
838
|
async function createOpenShellSandboxBackend(params) {
|
|
847
839
|
if ((params.createParams.cfg.docker.binds?.length ?? 0) > 0) throw new Error("OpenShell sandbox backend does not support sandbox.docker.binds.");
|
|
848
|
-
const
|
|
849
|
-
scopeKey: params.createParams.scopeKey,
|
|
850
|
-
registeredRuntimeIds: params.createParams.registeredRuntimeIds
|
|
851
|
-
});
|
|
852
|
-
const sandboxName = resolvedSandboxName.sandboxName;
|
|
840
|
+
const sandboxName = buildOpenShellSandboxName(params.createParams.scopeKey);
|
|
853
841
|
const execContext = {
|
|
854
842
|
config: params.pluginConfig,
|
|
855
843
|
sandboxName
|
|
@@ -857,7 +845,6 @@ async function createOpenShellSandboxBackend(params) {
|
|
|
857
845
|
const impl = new OpenShellSandboxBackendImpl({
|
|
858
846
|
createParams: params.createParams,
|
|
859
847
|
execContext,
|
|
860
|
-
legacyRuntimeAdopted: resolvedSandboxName.legacyRuntimeAdopted,
|
|
861
848
|
remoteWorkspaceDir: params.pluginConfig.remoteWorkspaceDir,
|
|
862
849
|
remoteAgentWorkspaceDir: params.pluginConfig.remoteAgentWorkspaceDir
|
|
863
850
|
});
|
|
@@ -1206,7 +1193,7 @@ var OpenShellSandboxBackendImpl = class {
|
|
|
1206
1193
|
}
|
|
1207
1194
|
}
|
|
1208
1195
|
async ensureSandboxExistsInner() {
|
|
1209
|
-
|
|
1196
|
+
if ((await runOpenShellCli({
|
|
1210
1197
|
context: this.params.execContext,
|
|
1211
1198
|
args: [
|
|
1212
1199
|
"sandbox",
|
|
@@ -1214,16 +1201,7 @@ var OpenShellSandboxBackendImpl = class {
|
|
|
1214
1201
|
this.params.execContext.sandboxName
|
|
1215
1202
|
],
|
|
1216
1203
|
cwd: this.params.createParams.workspaceDir
|
|
1217
|
-
});
|
|
1218
|
-
if (getResult.code === 0) {
|
|
1219
|
-
if (this.params.legacyRuntimeAdopted) {
|
|
1220
|
-
const phase = await this.resolveLegacyRuntimePhase();
|
|
1221
|
-
if (!phase) throw this.buildLegacyRuntimeUnavailableError("OpenShell did not report a lifecycle phase for this sandbox.");
|
|
1222
|
-
if (phase !== "Ready") throw this.buildLegacyRuntimeUnavailableError(`OpenShell reports phase "${phase}".`);
|
|
1223
|
-
}
|
|
1224
|
-
return;
|
|
1225
|
-
}
|
|
1226
|
-
if (this.params.legacyRuntimeAdopted) throw this.buildLegacyRuntimeUnavailableError(getResult.stderr.trim());
|
|
1204
|
+
})).code === 0) return;
|
|
1227
1205
|
const createArgs = [
|
|
1228
1206
|
"sandbox",
|
|
1229
1207
|
"create",
|
|
@@ -1247,38 +1225,6 @@ var OpenShellSandboxBackendImpl = class {
|
|
|
1247
1225
|
if (createResult.code !== 0) throw new Error(createResult.stderr.trim() || "openshell sandbox create failed");
|
|
1248
1226
|
this.remoteSeedPending = true;
|
|
1249
1227
|
}
|
|
1250
|
-
async resolveLegacyRuntimePhase() {
|
|
1251
|
-
const pageSize = 100;
|
|
1252
|
-
for (let offset = 0;; offset += pageSize) {
|
|
1253
|
-
const listResult = await runOpenShellCli({
|
|
1254
|
-
context: this.params.execContext,
|
|
1255
|
-
args: [
|
|
1256
|
-
"sandbox",
|
|
1257
|
-
"list",
|
|
1258
|
-
"--limit",
|
|
1259
|
-
String(pageSize),
|
|
1260
|
-
"--offset",
|
|
1261
|
-
String(offset),
|
|
1262
|
-
"--output",
|
|
1263
|
-
"json"
|
|
1264
|
-
],
|
|
1265
|
-
cwd: this.params.createParams.workspaceDir
|
|
1266
|
-
});
|
|
1267
|
-
if (listResult.code !== 0) throw this.buildLegacyRuntimeUnavailableError(listResult.stderr.trim());
|
|
1268
|
-
const page = parseOpenShellSandboxPhasePage(listResult.stdout, this.params.execContext.sandboxName);
|
|
1269
|
-
if (!page) throw this.buildLegacyRuntimeUnavailableError("OpenShell returned malformed sandbox lifecycle data.");
|
|
1270
|
-
if (page.phase) return page.phase;
|
|
1271
|
-
if (page.count < pageSize) return;
|
|
1272
|
-
}
|
|
1273
|
-
}
|
|
1274
|
-
buildLegacyRuntimeUnavailableError(detail) {
|
|
1275
|
-
const recreateCommand = `openclaw sandbox recreate --session ${shellEscape(this.params.createParams.scopeKey)}`;
|
|
1276
|
-
return new Error([
|
|
1277
|
-
`Registered legacy OpenShell sandbox "${this.params.execContext.sandboxName}" is not usable.`,
|
|
1278
|
-
detail,
|
|
1279
|
-
`OpenClaw will not recreate this retired runtime name. Run \`${recreateCommand}\` to migrate this scope to the current naming format.`
|
|
1280
|
-
].filter(Boolean).join(" "));
|
|
1281
|
-
}
|
|
1282
1228
|
async syncWorkspaceToRemote() {
|
|
1283
1229
|
await this.runRemoteShellScriptInternal({
|
|
1284
1230
|
script: "mkdir -p -- \"$1\" && find \"$1\" -mindepth 1 -maxdepth 1 -exec rm -rf -- {} +",
|
|
@@ -1386,51 +1332,8 @@ function resolveOpenShellPluginConfigFromConfig(config, fallback) {
|
|
|
1386
1332
|
}
|
|
1387
1333
|
function buildOpenShellSandboxName(scopeKey) {
|
|
1388
1334
|
const trimmed = scopeKey.trim() || "session";
|
|
1389
|
-
if (/:workspace:[a-f0-9]{32}$/i.test(trimmed)) {
|
|
1390
|
-
const hash = createHash("sha256").update(trimmed).digest("hex").slice(0, 20);
|
|
1391
|
-
return `oc-${BigInt(`0x${hash}`).toString(36).padStart(16, "0")}`;
|
|
1392
|
-
}
|
|
1393
1335
|
return `oc-${createHash("sha256").update(trimmed).digest("hex").slice(0, 16)}`;
|
|
1394
1336
|
}
|
|
1395
|
-
function buildLegacyOpenShellSandboxName(scopeKey) {
|
|
1396
|
-
const trimmed = scopeKey.trim() || "session";
|
|
1397
|
-
const safe = normalizeLowercaseStringOrEmpty(trimmed).replace(/[^a-z0-9-]+/g, "-").replace(/^-+|-+$/g, "").slice(0, 32);
|
|
1398
|
-
const hash = Array.from(trimmed).reduce((acc, char) => (acc * 33 ^ char.charCodeAt(0)) >>> 0, 5381);
|
|
1399
|
-
return `openclaw-${safe || "session"}-${hash.toString(16).slice(0, 8)}`;
|
|
1400
|
-
}
|
|
1401
|
-
function resolveOpenShellSandboxName(params) {
|
|
1402
|
-
const sandboxName = buildOpenShellSandboxName(params.scopeKey);
|
|
1403
|
-
if (params.registeredRuntimeIds?.includes(sandboxName)) return {
|
|
1404
|
-
sandboxName,
|
|
1405
|
-
legacyRuntimeAdopted: false
|
|
1406
|
-
};
|
|
1407
|
-
const legacySandboxName = buildLegacyOpenShellSandboxName(params.scopeKey);
|
|
1408
|
-
if (params.registeredRuntimeIds?.includes(legacySandboxName)) return {
|
|
1409
|
-
sandboxName: legacySandboxName,
|
|
1410
|
-
legacyRuntimeAdopted: true
|
|
1411
|
-
};
|
|
1412
|
-
return {
|
|
1413
|
-
sandboxName,
|
|
1414
|
-
legacyRuntimeAdopted: false
|
|
1415
|
-
};
|
|
1416
|
-
}
|
|
1417
|
-
function parseOpenShellSandboxPhasePage(stdout, sandboxName) {
|
|
1418
|
-
try {
|
|
1419
|
-
const parsed = JSON.parse(stdout);
|
|
1420
|
-
if (!Array.isArray(parsed)) return;
|
|
1421
|
-
for (const entry of parsed) {
|
|
1422
|
-
if (!entry || typeof entry !== "object") continue;
|
|
1423
|
-
const record = entry;
|
|
1424
|
-
if (record.name === sandboxName && typeof record.phase === "string") return {
|
|
1425
|
-
count: parsed.length,
|
|
1426
|
-
phase: record.phase
|
|
1427
|
-
};
|
|
1428
|
-
}
|
|
1429
|
-
return { count: parsed.length };
|
|
1430
|
-
} catch {
|
|
1431
|
-
return;
|
|
1432
|
-
}
|
|
1433
|
-
}
|
|
1434
1337
|
function resolveRemoteMaterializedSkillsWorkspaceDir(remoteWorkspaceDir) {
|
|
1435
1338
|
const root = remoteWorkspaceDir.replace(/\\/g, "/").replace(/\/+$/, "") || "/";
|
|
1436
1339
|
return path.posix.join(root, ...MATERIALIZED_SKILLS_REMOTE_PARTS);
|
package/openclaw.plugin.json
CHANGED
|
@@ -25,12 +25,6 @@
|
|
|
25
25
|
"type": "string",
|
|
26
26
|
"minLength": 1
|
|
27
27
|
},
|
|
28
|
-
"workspace": {
|
|
29
|
-
"type": "string",
|
|
30
|
-
"minLength": 1,
|
|
31
|
-
"maxLength": 19,
|
|
32
|
-
"pattern": "^[a-z0-9]+(?:-[a-z0-9]+)*$"
|
|
33
|
-
},
|
|
34
28
|
"from": {
|
|
35
29
|
"type": "string",
|
|
36
30
|
"minLength": 1
|
|
@@ -84,10 +78,6 @@
|
|
|
84
78
|
"label": "Gateway Endpoint",
|
|
85
79
|
"help": "Optional OpenShell gateway endpoint passed as --gateway-endpoint."
|
|
86
80
|
},
|
|
87
|
-
"workspace": {
|
|
88
|
-
"label": "OpenShell Workspace",
|
|
89
|
-
"help": "Existing OpenShell control-plane workspace for sandboxes, providers, policies, and inference routes. When unset, preserves the OpenShell CLI's ambient workspace selection."
|
|
90
|
-
},
|
|
91
81
|
"from": {
|
|
92
82
|
"label": "Sandbox Source",
|
|
93
83
|
"help": "OpenShell sandbox source for first-time create. Defaults to openclaw."
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@openclaw/openshell-sandbox",
|
|
3
|
-
"version": "2026.7.
|
|
3
|
+
"version": "2026.7.33",
|
|
4
4
|
"description": "OpenClaw sandbox backend for the NVIDIA OpenShell CLI with mirrored local workspaces and SSH command execution.",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -8,7 +8,6 @@
|
|
|
8
8
|
},
|
|
9
9
|
"type": "module",
|
|
10
10
|
"dependencies": {
|
|
11
|
-
"p-limit": "7.3.1",
|
|
12
11
|
"zod": "4.4.3"
|
|
13
12
|
},
|
|
14
13
|
"openclaw": {
|
|
@@ -21,10 +20,10 @@
|
|
|
21
20
|
"minHostVersion": ">=2026.5.12-beta.1"
|
|
22
21
|
},
|
|
23
22
|
"compat": {
|
|
24
|
-
"pluginApi": ">=2026.7.
|
|
23
|
+
"pluginApi": ">=2026.7.33"
|
|
25
24
|
},
|
|
26
25
|
"build": {
|
|
27
|
-
"openclawVersion": "2026.7.
|
|
26
|
+
"openclawVersion": "2026.7.33",
|
|
28
27
|
"bundledDist": false
|
|
29
28
|
},
|
|
30
29
|
"release": {
|
|
@@ -41,7 +40,7 @@
|
|
|
41
40
|
"README.md"
|
|
42
41
|
],
|
|
43
42
|
"peerDependencies": {
|
|
44
|
-
"openclaw": ">=2026.7.
|
|
43
|
+
"openclaw": ">=2026.7.33"
|
|
45
44
|
},
|
|
46
45
|
"peerDependenciesMeta": {
|
|
47
46
|
"openclaw": {
|
|
@@ -49,7 +48,6 @@
|
|
|
49
48
|
}
|
|
50
49
|
},
|
|
51
50
|
"bundledDependencies": [
|
|
52
|
-
"p-limit",
|
|
53
51
|
"zod"
|
|
54
52
|
]
|
|
55
53
|
}
|
|
@@ -1,136 +0,0 @@
|
|
|
1
|
-
export type LimitFunction = {
|
|
2
|
-
/**
|
|
3
|
-
The number of promises that are currently running.
|
|
4
|
-
*/
|
|
5
|
-
readonly activeCount: number;
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
The number of promises that are waiting to run (i.e. their internal `fn` was not called yet).
|
|
9
|
-
*/
|
|
10
|
-
readonly pendingCount: number;
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
Get or set the concurrency limit.
|
|
14
|
-
*/
|
|
15
|
-
concurrency: number;
|
|
16
|
-
|
|
17
|
-
/**
|
|
18
|
-
Discard pending promises that are waiting to run.
|
|
19
|
-
|
|
20
|
-
This might be useful if you want to tear down the queue at the end of your program's lifecycle or discard any function calls referencing an intermediary state of your app.
|
|
21
|
-
|
|
22
|
-
Note: This does not cancel promises that are already running.
|
|
23
|
-
|
|
24
|
-
When `rejectOnClear` is enabled, pending promises are rejected with an `AbortError`.
|
|
25
|
-
This is recommended if you await the returned promises, for example with `Promise.all`, so pending tasks do not remain unresolved after `clearQueue()`.
|
|
26
|
-
*/
|
|
27
|
-
clearQueue: () => void;
|
|
28
|
-
|
|
29
|
-
/**
|
|
30
|
-
Process an iterable of inputs with limited concurrency.
|
|
31
|
-
|
|
32
|
-
The mapper function receives the item value and its index.
|
|
33
|
-
|
|
34
|
-
This is a convenience function for processing inputs that arrive in batches. For more complex use cases, see [p-map](https://github.com/sindresorhus/p-map).
|
|
35
|
-
|
|
36
|
-
@param iterable - An iterable containing an argument for the given function.
|
|
37
|
-
@param mapperFunction - Promise-returning/async function.
|
|
38
|
-
@returns A promise equivalent to `Promise.all(Array.from(iterable, (item, index) => limit(mapperFunction, item, index)))`.
|
|
39
|
-
*/
|
|
40
|
-
map: <Input, ReturnType> (
|
|
41
|
-
iterable: Iterable<Input>,
|
|
42
|
-
mapperFunction: (input: Input, index: number) => PromiseLike<ReturnType> | ReturnType
|
|
43
|
-
) => Promise<ReturnType[]>;
|
|
44
|
-
|
|
45
|
-
/**
|
|
46
|
-
@param fn - Promise-returning/async function.
|
|
47
|
-
@param arguments - Any arguments to pass through to `fn`. Support for passing arguments on to the `fn` is provided in order to be able to avoid creating unnecessary closures. You probably don't need this optimization unless you're pushing a *lot* of functions.
|
|
48
|
-
|
|
49
|
-
Warning: Avoid calling the same `limit` function inside a function that is already limited by it. This can create a deadlock where inner tasks never run. Use a separate limiter for inner tasks.
|
|
50
|
-
|
|
51
|
-
@returns The promise returned by calling `fn(...arguments)`.
|
|
52
|
-
*/
|
|
53
|
-
<Arguments extends unknown[], ReturnType>(
|
|
54
|
-
function_: (...arguments_: Arguments) => PromiseLike<ReturnType> | ReturnType,
|
|
55
|
-
...arguments_: Arguments
|
|
56
|
-
): Promise<ReturnType>;
|
|
57
|
-
};
|
|
58
|
-
|
|
59
|
-
/**
|
|
60
|
-
Run multiple promise-returning & async functions with limited concurrency.
|
|
61
|
-
|
|
62
|
-
@param concurrency - Concurrency limit. Minimum: `1`. You can pass a number or an options object with a `concurrency` property.
|
|
63
|
-
@returns A `limit` function.
|
|
64
|
-
|
|
65
|
-
@example
|
|
66
|
-
```
|
|
67
|
-
import pLimit from 'p-limit';
|
|
68
|
-
|
|
69
|
-
const limit = pLimit(1);
|
|
70
|
-
|
|
71
|
-
const input = [
|
|
72
|
-
limit(() => fetchSomething('foo')),
|
|
73
|
-
limit(() => fetchSomething('bar')),
|
|
74
|
-
limit(() => doSomething())
|
|
75
|
-
];
|
|
76
|
-
|
|
77
|
-
// Only one promise is run at once
|
|
78
|
-
const result = await Promise.all(input);
|
|
79
|
-
console.log(result);
|
|
80
|
-
```
|
|
81
|
-
|
|
82
|
-
@example
|
|
83
|
-
```
|
|
84
|
-
import pLimit from 'p-limit';
|
|
85
|
-
|
|
86
|
-
const limit = pLimit({concurrency: 1});
|
|
87
|
-
```
|
|
88
|
-
*/
|
|
89
|
-
export default function pLimit(concurrency: number | Options): LimitFunction;
|
|
90
|
-
|
|
91
|
-
export type Options = {
|
|
92
|
-
/**
|
|
93
|
-
Concurrency limit.
|
|
94
|
-
|
|
95
|
-
Minimum: `1`.
|
|
96
|
-
*/
|
|
97
|
-
readonly concurrency: number;
|
|
98
|
-
|
|
99
|
-
/**
|
|
100
|
-
Reject pending promises with an `AbortError` when `clearQueue()` is called.
|
|
101
|
-
|
|
102
|
-
Default: `false`.
|
|
103
|
-
|
|
104
|
-
This is recommended if you await the returned promises, for example with `Promise.all`, so pending tasks do not remain unresolved after `clearQueue()`.
|
|
105
|
-
*/
|
|
106
|
-
readonly rejectOnClear?: boolean;
|
|
107
|
-
};
|
|
108
|
-
|
|
109
|
-
/**
|
|
110
|
-
Returns a function with limited concurrency.
|
|
111
|
-
|
|
112
|
-
The returned function manages its own concurrent executions, allowing you to call it multiple times without exceeding the specified concurrency limit.
|
|
113
|
-
|
|
114
|
-
Ideal for scenarios where you need to control the number of simultaneous executions of a single function, rather than managing concurrency across multiple functions.
|
|
115
|
-
|
|
116
|
-
@param function_ - Promise-returning/async function.
|
|
117
|
-
@return Function with limited concurrency.
|
|
118
|
-
|
|
119
|
-
@example
|
|
120
|
-
```
|
|
121
|
-
import {limitFunction} from 'p-limit';
|
|
122
|
-
|
|
123
|
-
const limitedFunction = limitFunction(async () => {
|
|
124
|
-
return doSomething();
|
|
125
|
-
}, {concurrency: 1});
|
|
126
|
-
|
|
127
|
-
const input = Array.from({length: 10}, limitedFunction);
|
|
128
|
-
|
|
129
|
-
// Only one promise is run at once.
|
|
130
|
-
await Promise.all(input);
|
|
131
|
-
```
|
|
132
|
-
*/
|
|
133
|
-
export function limitFunction<Arguments extends unknown[], ReturnType>(
|
|
134
|
-
function_: (...arguments_: Arguments) => PromiseLike<ReturnType>,
|
|
135
|
-
options: Options
|
|
136
|
-
): (...arguments_: Arguments) => Promise<ReturnType>;
|
|
@@ -1,127 +0,0 @@
|
|
|
1
|
-
import Queue from 'yocto-queue';
|
|
2
|
-
|
|
3
|
-
export default function pLimit(concurrency) {
|
|
4
|
-
let rejectOnClear = false;
|
|
5
|
-
|
|
6
|
-
if (typeof concurrency === 'object') {
|
|
7
|
-
({concurrency, rejectOnClear = false} = concurrency);
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
validateConcurrency(concurrency);
|
|
11
|
-
|
|
12
|
-
if (typeof rejectOnClear !== 'boolean') {
|
|
13
|
-
throw new TypeError('Expected `rejectOnClear` to be a boolean');
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
const queue = new Queue();
|
|
17
|
-
let activeCount = 0;
|
|
18
|
-
|
|
19
|
-
const resumeNext = () => {
|
|
20
|
-
// Process the next queued function if we're under the concurrency limit
|
|
21
|
-
if (activeCount < concurrency && queue.size > 0) {
|
|
22
|
-
activeCount++;
|
|
23
|
-
queue.dequeue().run();
|
|
24
|
-
}
|
|
25
|
-
};
|
|
26
|
-
|
|
27
|
-
const next = () => {
|
|
28
|
-
activeCount--;
|
|
29
|
-
resumeNext();
|
|
30
|
-
};
|
|
31
|
-
|
|
32
|
-
const run = async (function_, resolve, arguments_) => {
|
|
33
|
-
// Execute the function and capture the result promise
|
|
34
|
-
const result = (async () => function_(...arguments_))();
|
|
35
|
-
|
|
36
|
-
// Resolve immediately with the promise (don't wait for completion)
|
|
37
|
-
resolve(result);
|
|
38
|
-
|
|
39
|
-
// Wait for the function to complete (success or failure)
|
|
40
|
-
// We catch errors here to prevent unhandled rejections,
|
|
41
|
-
// but the original promise rejection is preserved for the caller
|
|
42
|
-
try {
|
|
43
|
-
await result;
|
|
44
|
-
} catch {}
|
|
45
|
-
|
|
46
|
-
// Decrement active count and process next queued function
|
|
47
|
-
next();
|
|
48
|
-
};
|
|
49
|
-
|
|
50
|
-
const enqueue = (function_, resolve, reject, arguments_) => {
|
|
51
|
-
const queueItem = {reject};
|
|
52
|
-
|
|
53
|
-
// Queue the internal resolve function instead of the run function
|
|
54
|
-
// to preserve the asynchronous execution context.
|
|
55
|
-
new Promise(internalResolve => { // eslint-disable-line promise/param-names
|
|
56
|
-
queueItem.run = internalResolve;
|
|
57
|
-
queue.enqueue(queueItem);
|
|
58
|
-
}).then(run.bind(undefined, function_, resolve, arguments_)); // eslint-disable-line promise/prefer-await-to-then
|
|
59
|
-
|
|
60
|
-
// Start processing immediately if we haven't reached the concurrency limit
|
|
61
|
-
if (activeCount < concurrency) {
|
|
62
|
-
resumeNext();
|
|
63
|
-
}
|
|
64
|
-
};
|
|
65
|
-
|
|
66
|
-
const generator = (function_, ...arguments_) => new Promise((resolve, reject) => {
|
|
67
|
-
enqueue(function_, resolve, reject, arguments_);
|
|
68
|
-
});
|
|
69
|
-
|
|
70
|
-
Object.defineProperties(generator, {
|
|
71
|
-
activeCount: {
|
|
72
|
-
get: () => activeCount,
|
|
73
|
-
},
|
|
74
|
-
pendingCount: {
|
|
75
|
-
get: () => queue.size,
|
|
76
|
-
},
|
|
77
|
-
clearQueue: {
|
|
78
|
-
value() {
|
|
79
|
-
if (!rejectOnClear) {
|
|
80
|
-
queue.clear();
|
|
81
|
-
return;
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
const abortError = AbortSignal.abort().reason;
|
|
85
|
-
|
|
86
|
-
while (queue.size > 0) {
|
|
87
|
-
queue.dequeue().reject(abortError);
|
|
88
|
-
}
|
|
89
|
-
},
|
|
90
|
-
},
|
|
91
|
-
concurrency: {
|
|
92
|
-
get: () => concurrency,
|
|
93
|
-
|
|
94
|
-
set(newConcurrency) {
|
|
95
|
-
validateConcurrency(newConcurrency);
|
|
96
|
-
concurrency = newConcurrency;
|
|
97
|
-
|
|
98
|
-
queueMicrotask(() => {
|
|
99
|
-
// eslint-disable-next-line no-unmodified-loop-condition
|
|
100
|
-
while (activeCount < concurrency && queue.size > 0) {
|
|
101
|
-
resumeNext();
|
|
102
|
-
}
|
|
103
|
-
});
|
|
104
|
-
},
|
|
105
|
-
},
|
|
106
|
-
map: {
|
|
107
|
-
async value(iterable, function_) {
|
|
108
|
-
const promises = Array.from(iterable, (value, index) => generator(function_, value, index));
|
|
109
|
-
return Promise.all(promises);
|
|
110
|
-
},
|
|
111
|
-
},
|
|
112
|
-
});
|
|
113
|
-
|
|
114
|
-
return generator;
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
export function limitFunction(function_, options) {
|
|
118
|
-
const limit = pLimit(options);
|
|
119
|
-
|
|
120
|
-
return (...arguments_) => limit(() => function_(...arguments_));
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
function validateConcurrency(concurrency) {
|
|
124
|
-
if (!((Number.isInteger(concurrency) || concurrency === Number.POSITIVE_INFINITY) && concurrency > 0)) {
|
|
125
|
-
throw new TypeError('Expected `concurrency` to be a number from 1 and up');
|
|
126
|
-
}
|
|
127
|
-
}
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
MIT License
|
|
2
|
-
|
|
3
|
-
Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (https://sindresorhus.com)
|
|
4
|
-
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
6
|
-
|
|
7
|
-
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
8
|
-
|
|
9
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
@@ -1,75 +0,0 @@
|
|
|
1
|
-
export default class Queue<ValueType> implements Iterable<ValueType> {
|
|
2
|
-
/**
|
|
3
|
-
The size of the queue.
|
|
4
|
-
*/
|
|
5
|
-
readonly size: number;
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
Tiny queue data structure.
|
|
9
|
-
|
|
10
|
-
The instance is an [`Iterable`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols), which means you can iterate over the queue front to back with a “for…of” loop, or use spreading to convert the queue to an array. Don't do this unless you really need to though, since it's slow.
|
|
11
|
-
|
|
12
|
-
@example
|
|
13
|
-
```
|
|
14
|
-
import Queue from 'yocto-queue';
|
|
15
|
-
|
|
16
|
-
const queue = new Queue();
|
|
17
|
-
|
|
18
|
-
queue.enqueue('🦄');
|
|
19
|
-
queue.enqueue('🌈');
|
|
20
|
-
|
|
21
|
-
console.log(queue.size);
|
|
22
|
-
//=> 2
|
|
23
|
-
|
|
24
|
-
console.log(...queue);
|
|
25
|
-
//=> '🦄 🌈'
|
|
26
|
-
|
|
27
|
-
console.log(queue.dequeue());
|
|
28
|
-
//=> '🦄'
|
|
29
|
-
|
|
30
|
-
console.log(queue.dequeue());
|
|
31
|
-
//=> '🌈'
|
|
32
|
-
```
|
|
33
|
-
*/
|
|
34
|
-
constructor();
|
|
35
|
-
|
|
36
|
-
/**
|
|
37
|
-
The instance is an [`Iterable`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols), which means you can iterate over the queue front to back with a “for…of” loop. Using the iterator will not remove the items from the queue. If you want that, use `drain()` instead.
|
|
38
|
-
|
|
39
|
-
You can also use spreading to convert the queue to an array. Don't do this unless you really need to though, since it's slow.
|
|
40
|
-
*/
|
|
41
|
-
[Symbol.iterator](): IterableIterator<ValueType>;
|
|
42
|
-
|
|
43
|
-
/**
|
|
44
|
-
Returns an iterator that dequeues items as you consume it.
|
|
45
|
-
|
|
46
|
-
This allows you to empty the queue while processing its items.
|
|
47
|
-
|
|
48
|
-
If you want to not remove items as you consume it, use the `Queue` object as an iterator.
|
|
49
|
-
*/
|
|
50
|
-
drain(): IterableIterator<ValueType>;
|
|
51
|
-
|
|
52
|
-
/**
|
|
53
|
-
Add a value to the queue.
|
|
54
|
-
*/
|
|
55
|
-
enqueue(value: ValueType): void;
|
|
56
|
-
|
|
57
|
-
/**
|
|
58
|
-
Remove the next value in the queue.
|
|
59
|
-
|
|
60
|
-
@returns The removed value or `undefined` if the queue is empty.
|
|
61
|
-
*/
|
|
62
|
-
dequeue(): ValueType | undefined;
|
|
63
|
-
|
|
64
|
-
/**
|
|
65
|
-
Get the next value in the queue without removing it.
|
|
66
|
-
|
|
67
|
-
@returns The value or `undefined` if the queue is empty.
|
|
68
|
-
*/
|
|
69
|
-
peek(): ValueType | undefined;
|
|
70
|
-
|
|
71
|
-
/**
|
|
72
|
-
Clear the queue.
|
|
73
|
-
*/
|
|
74
|
-
clear(): void;
|
|
75
|
-
}
|
|
@@ -1,90 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
How it works:
|
|
3
|
-
`this.#head` is an instance of `Node` which keeps track of its current value and nests another instance of `Node` that keeps the value that comes after it. When a value is provided to `.enqueue()`, the code needs to iterate through `this.#head`, going deeper and deeper to find the last value. However, iterating through every single item is slow. This problem is solved by saving a reference to the last value as `this.#tail` so that it can reference it to add a new value.
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
class Node {
|
|
7
|
-
value;
|
|
8
|
-
next;
|
|
9
|
-
|
|
10
|
-
constructor(value) {
|
|
11
|
-
this.value = value;
|
|
12
|
-
}
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
export default class Queue {
|
|
16
|
-
#head;
|
|
17
|
-
#tail;
|
|
18
|
-
#size;
|
|
19
|
-
|
|
20
|
-
constructor() {
|
|
21
|
-
this.clear();
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
enqueue(value) {
|
|
25
|
-
const node = new Node(value);
|
|
26
|
-
|
|
27
|
-
if (this.#head) {
|
|
28
|
-
this.#tail.next = node;
|
|
29
|
-
this.#tail = node;
|
|
30
|
-
} else {
|
|
31
|
-
this.#head = node;
|
|
32
|
-
this.#tail = node;
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
this.#size++;
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
dequeue() {
|
|
39
|
-
const current = this.#head;
|
|
40
|
-
if (!current) {
|
|
41
|
-
return;
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
this.#head = this.#head.next;
|
|
45
|
-
this.#size--;
|
|
46
|
-
|
|
47
|
-
// Clean up tail reference when queue becomes empty
|
|
48
|
-
if (!this.#head) {
|
|
49
|
-
this.#tail = undefined;
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
return current.value;
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
peek() {
|
|
56
|
-
if (!this.#head) {
|
|
57
|
-
return;
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
return this.#head.value;
|
|
61
|
-
|
|
62
|
-
// TODO: Node.js 18.
|
|
63
|
-
// return this.#head?.value;
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
clear() {
|
|
67
|
-
this.#head = undefined;
|
|
68
|
-
this.#tail = undefined;
|
|
69
|
-
this.#size = 0;
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
get size() {
|
|
73
|
-
return this.#size;
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
* [Symbol.iterator]() {
|
|
77
|
-
let current = this.#head;
|
|
78
|
-
|
|
79
|
-
while (current) {
|
|
80
|
-
yield current.value;
|
|
81
|
-
current = current.next;
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
* drain() {
|
|
86
|
-
while (this.#head) {
|
|
87
|
-
yield this.dequeue();
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
}
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
MIT License
|
|
2
|
-
|
|
3
|
-
Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (https://sindresorhus.com)
|
|
4
|
-
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
6
|
-
|
|
7
|
-
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
8
|
-
|
|
9
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "yocto-queue",
|
|
3
|
-
"version": "1.2.2",
|
|
4
|
-
"description": "Tiny queue data structure",
|
|
5
|
-
"license": "MIT",
|
|
6
|
-
"repository": "sindresorhus/yocto-queue",
|
|
7
|
-
"funding": "https://github.com/sponsors/sindresorhus",
|
|
8
|
-
"author": {
|
|
9
|
-
"name": "Sindre Sorhus",
|
|
10
|
-
"email": "sindresorhus@gmail.com",
|
|
11
|
-
"url": "https://sindresorhus.com"
|
|
12
|
-
},
|
|
13
|
-
"type": "module",
|
|
14
|
-
"exports": "./index.js",
|
|
15
|
-
"types": "./index.d.ts",
|
|
16
|
-
"sideEffects": false,
|
|
17
|
-
"engines": {
|
|
18
|
-
"node": ">=12.20"
|
|
19
|
-
},
|
|
20
|
-
"scripts": {
|
|
21
|
-
"//test": "xo && ava && tsd",
|
|
22
|
-
"test": "ava && tsd"
|
|
23
|
-
},
|
|
24
|
-
"files": [
|
|
25
|
-
"index.js",
|
|
26
|
-
"index.d.ts"
|
|
27
|
-
],
|
|
28
|
-
"keywords": [
|
|
29
|
-
"queue",
|
|
30
|
-
"data",
|
|
31
|
-
"structure",
|
|
32
|
-
"algorithm",
|
|
33
|
-
"queues",
|
|
34
|
-
"queuing",
|
|
35
|
-
"list",
|
|
36
|
-
"array",
|
|
37
|
-
"linkedlist",
|
|
38
|
-
"fifo",
|
|
39
|
-
"enqueue",
|
|
40
|
-
"dequeue",
|
|
41
|
-
"data-structure"
|
|
42
|
-
],
|
|
43
|
-
"devDependencies": {
|
|
44
|
-
"ava": "^3.15.0",
|
|
45
|
-
"tsd": "^0.17.0",
|
|
46
|
-
"xo": "^0.44.0"
|
|
47
|
-
}
|
|
48
|
-
}
|
|
@@ -1,80 +0,0 @@
|
|
|
1
|
-
# yocto-queue [](https://bundlephobia.com/result?p=yocto-queue)
|
|
2
|
-
|
|
3
|
-
> Tiny queue data structure
|
|
4
|
-
|
|
5
|
-
You should use this package instead of an array if you do a lot of `Array#push()` and `Array#shift()` on large arrays, since `Array#shift()` has [linear time complexity](https://medium.com/@ariel.salem1989/an-easy-to-use-guide-to-big-o-time-complexity-5dcf4be8a444#:~:text=O(N)%E2%80%94Linear%20Time) *O(n)* while `Queue#dequeue()` has [constant time complexity](https://medium.com/@ariel.salem1989/an-easy-to-use-guide-to-big-o-time-complexity-5dcf4be8a444#:~:text=O(1)%20%E2%80%94%20Constant%20Time) *O(1)*. That makes a huge difference for large arrays.
|
|
6
|
-
|
|
7
|
-
> A [queue](https://en.wikipedia.org/wiki/Queue_(abstract_data_type)) is an ordered list of elements where an element is inserted at the end of the queue and is removed from the front of the queue. A queue works based on the first-in, first-out ([FIFO](https://en.wikipedia.org/wiki/FIFO_(computing_and_electronics))) principle.
|
|
8
|
-
|
|
9
|
-
## Install
|
|
10
|
-
|
|
11
|
-
```sh
|
|
12
|
-
npm install yocto-queue
|
|
13
|
-
```
|
|
14
|
-
|
|
15
|
-
## Usage
|
|
16
|
-
|
|
17
|
-
```js
|
|
18
|
-
import Queue from 'yocto-queue';
|
|
19
|
-
|
|
20
|
-
const queue = new Queue();
|
|
21
|
-
|
|
22
|
-
queue.enqueue('🦄');
|
|
23
|
-
queue.enqueue('🌈');
|
|
24
|
-
|
|
25
|
-
console.log(queue.size);
|
|
26
|
-
//=> 2
|
|
27
|
-
|
|
28
|
-
console.log(...queue);
|
|
29
|
-
//=> '🦄 🌈'
|
|
30
|
-
|
|
31
|
-
console.log(queue.dequeue());
|
|
32
|
-
//=> '🦄'
|
|
33
|
-
|
|
34
|
-
console.log(queue.dequeue());
|
|
35
|
-
//=> '🌈'
|
|
36
|
-
```
|
|
37
|
-
|
|
38
|
-
## API
|
|
39
|
-
|
|
40
|
-
### `queue = new Queue()`
|
|
41
|
-
|
|
42
|
-
The instance is an [`Iterable`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols), which means you can iterate over the queue front to back with a “for…of” loop. Using the iterator will not remove the items from the queue. If you want that, use [`drain()`](#drain) instead.
|
|
43
|
-
|
|
44
|
-
You can also use spreading to convert the queue to an array. Don't do this unless you really need to though, since it's slow.
|
|
45
|
-
|
|
46
|
-
#### `.enqueue(value)`
|
|
47
|
-
|
|
48
|
-
Add a value to the queue.
|
|
49
|
-
|
|
50
|
-
#### `.dequeue()`
|
|
51
|
-
|
|
52
|
-
Remove the next value in the queue.
|
|
53
|
-
|
|
54
|
-
Returns the removed value or `undefined` if the queue is empty.
|
|
55
|
-
|
|
56
|
-
#### `.peek()`
|
|
57
|
-
|
|
58
|
-
Get the next value in the queue without removing it.
|
|
59
|
-
|
|
60
|
-
Returns the value or `undefined` if the queue is empty.
|
|
61
|
-
|
|
62
|
-
#### `.drain()`
|
|
63
|
-
|
|
64
|
-
Returns an iterator that dequeues items as you consume it.
|
|
65
|
-
|
|
66
|
-
This allows you to empty the queue while processing its items.
|
|
67
|
-
|
|
68
|
-
If you want to not remove items as you consume it, use the `Queue` object as an iterator.
|
|
69
|
-
|
|
70
|
-
#### `.clear()`
|
|
71
|
-
|
|
72
|
-
Clear the queue.
|
|
73
|
-
|
|
74
|
-
#### `.size`
|
|
75
|
-
|
|
76
|
-
The size of the queue.
|
|
77
|
-
|
|
78
|
-
## Related
|
|
79
|
-
|
|
80
|
-
- [quick-lru](https://github.com/sindresorhus/quick-lru) - Simple “Least Recently Used” (LRU) cache
|
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "p-limit",
|
|
3
|
-
"version": "7.3.1",
|
|
4
|
-
"description": "Run multiple promise-returning & async functions with limited concurrency",
|
|
5
|
-
"license": "MIT",
|
|
6
|
-
"repository": "sindresorhus/p-limit",
|
|
7
|
-
"funding": "https://github.com/sponsors/sindresorhus",
|
|
8
|
-
"author": {
|
|
9
|
-
"name": "Sindre Sorhus",
|
|
10
|
-
"email": "sindresorhus@gmail.com",
|
|
11
|
-
"url": "https://sindresorhus.com"
|
|
12
|
-
},
|
|
13
|
-
"type": "module",
|
|
14
|
-
"exports": {
|
|
15
|
-
"types": "./index.d.ts",
|
|
16
|
-
"default": "./index.js"
|
|
17
|
-
},
|
|
18
|
-
"sideEffects": false,
|
|
19
|
-
"engines": {
|
|
20
|
-
"node": ">=20"
|
|
21
|
-
},
|
|
22
|
-
"scripts": {
|
|
23
|
-
"test": "xo && ava && tsd",
|
|
24
|
-
"benchmark": "node benchmark.js"
|
|
25
|
-
},
|
|
26
|
-
"files": [
|
|
27
|
-
"index.js",
|
|
28
|
-
"index.d.ts"
|
|
29
|
-
],
|
|
30
|
-
"keywords": [
|
|
31
|
-
"promise",
|
|
32
|
-
"limit",
|
|
33
|
-
"limited",
|
|
34
|
-
"concurrency",
|
|
35
|
-
"throttle",
|
|
36
|
-
"throat",
|
|
37
|
-
"rate",
|
|
38
|
-
"batch",
|
|
39
|
-
"ratelimit",
|
|
40
|
-
"task",
|
|
41
|
-
"queue",
|
|
42
|
-
"async",
|
|
43
|
-
"await",
|
|
44
|
-
"promises",
|
|
45
|
-
"bluebird"
|
|
46
|
-
],
|
|
47
|
-
"dependencies": {
|
|
48
|
-
"yocto-queue": "^1.2.1"
|
|
49
|
-
},
|
|
50
|
-
"devDependencies": {
|
|
51
|
-
"ava": "^6.4.1",
|
|
52
|
-
"in-range": "^3.0.0",
|
|
53
|
-
"random-int": "^3.0.0",
|
|
54
|
-
"time-span": "^5.1.0",
|
|
55
|
-
"tsd": "^0.33.0",
|
|
56
|
-
"xo": "^1.2.1"
|
|
57
|
-
}
|
|
58
|
-
}
|
|
@@ -1,173 +0,0 @@
|
|
|
1
|
-
# p-limit
|
|
2
|
-
|
|
3
|
-
> Run multiple promise-returning & async functions with limited concurrency
|
|
4
|
-
|
|
5
|
-
*Works in Node.js and browsers.*
|
|
6
|
-
|
|
7
|
-
## Install
|
|
8
|
-
|
|
9
|
-
```sh
|
|
10
|
-
npm install p-limit
|
|
11
|
-
```
|
|
12
|
-
|
|
13
|
-
## Usage
|
|
14
|
-
|
|
15
|
-
```js
|
|
16
|
-
import pLimit from 'p-limit';
|
|
17
|
-
|
|
18
|
-
const limit = pLimit(1);
|
|
19
|
-
|
|
20
|
-
const input = [
|
|
21
|
-
limit(() => fetchSomething('foo')),
|
|
22
|
-
limit(() => fetchSomething('bar')),
|
|
23
|
-
limit(() => doSomething())
|
|
24
|
-
];
|
|
25
|
-
|
|
26
|
-
// Only one promise is run at once
|
|
27
|
-
const result = await Promise.all(input);
|
|
28
|
-
console.log(result);
|
|
29
|
-
```
|
|
30
|
-
|
|
31
|
-
## API
|
|
32
|
-
|
|
33
|
-
### pLimit(concurrency) <sup>default export</sup>
|
|
34
|
-
|
|
35
|
-
Returns a `limit` function.
|
|
36
|
-
|
|
37
|
-
#### concurrency
|
|
38
|
-
|
|
39
|
-
Type: `number | object`\
|
|
40
|
-
Minimum: `1`
|
|
41
|
-
|
|
42
|
-
Concurrency limit.
|
|
43
|
-
|
|
44
|
-
You can pass a number or an options object with a `concurrency` property.
|
|
45
|
-
|
|
46
|
-
#### rejectOnClear
|
|
47
|
-
|
|
48
|
-
Type: `boolean`\
|
|
49
|
-
Default: `false`
|
|
50
|
-
|
|
51
|
-
Reject pending promises with an `AbortError` when `clearQueue()` is called.
|
|
52
|
-
This is recommended if you await the returned promises, for example with `Promise.all`, so pending tasks do not remain unresolved after `clearQueue()`.
|
|
53
|
-
|
|
54
|
-
```js
|
|
55
|
-
import pLimit from 'p-limit';
|
|
56
|
-
|
|
57
|
-
const limit = pLimit({concurrency: 1});
|
|
58
|
-
```
|
|
59
|
-
|
|
60
|
-
### limit(fn, ...args)
|
|
61
|
-
|
|
62
|
-
Returns the promise returned by calling `fn(...args)`.
|
|
63
|
-
|
|
64
|
-
#### fn
|
|
65
|
-
|
|
66
|
-
Type: `Function`
|
|
67
|
-
|
|
68
|
-
Promise-returning/async function.
|
|
69
|
-
|
|
70
|
-
#### args
|
|
71
|
-
|
|
72
|
-
Any arguments to pass through to `fn`.
|
|
73
|
-
|
|
74
|
-
Support for passing arguments on to the `fn` is provided in order to be able to avoid creating unnecessary closures. You probably don't need this optimization unless you're pushing a *lot* of functions.
|
|
75
|
-
|
|
76
|
-
Warning: Avoid calling the same `limit` function inside a function that is already limited by it. This can create a deadlock where inner tasks never run. Use a separate limiter for inner tasks.
|
|
77
|
-
|
|
78
|
-
### limit.map(iterable, mapperFunction)
|
|
79
|
-
|
|
80
|
-
Process an iterable of inputs with limited concurrency.
|
|
81
|
-
|
|
82
|
-
The mapper function receives the item value and its index.
|
|
83
|
-
|
|
84
|
-
Returns a promise equivalent to `Promise.all(Array.from(iterable, (item, index) => limit(mapperFunction, item, index)))`.
|
|
85
|
-
|
|
86
|
-
This is a convenience function for processing inputs that arrive in batches. For more complex use cases, see [p-map](https://github.com/sindresorhus/p-map).
|
|
87
|
-
|
|
88
|
-
### limit.activeCount
|
|
89
|
-
|
|
90
|
-
The number of promises that are currently running.
|
|
91
|
-
|
|
92
|
-
### limit.pendingCount
|
|
93
|
-
|
|
94
|
-
The number of promises that are waiting to run (i.e. their internal `fn` was not called yet).
|
|
95
|
-
|
|
96
|
-
### limit.clearQueue()
|
|
97
|
-
|
|
98
|
-
Discard pending promises that are waiting to run.
|
|
99
|
-
|
|
100
|
-
This might be useful if you want to tear down the queue at the end of your program's lifecycle or discard any function calls referencing an intermediary state of your app.
|
|
101
|
-
|
|
102
|
-
Note: This does not cancel promises that are already running.
|
|
103
|
-
|
|
104
|
-
When `rejectOnClear` is enabled, pending promises are rejected with an `AbortError`.
|
|
105
|
-
This is recommended if you await the returned promises, for example with `Promise.all`, so pending tasks do not remain unresolved after `clearQueue()`.
|
|
106
|
-
|
|
107
|
-
### limit.concurrency
|
|
108
|
-
|
|
109
|
-
Get or set the concurrency limit.
|
|
110
|
-
|
|
111
|
-
### limitFunction(fn, options) <sup>named export</sup>
|
|
112
|
-
|
|
113
|
-
Returns a function with limited concurrency.
|
|
114
|
-
|
|
115
|
-
The returned function manages its own concurrent executions, allowing you to call it multiple times without exceeding the specified concurrency limit.
|
|
116
|
-
|
|
117
|
-
Ideal for scenarios where you need to control the number of simultaneous executions of a single function, rather than managing concurrency across multiple functions.
|
|
118
|
-
|
|
119
|
-
```js
|
|
120
|
-
import {limitFunction} from 'p-limit';
|
|
121
|
-
|
|
122
|
-
const limitedFunction = limitFunction(async () => {
|
|
123
|
-
return doSomething();
|
|
124
|
-
}, {concurrency: 1});
|
|
125
|
-
|
|
126
|
-
const input = Array.from({length: 10}, limitedFunction);
|
|
127
|
-
|
|
128
|
-
// Only one promise is run at once.
|
|
129
|
-
await Promise.all(input);
|
|
130
|
-
```
|
|
131
|
-
|
|
132
|
-
#### fn
|
|
133
|
-
|
|
134
|
-
Type: `Function`
|
|
135
|
-
|
|
136
|
-
Promise-returning/async function.
|
|
137
|
-
|
|
138
|
-
#### options
|
|
139
|
-
|
|
140
|
-
Type: `object`
|
|
141
|
-
|
|
142
|
-
#### concurrency
|
|
143
|
-
|
|
144
|
-
Type: `number`\
|
|
145
|
-
Minimum: `1`
|
|
146
|
-
|
|
147
|
-
Concurrency limit.
|
|
148
|
-
|
|
149
|
-
#### rejectOnClear
|
|
150
|
-
|
|
151
|
-
Type: `boolean`\
|
|
152
|
-
Default: `false`
|
|
153
|
-
|
|
154
|
-
Reject pending promises with an `AbortError` when `clearQueue()` is called.
|
|
155
|
-
This is recommended if you await the returned promises, for example with `Promise.all`, so pending tasks do not remain unresolved after `clearQueue()`.
|
|
156
|
-
|
|
157
|
-
## Recipes
|
|
158
|
-
|
|
159
|
-
See [recipes.md](recipes.md) for common use cases and patterns.
|
|
160
|
-
|
|
161
|
-
## FAQ
|
|
162
|
-
|
|
163
|
-
### How is this different from the [`p-queue`](https://github.com/sindresorhus/p-queue) package?
|
|
164
|
-
|
|
165
|
-
This package is only about limiting the number of concurrent executions, while `p-queue` is a fully featured queue implementation with lots of different options, introspection, and ability to pause the queue.
|
|
166
|
-
|
|
167
|
-
## Related
|
|
168
|
-
|
|
169
|
-
- [p-throttle](https://github.com/sindresorhus/p-throttle) - Throttle promise-returning & async functions
|
|
170
|
-
- [p-debounce](https://github.com/sindresorhus/p-debounce) - Debounce promise-returning & async functions
|
|
171
|
-
- [p-map](https://github.com/sindresorhus/p-map) - Run promise-returning & async functions concurrently with different inputs
|
|
172
|
-
- [p-all](https://github.com/sindresorhus/p-all) - Run promise-returning & async functions concurrently with optional limited concurrency
|
|
173
|
-
- [More…](https://github.com/sindresorhus/promise-fun)
|