@openai/agents-extensions 0.8.5 → 0.9.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/metadata.js +2 -2
- package/dist/metadata.mjs +2 -2
- package/dist/sandbox/blaxel/index.d.ts +2 -0
- package/dist/sandbox/blaxel/index.js +19 -0
- package/dist/sandbox/blaxel/index.js.map +1 -0
- package/dist/sandbox/blaxel/index.mjs +3 -0
- package/dist/sandbox/blaxel/index.mjs.map +1 -0
- package/dist/sandbox/blaxel/mounts.d.ts +101 -0
- package/dist/sandbox/blaxel/mounts.js +542 -0
- package/dist/sandbox/blaxel/mounts.js.map +1 -0
- package/dist/sandbox/blaxel/mounts.mjs +529 -0
- package/dist/sandbox/blaxel/mounts.mjs.map +1 -0
- package/dist/sandbox/blaxel/sandbox.d.ts +155 -0
- package/dist/sandbox/blaxel/sandbox.js +1110 -0
- package/dist/sandbox/blaxel/sandbox.js.map +1 -0
- package/dist/sandbox/blaxel/sandbox.mjs +1072 -0
- package/dist/sandbox/blaxel/sandbox.mjs.map +1 -0
- package/dist/sandbox/cloudflare/index.d.ts +2 -0
- package/dist/sandbox/cloudflare/index.js +19 -0
- package/dist/sandbox/cloudflare/index.js.map +1 -0
- package/dist/sandbox/cloudflare/index.mjs +3 -0
- package/dist/sandbox/cloudflare/index.mjs.map +1 -0
- package/dist/sandbox/cloudflare/mounts.d.ts +28 -0
- package/dist/sandbox/cloudflare/mounts.js +150 -0
- package/dist/sandbox/cloudflare/mounts.js.map +1 -0
- package/dist/sandbox/cloudflare/mounts.mjs +143 -0
- package/dist/sandbox/cloudflare/mounts.mjs.map +1 -0
- package/dist/sandbox/cloudflare/sandbox.d.ts +91 -0
- package/dist/sandbox/cloudflare/sandbox.js +1163 -0
- package/dist/sandbox/cloudflare/sandbox.js.map +1 -0
- package/dist/sandbox/cloudflare/sandbox.mjs +1125 -0
- package/dist/sandbox/cloudflare/sandbox.mjs.map +1 -0
- package/dist/sandbox/daytona/index.d.ts +2 -0
- package/dist/sandbox/daytona/index.js +19 -0
- package/dist/sandbox/daytona/index.js.map +1 -0
- package/dist/sandbox/daytona/index.mjs +3 -0
- package/dist/sandbox/daytona/index.mjs.map +1 -0
- package/dist/sandbox/daytona/mounts.d.ts +11 -0
- package/dist/sandbox/daytona/mounts.js +17 -0
- package/dist/sandbox/daytona/mounts.js.map +1 -0
- package/dist/sandbox/daytona/mounts.mjs +12 -0
- package/dist/sandbox/daytona/mounts.mjs.map +1 -0
- package/dist/sandbox/daytona/sandbox.d.ts +160 -0
- package/dist/sandbox/daytona/sandbox.js +938 -0
- package/dist/sandbox/daytona/sandbox.js.map +1 -0
- package/dist/sandbox/daytona/sandbox.mjs +900 -0
- package/dist/sandbox/daytona/sandbox.mjs.map +1 -0
- package/dist/sandbox/e2b/index.d.ts +2 -0
- package/dist/sandbox/e2b/index.js +19 -0
- package/dist/sandbox/e2b/index.js.map +1 -0
- package/dist/sandbox/e2b/index.mjs +3 -0
- package/dist/sandbox/e2b/index.mjs.map +1 -0
- package/dist/sandbox/e2b/mounts.d.ts +11 -0
- package/dist/sandbox/e2b/mounts.js +17 -0
- package/dist/sandbox/e2b/mounts.js.map +1 -0
- package/dist/sandbox/e2b/mounts.mjs +12 -0
- package/dist/sandbox/e2b/mounts.mjs.map +1 -0
- package/dist/sandbox/e2b/sandbox.d.ts +169 -0
- package/dist/sandbox/e2b/sandbox.js +829 -0
- package/dist/sandbox/e2b/sandbox.js.map +1 -0
- package/dist/sandbox/e2b/sandbox.mjs +791 -0
- package/dist/sandbox/e2b/sandbox.mjs.map +1 -0
- package/dist/sandbox/modal/index.d.ts +2 -0
- package/dist/sandbox/modal/index.js +19 -0
- package/dist/sandbox/modal/index.js.map +1 -0
- package/dist/sandbox/modal/index.mjs +3 -0
- package/dist/sandbox/modal/index.mjs.map +1 -0
- package/dist/sandbox/modal/mounts.d.ts +24 -0
- package/dist/sandbox/modal/mounts.js +194 -0
- package/dist/sandbox/modal/mounts.js.map +1 -0
- package/dist/sandbox/modal/mounts.mjs +188 -0
- package/dist/sandbox/modal/mounts.mjs.map +1 -0
- package/dist/sandbox/modal/sandbox.d.ts +220 -0
- package/dist/sandbox/modal/sandbox.js +1621 -0
- package/dist/sandbox/modal/sandbox.js.map +1 -0
- package/dist/sandbox/modal/sandbox.mjs +1581 -0
- package/dist/sandbox/modal/sandbox.mjs.map +1 -0
- package/dist/sandbox/runloop/index.d.ts +2 -0
- package/dist/sandbox/runloop/index.js +19 -0
- package/dist/sandbox/runloop/index.js.map +1 -0
- package/dist/sandbox/runloop/index.mjs +3 -0
- package/dist/sandbox/runloop/index.mjs.map +1 -0
- package/dist/sandbox/runloop/mounts.d.ts +11 -0
- package/dist/sandbox/runloop/mounts.js +17 -0
- package/dist/sandbox/runloop/mounts.js.map +1 -0
- package/dist/sandbox/runloop/mounts.mjs +12 -0
- package/dist/sandbox/runloop/mounts.mjs.map +1 -0
- package/dist/sandbox/runloop/sandbox.d.ts +266 -0
- package/dist/sandbox/runloop/sandbox.js +1390 -0
- package/dist/sandbox/runloop/sandbox.js.map +1 -0
- package/dist/sandbox/runloop/sandbox.mjs +1346 -0
- package/dist/sandbox/runloop/sandbox.mjs.map +1 -0
- package/dist/sandbox/shared/archive.d.ts +34 -0
- package/dist/sandbox/shared/archive.js +397 -0
- package/dist/sandbox/shared/archive.js.map +1 -0
- package/dist/sandbox/shared/archive.mjs +389 -0
- package/dist/sandbox/shared/archive.mjs.map +1 -0
- package/dist/sandbox/shared/editor.d.ts +17 -0
- package/dist/sandbox/shared/editor.js +65 -0
- package/dist/sandbox/shared/editor.js.map +1 -0
- package/dist/sandbox/shared/editor.mjs +61 -0
- package/dist/sandbox/shared/editor.mjs.map +1 -0
- package/dist/sandbox/shared/environment.d.ts +1 -0
- package/dist/sandbox/shared/environment.js +13 -0
- package/dist/sandbox/shared/environment.js.map +1 -0
- package/dist/sandbox/shared/environment.mjs +2 -0
- package/dist/sandbox/shared/environment.mjs.map +1 -0
- package/dist/sandbox/shared/git.d.ts +4 -0
- package/dist/sandbox/shared/git.js +20 -0
- package/dist/sandbox/shared/git.js.map +1 -0
- package/dist/sandbox/shared/git.mjs +17 -0
- package/dist/sandbox/shared/git.mjs.map +1 -0
- package/dist/sandbox/shared/inContainerMounts.d.ts +40 -0
- package/dist/sandbox/shared/inContainerMounts.js +670 -0
- package/dist/sandbox/shared/inContainerMounts.js.map +1 -0
- package/dist/sandbox/shared/inContainerMounts.mjs +662 -0
- package/dist/sandbox/shared/inContainerMounts.mjs.map +1 -0
- package/dist/sandbox/shared/index.d.ts +23 -0
- package/dist/sandbox/shared/index.js +112 -0
- package/dist/sandbox/shared/index.js.map +1 -0
- package/dist/sandbox/shared/index.mjs +18 -0
- package/dist/sandbox/shared/index.mjs.map +1 -0
- package/dist/sandbox/shared/localSources.d.ts +8 -0
- package/dist/sandbox/shared/localSources.js +378 -0
- package/dist/sandbox/shared/localSources.js.map +1 -0
- package/dist/sandbox/shared/localSources.mjs +372 -0
- package/dist/sandbox/shared/localSources.mjs.map +1 -0
- package/dist/sandbox/shared/manifest.d.ts +38 -0
- package/dist/sandbox/shared/manifest.js +254 -0
- package/dist/sandbox/shared/manifest.js.map +1 -0
- package/dist/sandbox/shared/manifest.mjs +233 -0
- package/dist/sandbox/shared/manifest.mjs.map +1 -0
- package/dist/sandbox/shared/media.d.ts +1 -0
- package/dist/sandbox/shared/media.js +10 -0
- package/dist/sandbox/shared/media.js.map +1 -0
- package/dist/sandbox/shared/media.mjs +2 -0
- package/dist/sandbox/shared/media.mjs.map +1 -0
- package/dist/sandbox/shared/metadata.d.ts +7 -0
- package/dist/sandbox/shared/metadata.js +87 -0
- package/dist/sandbox/shared/metadata.js.map +1 -0
- package/dist/sandbox/shared/metadata.mjs +81 -0
- package/dist/sandbox/shared/metadata.mjs.map +1 -0
- package/dist/sandbox/shared/output.d.ts +1 -0
- package/dist/sandbox/shared/output.js +8 -0
- package/dist/sandbox/shared/output.js.map +1 -0
- package/dist/sandbox/shared/output.mjs +2 -0
- package/dist/sandbox/shared/output.mjs.map +1 -0
- package/dist/sandbox/shared/paths.d.ts +27 -0
- package/dist/sandbox/shared/paths.js +245 -0
- package/dist/sandbox/shared/paths.js.map +1 -0
- package/dist/sandbox/shared/paths.mjs +236 -0
- package/dist/sandbox/shared/paths.mjs.map +1 -0
- package/dist/sandbox/shared/ports.d.ts +14 -0
- package/dist/sandbox/shared/ports.js +75 -0
- package/dist/sandbox/shared/ports.js.map +1 -0
- package/dist/sandbox/shared/ports.mjs +69 -0
- package/dist/sandbox/shared/ports.mjs.map +1 -0
- package/dist/sandbox/shared/process.d.ts +16 -0
- package/dist/sandbox/shared/process.js +90 -0
- package/dist/sandbox/shared/process.js.map +1 -0
- package/dist/sandbox/shared/process.mjs +86 -0
- package/dist/sandbox/shared/process.mjs.map +1 -0
- package/dist/sandbox/shared/pty.d.ts +81 -0
- package/dist/sandbox/shared/pty.js +382 -0
- package/dist/sandbox/shared/pty.js.map +1 -0
- package/dist/sandbox/shared/pty.mjs +335 -0
- package/dist/sandbox/shared/pty.mjs.map +1 -0
- package/dist/sandbox/shared/runAs.d.ts +46 -0
- package/dist/sandbox/shared/runAs.js +149 -0
- package/dist/sandbox/shared/runAs.js.map +1 -0
- package/dist/sandbox/shared/runAs.mjs +141 -0
- package/dist/sandbox/shared/runAs.mjs.map +1 -0
- package/dist/sandbox/shared/session.d.ts +16 -0
- package/dist/sandbox/shared/session.js +138 -0
- package/dist/sandbox/shared/session.js.map +1 -0
- package/dist/sandbox/shared/session.mjs +128 -0
- package/dist/sandbox/shared/session.mjs.map +1 -0
- package/dist/sandbox/shared/sessionBase.d.ts +90 -0
- package/dist/sandbox/shared/sessionBase.js +446 -0
- package/dist/sandbox/shared/sessionBase.js.map +1 -0
- package/dist/sandbox/shared/sessionBase.mjs +442 -0
- package/dist/sandbox/shared/sessionBase.mjs.map +1 -0
- package/dist/sandbox/shared/sessionState.d.ts +7 -0
- package/dist/sandbox/shared/sessionState.js +35 -0
- package/dist/sandbox/shared/sessionState.js.map +1 -0
- package/dist/sandbox/shared/sessionState.mjs +31 -0
- package/dist/sandbox/shared/sessionState.mjs.map +1 -0
- package/dist/sandbox/shared/snapshots.d.ts +9 -0
- package/dist/sandbox/shared/snapshots.js +62 -0
- package/dist/sandbox/shared/snapshots.js.map +1 -0
- package/dist/sandbox/shared/snapshots.mjs +57 -0
- package/dist/sandbox/shared/snapshots.mjs.map +1 -0
- package/dist/sandbox/shared/typeGuards.d.ts +10 -0
- package/dist/sandbox/shared/typeGuards.js +50 -0
- package/dist/sandbox/shared/typeGuards.js.map +1 -0
- package/dist/sandbox/shared/typeGuards.mjs +38 -0
- package/dist/sandbox/shared/typeGuards.mjs.map +1 -0
- package/dist/sandbox/shared/types.d.ts +24 -0
- package/dist/sandbox/shared/types.js +3 -0
- package/dist/sandbox/shared/types.js.map +1 -0
- package/dist/sandbox/shared/types.mjs +2 -0
- package/dist/sandbox/shared/types.mjs.map +1 -0
- package/dist/sandbox/vercel/index.d.ts +1 -0
- package/dist/sandbox/vercel/index.js +18 -0
- package/dist/sandbox/vercel/index.js.map +1 -0
- package/dist/sandbox/vercel/index.mjs +2 -0
- package/dist/sandbox/vercel/index.mjs.map +1 -0
- package/dist/sandbox/vercel/sandbox.d.ts +135 -0
- package/dist/sandbox/vercel/sandbox.js +1001 -0
- package/dist/sandbox/vercel/sandbox.js.map +1 -0
- package/dist/sandbox/vercel/sandbox.mjs +963 -0
- package/dist/sandbox/vercel/sandbox.mjs.map +1 -0
- package/package.json +108 -4
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.assertConfiguredExposedPort = assertConfiguredExposedPort;
|
|
4
|
+
exports.getCachedExposedPortEndpoint = getCachedExposedPortEndpoint;
|
|
5
|
+
exports.recordResolvedExposedPortEndpoint = recordResolvedExposedPortEndpoint;
|
|
6
|
+
exports.parseExposedPortEndpoint = parseExposedPortEndpoint;
|
|
7
|
+
const sandbox_1 = require("@openai/agents-core/sandbox");
|
|
8
|
+
function assertConfiguredExposedPort(args) {
|
|
9
|
+
const port = (0, sandbox_1.normalizeExposedPort)(args.port);
|
|
10
|
+
if (args.allowOnDemand) {
|
|
11
|
+
return port;
|
|
12
|
+
}
|
|
13
|
+
const configuredPorts = args.configuredPorts?.map((entry) => (0, sandbox_1.normalizeExposedPort)(entry));
|
|
14
|
+
if (!configuredPorts?.includes(port)) {
|
|
15
|
+
throw new sandbox_1.SandboxConfigurationError(`${args.providerName} exposed port ${port} was not configured. Configure exposedPorts with ${port} before resolving it.`, {
|
|
16
|
+
provider: args.providerName,
|
|
17
|
+
port,
|
|
18
|
+
configuredPorts: configuredPorts ?? [],
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
return port;
|
|
22
|
+
}
|
|
23
|
+
function getCachedExposedPortEndpoint(state, port) {
|
|
24
|
+
return (0, sandbox_1.getRecordedExposedPortEndpoint)(state, port);
|
|
25
|
+
}
|
|
26
|
+
function recordResolvedExposedPortEndpoint(state, requestedPort, endpoint) {
|
|
27
|
+
return (0, sandbox_1.recordExposedPortEndpoint)(state, endpoint, requestedPort);
|
|
28
|
+
}
|
|
29
|
+
function parseExposedPortEndpoint(value, args) {
|
|
30
|
+
const trimmed = value.trim();
|
|
31
|
+
if (!trimmed) {
|
|
32
|
+
throw new sandbox_1.SandboxProviderError(`${args.providerName} returned an empty exposed port ${args.source}.`, {
|
|
33
|
+
provider: args.providerName,
|
|
34
|
+
source: args.source,
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
const hasScheme = /^[a-z][a-z0-9+.-]*:\/\//iu.test(trimmed);
|
|
38
|
+
let parsed;
|
|
39
|
+
try {
|
|
40
|
+
parsed = new URL(hasScheme ? trimmed : `http://${trimmed}`);
|
|
41
|
+
}
|
|
42
|
+
catch (error) {
|
|
43
|
+
throw new sandbox_1.SandboxProviderError(`${args.providerName} returned an invalid exposed port ${args.source}: ${trimmed}`, {
|
|
44
|
+
provider: args.providerName,
|
|
45
|
+
source: args.source,
|
|
46
|
+
value: trimmed,
|
|
47
|
+
cause: error instanceof Error ? error.message : String(error),
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
const host = parsed.hostname;
|
|
51
|
+
if (!host) {
|
|
52
|
+
throw new sandbox_1.SandboxProviderError(`${args.providerName} returned an exposed port ${args.source} without a host: ${trimmed}`, {
|
|
53
|
+
provider: args.providerName,
|
|
54
|
+
source: args.source,
|
|
55
|
+
value: trimmed,
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
const explicitPort = parsed.port.length > 0 ? Number.parseInt(parsed.port, 10) : undefined;
|
|
59
|
+
const tls = hasScheme
|
|
60
|
+
? parsed.protocol === 'https:' || parsed.protocol === 'wss:'
|
|
61
|
+
: explicitPort === undefined;
|
|
62
|
+
const port = (0, sandbox_1.normalizeExposedPort)(explicitPort ?? (tls ? 443 : 80));
|
|
63
|
+
const query = [parsed.search.replace(/^\?/u, ''), args.query]
|
|
64
|
+
.filter((entry) => typeof entry === 'string')
|
|
65
|
+
.filter((entry) => entry.length > 0)
|
|
66
|
+
.join('&');
|
|
67
|
+
return {
|
|
68
|
+
host,
|
|
69
|
+
port,
|
|
70
|
+
tls,
|
|
71
|
+
query,
|
|
72
|
+
url: hasScheme ? trimmed : undefined,
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
//# sourceMappingURL=ports.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ports.js","sourceRoot":"","sources":["../../../src/sandbox/shared/ports.ts"],"names":[],"mappings":";;AAUA,kEAyBC;AAED,oEAKC;AAED,8EAMC;AAED,4DAiEC;AArHD,yDAQqC;AAErC,SAAgB,2BAA2B,CAAC,IAK3C;IACC,MAAM,IAAI,GAAG,IAAA,8BAAoB,EAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAC7C,IAAI,IAAI,CAAC,aAAa,EAAE,CAAC;QACvB,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AC,EAAE,CAAC,CAAC,CAAC;IACpE,MAAM,KAAK,GAAG,CAAC,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC,EAAE,IAAI,CAAC,KAAK,CAAC;SAC1D,MAAM,CAAC,CAAC,KAAK,EAAmB,EAAE,CAAC,OAAO,KAAK,KAAK,QAAQ,CAAC;SAC7D,MAAM,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,MAAM,GAAG,CAAC,CAAC;SACnC,IAAI,CAAC,GAAG,CAAC,CAAC;IAEb,OAAO;QACL,IAAI;QACJ,IAAI;QACJ,GAAG;QACH,KAAK;QACL,GAAG,EAAE,SAAS,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,SAAS;KACrC,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { SandboxConfigurationError, SandboxProviderError, getRecordedExposedPortEndpoint, normalizeExposedPort, recordExposedPortEndpoint, } from '@openai/agents-core/sandbox';
|
|
2
|
+
export function assertConfiguredExposedPort(args) {
|
|
3
|
+
const port = normalizeExposedPort(args.port);
|
|
4
|
+
if (args.allowOnDemand) {
|
|
5
|
+
return port;
|
|
6
|
+
}
|
|
7
|
+
const configuredPorts = args.configuredPorts?.map((entry) => normalizeExposedPort(entry));
|
|
8
|
+
if (!configuredPorts?.includes(port)) {
|
|
9
|
+
throw new SandboxConfigurationError(`${args.providerName} exposed port ${port} was not configured. Configure exposedPorts with ${port} before resolving it.`, {
|
|
10
|
+
provider: args.providerName,
|
|
11
|
+
port,
|
|
12
|
+
configuredPorts: configuredPorts ?? [],
|
|
13
|
+
});
|
|
14
|
+
}
|
|
15
|
+
return port;
|
|
16
|
+
}
|
|
17
|
+
export function getCachedExposedPortEndpoint(state, port) {
|
|
18
|
+
return getRecordedExposedPortEndpoint(state, port);
|
|
19
|
+
}
|
|
20
|
+
export function recordResolvedExposedPortEndpoint(state, requestedPort, endpoint) {
|
|
21
|
+
return recordExposedPortEndpoint(state, endpoint, requestedPort);
|
|
22
|
+
}
|
|
23
|
+
export function parseExposedPortEndpoint(value, args) {
|
|
24
|
+
const trimmed = value.trim();
|
|
25
|
+
if (!trimmed) {
|
|
26
|
+
throw new SandboxProviderError(`${args.providerName} returned an empty exposed port ${args.source}.`, {
|
|
27
|
+
provider: args.providerName,
|
|
28
|
+
source: args.source,
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
const hasScheme = /^[a-z][a-z0-9+.-]*:\/\//iu.test(trimmed);
|
|
32
|
+
let parsed;
|
|
33
|
+
try {
|
|
34
|
+
parsed = new URL(hasScheme ? trimmed : `http://${trimmed}`);
|
|
35
|
+
}
|
|
36
|
+
catch (error) {
|
|
37
|
+
throw new SandboxProviderError(`${args.providerName} returned an invalid exposed port ${args.source}: ${trimmed}`, {
|
|
38
|
+
provider: args.providerName,
|
|
39
|
+
source: args.source,
|
|
40
|
+
value: trimmed,
|
|
41
|
+
cause: error instanceof Error ? error.message : String(error),
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
const host = parsed.hostname;
|
|
45
|
+
if (!host) {
|
|
46
|
+
throw new SandboxProviderError(`${args.providerName} returned an exposed port ${args.source} without a host: ${trimmed}`, {
|
|
47
|
+
provider: args.providerName,
|
|
48
|
+
source: args.source,
|
|
49
|
+
value: trimmed,
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
const explicitPort = parsed.port.length > 0 ? Number.parseInt(parsed.port, 10) : undefined;
|
|
53
|
+
const tls = hasScheme
|
|
54
|
+
? parsed.protocol === 'https:' || parsed.protocol === 'wss:'
|
|
55
|
+
: explicitPort === undefined;
|
|
56
|
+
const port = normalizeExposedPort(explicitPort ?? (tls ? 443 : 80));
|
|
57
|
+
const query = [parsed.search.replace(/^\?/u, ''), args.query]
|
|
58
|
+
.filter((entry) => typeof entry === 'string')
|
|
59
|
+
.filter((entry) => entry.length > 0)
|
|
60
|
+
.join('&');
|
|
61
|
+
return {
|
|
62
|
+
host,
|
|
63
|
+
port,
|
|
64
|
+
tls,
|
|
65
|
+
query,
|
|
66
|
+
url: hasScheme ? trimmed : undefined,
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
//# sourceMappingURL=ports.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ports.mjs","sourceRoot":"","sources":["../../../src/sandbox/shared/ports.ts"],"names":[],"mappings":"OAAO,EACL,yBAAyB,EACzB,oBAAoB,EAEpB,8BAA8B,EAC9B,oBAAoB,EACpB,yBAAyB,GAE1B,MAAM,6BAA6B;AAEpC,MAAM,UAAU,2BAA2B,CAAC,IAK3C;IACC,MAAM,IAAI,GAAG,oBAAoB,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAC7C,IAAI,IAAI,CAAC,aAAa,EAAE,CAAC;QACvB,OAAO,IAAI,CAAC;IACd,CAAC;IAED,MAAM,eAAe,GAAG,IAAI,CAAC,eAAe,EAAE,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAC1D,oBAAoB,CAAC,KAAK,CAAC,CAC5B,CAAC;IACF,IAAI,CAAC,eAAe,EAAE,QAAQ,CAAC,IAAI,CAAC,EAAE,CAAC;QACrC,MAAM,IAAI,yBAAyB,CACjC,GAAG,IAAI,CAAC,YAAY,iBAAiB,IAAI,oDAAoD,IAAI,uBAAuB,EACxH;YACE,QAAQ,EAAE,IAAI,CAAC,YAAY;YAC3B,IAAI;YACJ,eAAe,EAAE,eAAe,IAAI,EAAE;SACvC,CACF,CAAC;IACJ,CAAC;IACD,OAAO,IAAI,CAAC;AACd,CAAC;AAED,MAAM,UAAU,4BAA4B,CAC1C,KAA0B,EAC1B,IAAY;IAEZ,OAAO,8BAA8B,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC;AACrD,CAAC;AAED,MAAM,UAAU,iCAAiC,CAC/C,KAA0B,EAC1B,aAAqB,EACrB,QAA6B;IAE7B,OAAO,yBAAyB,CAAC,KAAK,EA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+
};
|
|
9
|
+
export type RunSandboxProcessOptions = {
|
|
10
|
+
cwd?: string;
|
|
11
|
+
env?: NodeJS.ProcessEnv;
|
|
12
|
+
timeoutMs?: number;
|
|
13
|
+
maxOutputBytes?: number;
|
|
14
|
+
};
|
|
15
|
+
export declare function runSandboxProcess(command: string, args: string[], options?: RunSandboxProcessOptions): Promise<SandboxProcessResult>;
|
|
16
|
+
export declare function formatSandboxProcessError(result: SandboxProcessResult): string;
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.runSandboxProcess = runSandboxProcess;
|
|
4
|
+
exports.formatSandboxProcessError = formatSandboxProcessError;
|
|
5
|
+
const node_child_process_1 = require("node:child_process");
|
|
6
|
+
const DEFAULT_MAX_OUTPUT_BYTES = 1024 * 1024;
|
|
7
|
+
const FORCE_KILL_DELAY_MS = 5_000;
|
|
8
|
+
async function runSandboxProcess(command, args, options = {}) {
|
|
9
|
+
return new Promise((resolve) => {
|
|
10
|
+
const stdoutChunks = [];
|
|
11
|
+
const stderrChunks = [];
|
|
12
|
+
let stdoutBytes = 0;
|
|
13
|
+
let stderrBytes = 0;
|
|
14
|
+
let error;
|
|
15
|
+
let timedOut = false;
|
|
16
|
+
let closed = false;
|
|
17
|
+
let settled = false;
|
|
18
|
+
let timeout;
|
|
19
|
+
let forceKillTimeout;
|
|
20
|
+
const maxOutputBytes = options.maxOutputBytes ?? DEFAULT_MAX_OUTPUT_BYTES;
|
|
21
|
+
const child = (0, node_child_process_1.spawn)(command, args, {
|
|
22
|
+
cwd: options.cwd,
|
|
23
|
+
env: options.env,
|
|
24
|
+
stdio: ['ignore', 'pipe', 'pipe'],
|
|
25
|
+
});
|
|
26
|
+
const captureChunk = (chunks, currentBytes, chunk) => {
|
|
27
|
+
const remainingBytes = maxOutputBytes - currentBytes;
|
|
28
|
+
if (remainingBytes <= 0) {
|
|
29
|
+
return currentBytes;
|
|
30
|
+
}
|
|
31
|
+
const captured = chunk.length > remainingBytes
|
|
32
|
+
? chunk.subarray(0, remainingBytes)
|
|
33
|
+
: chunk;
|
|
34
|
+
chunks.push(captured);
|
|
35
|
+
return currentBytes + captured.length;
|
|
36
|
+
};
|
|
37
|
+
const finish = (status, signal) => {
|
|
38
|
+
if (settled) {
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
settled = true;
|
|
42
|
+
closed = true;
|
|
43
|
+
if (timeout) {
|
|
44
|
+
clearTimeout(timeout);
|
|
45
|
+
}
|
|
46
|
+
if (forceKillTimeout) {
|
|
47
|
+
clearTimeout(forceKillTimeout);
|
|
48
|
+
}
|
|
49
|
+
resolve({
|
|
50
|
+
status,
|
|
51
|
+
signal,
|
|
52
|
+
stdout: Buffer.concat(stdoutChunks).toString('utf8'),
|
|
53
|
+
stderr: Buffer.concat(stderrChunks).toString('utf8'),
|
|
54
|
+
error,
|
|
55
|
+
timedOut,
|
|
56
|
+
});
|
|
57
|
+
};
|
|
58
|
+
child.stdout.on('data', (chunk) => {
|
|
59
|
+
stdoutBytes = captureChunk(stdoutChunks, stdoutBytes, chunk);
|
|
60
|
+
});
|
|
61
|
+
child.stderr.on('data', (chunk) => {
|
|
62
|
+
stderrBytes = captureChunk(stderrChunks, stderrBytes, chunk);
|
|
63
|
+
});
|
|
64
|
+
child.on('error', (childError) => {
|
|
65
|
+
error = childError;
|
|
66
|
+
finish(null, null);
|
|
67
|
+
});
|
|
68
|
+
if (options.timeoutMs !== undefined) {
|
|
69
|
+
timeout = setTimeout(() => {
|
|
70
|
+
timedOut = true;
|
|
71
|
+
child.kill('SIGTERM');
|
|
72
|
+
forceKillTimeout = setTimeout(() => {
|
|
73
|
+
if (!closed) {
|
|
74
|
+
child.kill('SIGKILL');
|
|
75
|
+
}
|
|
76
|
+
}, FORCE_KILL_DELAY_MS);
|
|
77
|
+
}, options.timeoutMs);
|
|
78
|
+
}
|
|
79
|
+
child.on('close', (status, signal) => {
|
|
80
|
+
finish(status, signal);
|
|
81
|
+
});
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
function formatSandboxProcessError(result) {
|
|
85
|
+
if (result.timedOut) {
|
|
86
|
+
return 'process timed out';
|
|
87
|
+
}
|
|
88
|
+
return (result.stderr || result.stdout || result.error?.message || 'process failed');
|
|
89
|
+
}
|
|
90
|
+
//# sourceMappingURL=process.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"process.js","sourceRoot":"","sources":["../../../src/sandbox/shared/process.ts"],"names":[],"mappings":";;AAqBA,8CA2FC;AAED,8DASC;AA3HD,2DAA2C;AAkB3C,MAAM,wBAAwB,GAAG,IAAI,GAAG,IAAI,CAAC;AAC7C,MAAM,mBAAmB,GAAG,KAAK,CAAC;AAE3B,KAAK,UAAU,iBAAiB,CACrC,OAAe,EACf,IAAc,EACd,UAAoC,EAAE;IAEtC,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE;QAC7B,MAAM,YAAY,GAAa,EAAE,CAAC;QAClC,MAAM,YAAY,GAAa,EAAE,CAAC;QAClC,IAAI,WAAW,GAAG,CAAC,CAAC;QACpB,IAAI,WAAW,GAAG,CAAC,CAAC;QACpB,IAAI,KAAwB,CAAC;QAC7B,IAAI,QAAQ,GAAG,KAAK,CAAC;QACrB,IAAI,MAAM,GAAG,KAAK,CAAC;QACnB,IAAI,OAAO,GAAG,KAAK,CAAC;QACpB,IAAI,OAAmC,CAAC;QACxC,IAAI,gBAA4C,CAAC;QACjD,MAAM,cAAc,GAAG,OAAO,CAAC,cAAc,IAAI,wBAAwB,CAAC;QAE1E,MAAM,KAAK,GAAG,IAAA,0BAAK,EAAC,OAAO,EAAE,IAAI,EAAE;YACjC,GAAG,EAAE,OAAO,CAAC,GAAG;YAChB,GAAG,EAAE,OAAO,CAAC,GAAG;YAChB,KAAK,EAAE,CAAC,QAAQ,EAAE,MAAM,EAAE,MAAM,CAAC;SAClC,CAAC,CAAC;QAEH,M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,0 +1,86 @@
|
|
|
1
|
+
import { spawn } from 'node:child_process';
|
|
2
|
+
const DEFAULT_MAX_OUTPUT_BYTES = 1024 * 1024;
|
|
3
|
+
const FORCE_KILL_DELAY_MS = 5_000;
|
|
4
|
+
export async function runSandboxProcess(command, args, options = {}) {
|
|
5
|
+
return new Promise((resolve) => {
|
|
6
|
+
const stdoutChunks = [];
|
|
7
|
+
const stderrChunks = [];
|
|
8
|
+
let stdoutBytes = 0;
|
|
9
|
+
let stderrBytes = 0;
|
|
10
|
+
let error;
|
|
11
|
+
let timedOut = false;
|
|
12
|
+
let closed = false;
|
|
13
|
+
let settled = false;
|
|
14
|
+
let timeout;
|
|
15
|
+
let forceKillTimeout;
|
|
16
|
+
const maxOutputBytes = options.maxOutputBytes ?? DEFAULT_MAX_OUTPUT_BYTES;
|
|
17
|
+
const child = spawn(command, args, {
|
|
18
|
+
cwd: options.cwd,
|
|
19
|
+
env: options.env,
|
|
20
|
+
stdio: ['ignore', 'pipe', 'pipe'],
|
|
21
|
+
});
|
|
22
|
+
const captureChunk = (chunks, currentBytes, chunk) => {
|
|
23
|
+
const remainingBytes = maxOutputBytes - currentBytes;
|
|
24
|
+
if (remainingBytes <= 0) {
|
|
25
|
+
return currentBytes;
|
|
26
|
+
}
|
|
27
|
+
const captured = chunk.length > remainingBytes
|
|
28
|
+
? chunk.subarray(0, remainingBytes)
|
|
29
|
+
: chunk;
|
|
30
|
+
chunks.push(captured);
|
|
31
|
+
return currentBytes + captured.length;
|
|
32
|
+
};
|
|
33
|
+
const finish = (status, signal) => {
|
|
34
|
+
if (settled) {
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
settled = true;
|
|
38
|
+
closed = true;
|
|
39
|
+
if (timeout) {
|
|
40
|
+
clearTimeout(timeout);
|
|
41
|
+
}
|
|
42
|
+
if (forceKillTimeout) {
|
|
43
|
+
clearTimeout(forceKillTimeout);
|
|
44
|
+
}
|
|
45
|
+
resolve({
|
|
46
|
+
status,
|
|
47
|
+
signal,
|
|
48
|
+
stdout: Buffer.concat(stdoutChunks).toString('utf8'),
|
|
49
|
+
stderr: Buffer.concat(stderrChunks).toString('utf8'),
|
|
50
|
+
error,
|
|
51
|
+
timedOut,
|
|
52
|
+
});
|
|
53
|
+
};
|
|
54
|
+
child.stdout.on('data', (chunk) => {
|
|
55
|
+
stdoutBytes = captureChunk(stdoutChunks, stdoutBytes, chunk);
|
|
56
|
+
});
|
|
57
|
+
child.stderr.on('data', (chunk) => {
|
|
58
|
+
stderrBytes = captureChunk(stderrChunks, stderrBytes, chunk);
|
|
59
|
+
});
|
|
60
|
+
child.on('error', (childError) => {
|
|
61
|
+
error = childError;
|
|
62
|
+
finish(null, null);
|
|
63
|
+
});
|
|
64
|
+
if (options.timeoutMs !== undefined) {
|
|
65
|
+
timeout = setTimeout(() => {
|
|
66
|
+
timedOut = true;
|
|
67
|
+
child.kill('SIGTERM');
|
|
68
|
+
forceKillTimeout = setTimeout(() => {
|
|
69
|
+
if (!closed) {
|
|
70
|
+
child.kill('SIGKILL');
|
|
71
|
+
}
|
|
72
|
+
}, FORCE_KILL_DELAY_MS);
|
|
73
|
+
}, options.timeoutMs);
|
|
74
|
+
}
|
|
75
|
+
child.on('close', (status, signal) => {
|
|
76
|
+
finish(status, signal);
|
|
77
|
+
});
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
export function formatSandboxProcessError(result) {
|
|
81
|
+
if (result.timedOut) {
|
|
82
|
+
return 'process timed out';
|
|
83
|
+
}
|
|
84
|
+
return (result.stderr || result.stdout || result.error?.message || 'process failed');
|
|
85
|
+
}
|
|
86
|
+
//# sourceMappingURL=process.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"process.mjs","sourceRoot":"","sources":["../../../src/sandbox/shared/process.ts"],"names":[],"mappings":"OAAO,EAAE,KAAK,EAAE,MAAM,oBAAoB;AAkB1C,MAAM,wBAAwB,GAAG,IAAI,GAAG,IAAI,CAAC;AAC7C,M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,EAAE;gBACxB,QAAQ,GAAG,IAAI,CAAC;gBAChB,KAAK,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;gBACtB,gBAAgB,GAAG,UAAU,CAAC,GAAG,EAAE;oBACjC,IAAI,CAAC,MAAM,EAAE,CAAC;wBACZ,KAAK,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;oBACxB,CAAC;gBACH,CAAC,EAAE,mBAAmB,CAAC,CAAC;YAC1B,CAAC,EAAE,OAAO,CAAC,SAAS,CAAC,CAAC;QACxB,CAAC;QAED,KAAK,CAAC,EAAE,CAAC,OAAO,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,EAAE;YACnC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;QACzB,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC;AAED,MAAM,UAAU,yBAAyB,CACvC,MAA4B;IAE5B,IAAI,MAAM,CAAC,QAAQ,EAAE,CAAC;QACpB,OAAO,mBAAmB,CAAC;IAC7B,CAAC;IACD,OAAO,CACL,MAAM,CAAC,MAAM,IAAI,MAAM,CAAC,MAAM,IAAI,MAAM,CAAC,KAAK,EAAE,OAAO,IAAI,gBAAgB,CAC5E,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
export type PtyProcessEntry = {
|
|
2
|
+
tty: boolean;
|
|
3
|
+
output: string;
|
|
4
|
+
done: boolean;
|
|
5
|
+
exitCode: number | null;
|
|
6
|
+
lastUsed: number;
|
|
7
|
+
waiters: Set<() => void>;
|
|
8
|
+
sendInput?: (chars: string) => Promise<void>;
|
|
9
|
+
terminate?: () => Promise<void>;
|
|
10
|
+
};
|
|
11
|
+
export type PtyWebSocket = {
|
|
12
|
+
readyState?: number;
|
|
13
|
+
binaryType?: string;
|
|
14
|
+
send(data: string | Uint8Array | ArrayBuffer): void;
|
|
15
|
+
close(): void;
|
|
16
|
+
addEventListener?: (type: string, listener: (event: unknown) => void) => void;
|
|
17
|
+
removeEventListener?: (type: string, listener: (event: unknown) => void) => void;
|
|
18
|
+
on?: (type: string, listener: (...args: unknown[]) => void) => void;
|
|
19
|
+
off?: (type: string, listener: (...args: unknown[]) => void) => void;
|
|
20
|
+
removeListener?: (type: string, listener: (...args: unknown[]) => void) => void;
|
|
21
|
+
};
|
|
22
|
+
export declare function createPtyProcessEntry(args: {
|
|
23
|
+
tty?: boolean;
|
|
24
|
+
sendInput?: (chars: string) => Promise<void>;
|
|
25
|
+
terminate?: () => Promise<void>;
|
|
26
|
+
}): PtyProcessEntry;
|
|
27
|
+
export declare function appendPtyOutput(entry: PtyProcessEntry, chunk: string | Uint8Array | ArrayBuffer): void;
|
|
28
|
+
export declare function markPtyDone(entry: PtyProcessEntry, exitCode?: number | null): void;
|
|
29
|
+
export declare function watchPtyProcess(entry: PtyProcessEntry, wait: () => Promise<unknown>, exitCode: (result: unknown, error?: unknown) => number | null | undefined): void;
|
|
30
|
+
export declare function openPtyWebSocket(args: {
|
|
31
|
+
url: string;
|
|
32
|
+
providerName: string;
|
|
33
|
+
headers?: Record<string, string>;
|
|
34
|
+
headersUnsupportedUrl?: string;
|
|
35
|
+
timeoutMs?: number;
|
|
36
|
+
configure?: (socket: PtyWebSocket) => void | Promise<void>;
|
|
37
|
+
}): Promise<PtyWebSocket>;
|
|
38
|
+
export declare function addPtyWebSocketListener(socket: PtyWebSocket, type: string, listener: (event: unknown) => void): () => void;
|
|
39
|
+
export declare class PtyProcessRegistry {
|
|
40
|
+
private readonly processes;
|
|
41
|
+
register(entry: PtyProcessEntry): {
|
|
42
|
+
sessionId: number;
|
|
43
|
+
pruned?: PtyProcessEntry;
|
|
44
|
+
};
|
|
45
|
+
get(sessionId: number): PtyProcessEntry | undefined;
|
|
46
|
+
terminateAll(): Promise<void>;
|
|
47
|
+
finalize(sessionId: number): Promise<{
|
|
48
|
+
processId?: number;
|
|
49
|
+
exitCode?: number | null;
|
|
50
|
+
}>;
|
|
51
|
+
private pruneIfNeeded;
|
|
52
|
+
}
|
|
53
|
+
export declare function collectPtyOutput(args: {
|
|
54
|
+
entry: PtyProcessEntry;
|
|
55
|
+
yieldTimeMs: number;
|
|
56
|
+
maxOutputTokens?: number;
|
|
57
|
+
}): Promise<{
|
|
58
|
+
text: string;
|
|
59
|
+
originalTokenCount?: number;
|
|
60
|
+
}>;
|
|
61
|
+
export declare function writePtyStdin(args: {
|
|
62
|
+
providerName: string;
|
|
63
|
+
registry: PtyProcessRegistry;
|
|
64
|
+
sessionId: number;
|
|
65
|
+
chars?: string;
|
|
66
|
+
yieldTimeMs?: number;
|
|
67
|
+
maxOutputTokens?: number;
|
|
68
|
+
}): Promise<string>;
|
|
69
|
+
export declare function formatPtyExecUpdate(args: {
|
|
70
|
+
registry: PtyProcessRegistry;
|
|
71
|
+
sessionId: number;
|
|
72
|
+
entry: PtyProcessEntry;
|
|
73
|
+
startTime: number;
|
|
74
|
+
yieldTimeMs?: number;
|
|
75
|
+
maxOutputTokens?: number;
|
|
76
|
+
}): Promise<string>;
|
|
77
|
+
export declare function shellCommandForPty(args: {
|
|
78
|
+
cmd: string;
|
|
79
|
+
shell?: string;
|
|
80
|
+
login?: boolean;
|
|
81
|
+
}): string;
|