@inquir/compute-cli 0.4.3 → 0.4.4
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 +57 -2
- package/dist/commands/admin-tenants.d.ts.map +1 -1
- package/dist/commands/admin-tenants.js +8 -7
- package/dist/commands/admin-tenants.js.map +1 -1
- package/dist/commands/admin.js +2 -2
- package/dist/commands/admin.js.map +1 -1
- package/dist/commands/apps-replicas.d.ts +27 -0
- package/dist/commands/apps-replicas.d.ts.map +1 -0
- package/dist/commands/apps-replicas.js +278 -0
- package/dist/commands/apps-replicas.js.map +1 -0
- package/dist/commands/apps.d.ts +5 -3
- package/dist/commands/apps.d.ts.map +1 -1
- package/dist/commands/apps.js +58 -15
- package/dist/commands/apps.js.map +1 -1
- package/dist/commands/compose.d.ts +29 -0
- package/dist/commands/compose.d.ts.map +1 -0
- package/dist/commands/compose.js +159 -0
- package/dist/commands/compose.js.map +1 -0
- package/dist/commands/logout.js +1 -1
- package/dist/commands/logout.js.map +1 -1
- package/dist/commands/mcp.d.ts.map +1 -1
- package/dist/commands/mcp.js +9 -1
- package/dist/commands/mcp.js.map +1 -1
- package/dist/commands/sandbox.d.ts +58 -0
- package/dist/commands/sandbox.d.ts.map +1 -0
- package/dist/commands/sandbox.js +462 -0
- package/dist/commands/sandbox.js.map +1 -0
- package/dist/index.js +9 -0
- package/dist/index.js.map +1 -1
- package/dist/lib/mcp-replica-tools.d.ts +10 -0
- package/dist/lib/mcp-replica-tools.d.ts.map +1 -0
- package/dist/lib/mcp-replica-tools.js +77 -0
- package/dist/lib/mcp-replica-tools.js.map +1 -0
- package/dist/lib/mcp-sandbox-tools.d.ts +30 -0
- package/dist/lib/mcp-sandbox-tools.d.ts.map +1 -0
- package/dist/lib/mcp-sandbox-tools.js +211 -0
- package/dist/lib/mcp-sandbox-tools.js.map +1 -0
- package/dist/lib/replica-roles.d.ts +22 -0
- package/dist/lib/replica-roles.d.ts.map +1 -0
- package/dist/lib/replica-roles.js +39 -0
- package/dist/lib/replica-roles.js.map +1 -0
- package/dist/lib/sandbox-api.d.ts +165 -0
- package/dist/lib/sandbox-api.d.ts.map +1 -0
- package/dist/lib/sandbox-api.js +241 -0
- package/dist/lib/sandbox-api.js.map +1 -0
- package/dist/lib/tar-safety.d.ts +17 -0
- package/dist/lib/tar-safety.d.ts.map +1 -0
- package/dist/lib/tar-safety.js +135 -0
- package/dist/lib/tar-safety.js.map +1 -0
- package/dist/utils/api.d.ts +31 -2
- package/dist/utils/api.d.ts.map +1 -1
- package/dist/utils/api.js +61 -2
- package/dist/utils/api.js.map +1 -1
- package/dist/utils/auth.d.ts.map +1 -1
- package/dist/utils/auth.js +2 -4
- package/dist/utils/auth.js.map +1 -1
- package/dist/utils/context.d.ts +7 -0
- package/dist/utils/context.d.ts.map +1 -1
- package/dist/utils/context.js +23 -1
- package/dist/utils/context.js.map +1 -1
- package/dist/utils/errors.d.ts +11 -0
- package/dist/utils/errors.d.ts.map +1 -1
- package/dist/utils/errors.js +42 -7
- package/dist/utils/errors.js.map +1 -1
- package/dist/utils/package-metadata.js +1 -1
- package/package.json +2 -2
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Stateful replicas in `inquir mcp` (docs/roadmap/STATEFUL_REPLICAS.md §7.2).
|
|
3
|
+
* The `scale` input is the same object as inquir.yaml's services.web.scale
|
|
4
|
+
* and the API's (its JSON Schema is the SDK's SCALE_JSON_SCHEMA): an agent
|
|
5
|
+
* configures replicas exactly as a person does in the file or the dashboard.
|
|
6
|
+
*/
|
|
7
|
+
import { SCALE_JSON_SCHEMA } from '@inquir/compute';
|
|
8
|
+
import { deleteAppReplicaVolumes, getAppReplicas, rebuildAppReplica, resolveApplication, updateApplication, } from '../utils/api.js';
|
|
9
|
+
const app = { type: 'string', description: 'Application name or id' };
|
|
10
|
+
const ordinal = { type: 'integer', minimum: 0, maximum: 63, description: 'The replica ordinal (0..N-1)' };
|
|
11
|
+
function ordinalOf(value) {
|
|
12
|
+
if (typeof value !== 'number' || !Number.isInteger(value) || value < 0 || value > 63)
|
|
13
|
+
throw new Error('ordinal must be an integer from 0 to 63');
|
|
14
|
+
return value;
|
|
15
|
+
}
|
|
16
|
+
export const REPLICA_TOOLS = [
|
|
17
|
+
{
|
|
18
|
+
name: 'apps_scale_get',
|
|
19
|
+
description: 'Read an application\'s replica configuration and state: its scale block (as in inquir.yaml services.web.scale), ' +
|
|
20
|
+
'the keys inquir.yaml manages, every ordinal with its server, volume generation, release, role and conditions, the stateful ' +
|
|
21
|
+
'rollout, and the role endpoints (hostname, members, conflicts) with the application\'s conditions.',
|
|
22
|
+
inputSchema: { type: 'object', properties: { app }, required: ['app'], additionalProperties: false },
|
|
23
|
+
handler: async (args, apiOptions) => {
|
|
24
|
+
const resolved = await resolveApplication(String(args.app), apiOptions);
|
|
25
|
+
return getAppReplicas(resolved.id, apiOptions);
|
|
26
|
+
},
|
|
27
|
+
},
|
|
28
|
+
{
|
|
29
|
+
name: 'apps_scale_apply',
|
|
30
|
+
description: 'Alpha (may change and has limits; keep backups of the data). Apply a scale block to an application: the same object ' +
|
|
31
|
+
'as inquir.yaml services.web.scale (mode: stateful gives each ' +
|
|
32
|
+
'replica its own volume and private name <n>.<slug>; update.partition holds ordinals below it on their release). Keys the deployed ' +
|
|
33
|
+
'inquir.yaml declares are refused (MANAGED_BY_MANIFEST) unless override is true; the next Git deploy restores them.',
|
|
34
|
+
inputSchema: {
|
|
35
|
+
type: 'object',
|
|
36
|
+
properties: { app, scale: SCALE_JSON_SCHEMA, override: { type: 'boolean' } },
|
|
37
|
+
required: ['app', 'scale'],
|
|
38
|
+
additionalProperties: false,
|
|
39
|
+
},
|
|
40
|
+
handler: async (args, apiOptions) => {
|
|
41
|
+
const resolved = await resolveApplication(String(args.app), apiOptions);
|
|
42
|
+
if (!args.scale || typeof args.scale !== 'object' || Array.isArray(args.scale))
|
|
43
|
+
throw new Error('scale must be an object');
|
|
44
|
+
return updateApplication(resolved.id, {
|
|
45
|
+
scale: args.scale, ...(args.override === true ? { scaleOverride: true } : {}),
|
|
46
|
+
}, apiOptions);
|
|
47
|
+
},
|
|
48
|
+
},
|
|
49
|
+
{
|
|
50
|
+
name: 'apps_replica_rebuild',
|
|
51
|
+
description: 'Rebuild one replica of a stateful application on another server, on a new, empty volume generation (its ' +
|
|
52
|
+
'runtime.hooks.init or its image bootstraps the data; the old volume is kept for retentionDays). For a replica whose server is lost.',
|
|
53
|
+
inputSchema: {
|
|
54
|
+
type: 'object',
|
|
55
|
+
properties: { app, ordinal, reason: { type: 'string', maxLength: 500 } },
|
|
56
|
+
required: ['app', 'ordinal'],
|
|
57
|
+
additionalProperties: false,
|
|
58
|
+
},
|
|
59
|
+
handler: async (args, apiOptions) => {
|
|
60
|
+
const resolved = await resolveApplication(String(args.app), apiOptions);
|
|
61
|
+
return rebuildAppReplica(resolved.id, ordinalOf(args.ordinal), {
|
|
62
|
+
...(typeof args.reason === 'string' ? { reason: args.reason } : {}),
|
|
63
|
+
}, apiOptions);
|
|
64
|
+
},
|
|
65
|
+
},
|
|
66
|
+
{
|
|
67
|
+
name: 'apps_replica_delete_volume',
|
|
68
|
+
description: 'Delete the retained volumes of one replica of a stateful application (scaled down, or the generation a rebuild left). ' +
|
|
69
|
+
'The data cannot be recovered.',
|
|
70
|
+
inputSchema: { type: 'object', properties: { app, ordinal }, required: ['app', 'ordinal'], additionalProperties: false },
|
|
71
|
+
handler: async (args, apiOptions) => {
|
|
72
|
+
const resolved = await resolveApplication(String(args.app), apiOptions);
|
|
73
|
+
return deleteAppReplicaVolumes(resolved.id, ordinalOf(args.ordinal), apiOptions);
|
|
74
|
+
},
|
|
75
|
+
},
|
|
76
|
+
];
|
|
77
|
+
//# sourceMappingURL=mcp-replica-tools.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mcp-replica-tools.js","sourceRoot":"","sources":["../../src/lib/mcp-replica-tools.ts"],"names":[],"mappings":"AAAA;;;;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K,EAAE,IAAI,EAAE,UAAU,EAAE,EAAE;YAClC,MAAM,QAAQ,GAAG,MAAM,kBAAkB,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,UAAU,CAAC,CAAC;YACxE,OAAO,iBAAiB,CAAC,QAAQ,CAAC,EAAE,EAAE,SAAS,CAAC,IAAI,CAAC,OAAO,CAAC,EAAE;gBAC7D,GAAG,CAAC,OAAO,IAAI,CAAC,MAAM,KAAK,QAAQ,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,IAAI,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;aACpE,EAAE,UAAU,CAAC,CAAC;QACjB,CAAC;KACF;IACD;QACE,IAAI,EAAE,4BAA4B;QAClC,WAAW,EAAE,wHAAwH;YACnI,+BAA+B;QACjC,WAAW,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,UAAU,EAAE,EAAE,GAAG,EAAE,OAAO,EAAE,EAAE,QAAQ,EAAE,CAAC,KAAK,EAAE,SAAS,CAAC,EAAE,oBAAoB,EAAE,KAAK,EAAE;QACxH,OAAO,EAAE,KAAK,EAAE,IAAI,EAAE,UAAU,EAAE,EAAE;YAClC,MAAM,QAAQ,GAAG,MAAM,kBAAkB,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,UAAU,CAAC,CAAC;YACxE,OAAO,uBAAuB,CAAC,QAAQ,CAAC,EAAE,EAAE,SAAS,CAAC,IAAI,CAAC,OAAO,CAAC,EAAE,UAAU,CAAC,CAAC;QACnF,CAAC;KACF;CACF,CAAC"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The six sandbox tools of `inquir mcp` (docs/roadmap/SANDBOXES.md §6.4).
|
|
3
|
+
* Inputs are SandboxSpec and its operations, the same object as the REST
|
|
4
|
+
* body and the CLI flags. Output for the model is bounded: stdout and stderr
|
|
5
|
+
* at 64 KiB each, file reads at 64 KiB unless asked for less.
|
|
6
|
+
*/
|
|
7
|
+
import type { ApiRequestOptions } from '../utils/api.js';
|
|
8
|
+
/** stdout / stderr kept for the model, each. */
|
|
9
|
+
export declare const MCP_SANDBOX_OUTPUT_BYTES: number;
|
|
10
|
+
interface SandboxTool {
|
|
11
|
+
name: string;
|
|
12
|
+
description: string;
|
|
13
|
+
inputSchema: Record<string, unknown>;
|
|
14
|
+
handler: (args: Record<string, unknown>, apiOptions: ApiRequestOptions) => Promise<unknown>;
|
|
15
|
+
}
|
|
16
|
+
/** SandboxSpec as JSON Schema (§5.1). */
|
|
17
|
+
export declare const SANDBOX_SPEC_JSON_SCHEMA: Record<string, unknown>;
|
|
18
|
+
/** Keeps the first `limit` bytes of a stream for the model; counts the rest. */
|
|
19
|
+
export declare class BoundedText {
|
|
20
|
+
private readonly limit;
|
|
21
|
+
private chunks;
|
|
22
|
+
private kept;
|
|
23
|
+
truncated: boolean;
|
|
24
|
+
constructor(limit: number);
|
|
25
|
+
push(text: string): void;
|
|
26
|
+
text(): string;
|
|
27
|
+
}
|
|
28
|
+
export declare const SANDBOX_TOOLS: SandboxTool[];
|
|
29
|
+
export {};
|
|
30
|
+
//# sourceMappingURL=mcp-sandbox-tools.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mcp-sandbox-tools.d.ts","sourceRoot":"","sources":["../../src/lib/mcp-sandbox-tools.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAC;AAazD,gDAAgD;AAChD,eAAO,MAAM,wBAAwB,QAAY,CAAC;AAGlD,UAAU,WAAW;IACnB,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,MAAM,CAAC;IACpB,WAAW,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACrC,OAAO,EAAE,CAAC,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,UAAU,EAAE,iBAAiB,KAAK,OAAO,CAAC,OAAO,CAAC,CAAC;CAC7F;AAKD,yCAAyC;AACzC,eAAO,MAAM,wBAAwB,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAwB5D,CAAC;AAOF,gFAAgF;AAChF,qBAAa,WAAW;IAIV,OAAO,CAAC,QAAQ,CAAC,KAAK;IAHlC,OAAO,CAAC,MAAM,CAAgB;IAC9B,OAAO,CAAC,IAAI,CAAK;IACjB,SAAS,UAAS;gBACW,KAAK,EAAE,MAAM;IAC1C,IAAI,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI;IAYxB,IAAI,IAAI,MAAM;CAIf;AA4ID,eAAO,MAAM,aAAa,EAAE,WAAW,EAA4B,CAAC"}
|
|
@@ -0,0 +1,211 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The six sandbox tools of `inquir mcp` (docs/roadmap/SANDBOXES.md §6.4).
|
|
3
|
+
* Inputs are SandboxSpec and its operations, the same object as the REST
|
|
4
|
+
* body and the CLI flags. Output for the model is bounded: stdout and stderr
|
|
5
|
+
* at 64 KiB each, file reads at 64 KiB unless asked for less.
|
|
6
|
+
*/
|
|
7
|
+
import { sandboxPlanRequired } from '../utils/errors.js';
|
|
8
|
+
import { createSandbox, destroySandbox, execInSandbox, listSandboxes, readSandboxFile, resolveSandboxId, writeSandboxFile, } from './sandbox-api.js';
|
|
9
|
+
/** stdout / stderr kept for the model, each. */
|
|
10
|
+
export const MCP_SANDBOX_OUTPUT_BYTES = 64 * 1024;
|
|
11
|
+
const MCP_SANDBOX_READ_BYTES = 64 * 1024;
|
|
12
|
+
const duration = { anyOf: [{ type: 'string', pattern: '^(?:\\d+|(?:\\d+h)?(?:\\d+m)?(?:\\d+s)?)$' }, { type: 'integer', minimum: 1 }] };
|
|
13
|
+
const env = { type: 'object', additionalProperties: { type: 'string' }, description: 'Plain variables; never secrets or platform credentials' };
|
|
14
|
+
/** SandboxSpec as JSON Schema (§5.1). */
|
|
15
|
+
export const SANDBOX_SPEC_JSON_SCHEMA = {
|
|
16
|
+
type: 'object',
|
|
17
|
+
properties: {
|
|
18
|
+
name: { type: 'string', pattern: '^[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?$', description: 'Unique among your live sandboxes' },
|
|
19
|
+
image: { type: 'string', description: 'A configured sandbox image (default: Ubuntu 24.04, Node 22, Python 3.12, git)' },
|
|
20
|
+
region: { type: 'string', enum: ['auto', 'ru', 'nl'] },
|
|
21
|
+
resources: {
|
|
22
|
+
type: 'object',
|
|
23
|
+
properties: { vcpu: { type: 'number', exclusiveMinimum: 0 }, memoryMb: { type: 'integer', minimum: 256 }, diskGb: { type: 'number', exclusiveMinimum: 0 } },
|
|
24
|
+
additionalProperties: false,
|
|
25
|
+
},
|
|
26
|
+
network: {
|
|
27
|
+
type: 'object',
|
|
28
|
+
properties: {
|
|
29
|
+
mode: { type: 'string', enum: ['none', 'proxy'], description: 'none (default): no network; proxy: only the allowlisted hosts, downloads only' },
|
|
30
|
+
allow: { type: 'array', items: { type: 'string' }, description: 'Presets npm, pypi, github, or public hostnames' },
|
|
31
|
+
},
|
|
32
|
+
additionalProperties: false,
|
|
33
|
+
},
|
|
34
|
+
env,
|
|
35
|
+
lifetime: { type: 'object', properties: { idle: duration, max: duration }, additionalProperties: false },
|
|
36
|
+
project: { type: 'string' },
|
|
37
|
+
},
|
|
38
|
+
additionalProperties: false,
|
|
39
|
+
};
|
|
40
|
+
function utf8OrBase64(data) {
|
|
41
|
+
const text = data.toString('utf8');
|
|
42
|
+
return Buffer.from(text, 'utf8').equals(data) ? { content: text, encoding: 'utf8' } : { content: data.toString('base64'), encoding: 'base64' };
|
|
43
|
+
}
|
|
44
|
+
/** Keeps the first `limit` bytes of a stream for the model; counts the rest. */
|
|
45
|
+
export class BoundedText {
|
|
46
|
+
limit;
|
|
47
|
+
chunks = [];
|
|
48
|
+
kept = 0;
|
|
49
|
+
truncated = false;
|
|
50
|
+
constructor(limit) {
|
|
51
|
+
this.limit = limit;
|
|
52
|
+
}
|
|
53
|
+
push(text) {
|
|
54
|
+
const data = Buffer.from(text, 'utf8');
|
|
55
|
+
const room = this.limit - this.kept;
|
|
56
|
+
if (room <= 0) {
|
|
57
|
+
if (data.length > 0)
|
|
58
|
+
this.truncated = true;
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
61
|
+
if (data.length > room)
|
|
62
|
+
this.truncated = true;
|
|
63
|
+
const slice = data.subarray(0, room);
|
|
64
|
+
this.chunks.push(slice);
|
|
65
|
+
this.kept += slice.length;
|
|
66
|
+
}
|
|
67
|
+
text() {
|
|
68
|
+
// A cut inside a multi-byte character decodes to U+FFFD, never invalid JSON.
|
|
69
|
+
return Buffer.concat(this.chunks).toString('utf8');
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
function idOf(args) {
|
|
73
|
+
if (typeof args.id !== 'string' || !args.id)
|
|
74
|
+
throw new Error('id is required (a sandbox id or name)');
|
|
75
|
+
return args.id;
|
|
76
|
+
}
|
|
77
|
+
/** A plan without sandboxes (402 SANDBOX_PLAN_REQUIRED): tell the agent, and through it the person, where to upgrade. */
|
|
78
|
+
function withPlanHint(tool) {
|
|
79
|
+
return {
|
|
80
|
+
...tool,
|
|
81
|
+
handler: async (args, apiOptions) => {
|
|
82
|
+
try {
|
|
83
|
+
return await tool.handler(args, apiOptions);
|
|
84
|
+
}
|
|
85
|
+
catch (error) {
|
|
86
|
+
const plan = sandboxPlanRequired(error);
|
|
87
|
+
if (!plan)
|
|
88
|
+
throw error;
|
|
89
|
+
throw new Error(`SANDBOX_PLAN_REQUIRED: ${plan.title}. ${plan.explanation} ${plan.fix} Do not retry until the person has upgraded.`);
|
|
90
|
+
}
|
|
91
|
+
},
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
const TOOLS = [
|
|
95
|
+
{
|
|
96
|
+
name: 'sandbox_create',
|
|
97
|
+
description: 'Create an isolated, short-lived Linux sandbox (gVisor; Ubuntu, Node 22, Python 3.12, git) for code you have not verified: ' +
|
|
98
|
+
'generated code, tests, dependency installs, untrusted repos. Waits until it runs. Network is off unless network.mode is "proxy" ' +
|
|
99
|
+
'with an allowlist (downloads only). Never pass secrets. Destroy it with sandbox_destroy when done.',
|
|
100
|
+
inputSchema: SANDBOX_SPEC_JSON_SCHEMA,
|
|
101
|
+
handler: async (args, apiOptions) => {
|
|
102
|
+
const sandbox = await createSandbox(args, apiOptions, { wait: true });
|
|
103
|
+
return {
|
|
104
|
+
id: sandbox.id, name: sandbox.name, status: sandbox.status, expiresAt: sandbox.expiresAt, idleExpiresAt: sandbox.idleExpiresAt,
|
|
105
|
+
...(sandbox.failureCode ? { failureCode: sandbox.failureCode } : {}),
|
|
106
|
+
};
|
|
107
|
+
},
|
|
108
|
+
},
|
|
109
|
+
{
|
|
110
|
+
name: 'sandbox_exec',
|
|
111
|
+
description: 'Run a command in a sandbox and return its exit code and output (stdout and stderr, up to 64 KiB each). ' +
|
|
112
|
+
'cmd as a string runs through `sh -c`; as an array it is exec\'d directly. Default working directory: /workspace.',
|
|
113
|
+
inputSchema: {
|
|
114
|
+
type: 'object',
|
|
115
|
+
properties: {
|
|
116
|
+
id: { type: 'string', description: 'Sandbox id or name' },
|
|
117
|
+
cmd: { anyOf: [{ type: 'string', minLength: 1 }, { type: 'array', items: { type: 'string' }, minItems: 1 }] },
|
|
118
|
+
cwd: { type: 'string', description: 'Absolute path inside the sandbox' },
|
|
119
|
+
env,
|
|
120
|
+
timeoutMs: { type: 'integer', minimum: 1000, maximum: 900000 },
|
|
121
|
+
},
|
|
122
|
+
required: ['id', 'cmd'],
|
|
123
|
+
additionalProperties: false,
|
|
124
|
+
},
|
|
125
|
+
handler: async (args, apiOptions) => {
|
|
126
|
+
const id = await resolveSandboxId(idOf(args), apiOptions);
|
|
127
|
+
const stdout = new BoundedText(MCP_SANDBOX_OUTPUT_BYTES);
|
|
128
|
+
const stderr = new BoundedText(MCP_SANDBOX_OUTPUT_BYTES);
|
|
129
|
+
const result = await execInSandbox(id, {
|
|
130
|
+
cmd: args.cmd,
|
|
131
|
+
...(typeof args.cwd === 'string' ? { cwd: args.cwd } : {}),
|
|
132
|
+
...(args.env && typeof args.env === 'object' ? { env: args.env } : {}),
|
|
133
|
+
...(typeof args.timeoutMs === 'number' ? { timeoutMs: args.timeoutMs } : {}),
|
|
134
|
+
}, apiOptions, { onStdout: (text) => stdout.push(text), onStderr: (text) => stderr.push(text) });
|
|
135
|
+
return {
|
|
136
|
+
exitCode: result.exitCode,
|
|
137
|
+
stdout: stdout.text(),
|
|
138
|
+
stderr: stderr.text(),
|
|
139
|
+
truncated: result.truncated || stdout.truncated || stderr.truncated,
|
|
140
|
+
timedOut: result.timedOut,
|
|
141
|
+
execId: result.execId,
|
|
142
|
+
...(result.errorCode ? { errorCode: result.errorCode, error: result.errorMessage } : {}),
|
|
143
|
+
};
|
|
144
|
+
},
|
|
145
|
+
},
|
|
146
|
+
{
|
|
147
|
+
name: 'sandbox_write_file',
|
|
148
|
+
description: 'Write a file inside a sandbox (parent directories are created). content is UTF-8 text, or base64 with encoding "base64".',
|
|
149
|
+
inputSchema: {
|
|
150
|
+
type: 'object',
|
|
151
|
+
properties: {
|
|
152
|
+
id: { type: 'string' },
|
|
153
|
+
path: { type: 'string', description: 'Absolute path, e.g. /workspace/index.js' },
|
|
154
|
+
content: { type: 'string' },
|
|
155
|
+
encoding: { type: 'string', enum: ['utf8', 'base64'] },
|
|
156
|
+
},
|
|
157
|
+
required: ['id', 'path', 'content'],
|
|
158
|
+
additionalProperties: false,
|
|
159
|
+
},
|
|
160
|
+
handler: async (args, apiOptions) => {
|
|
161
|
+
const id = await resolveSandboxId(idOf(args), apiOptions);
|
|
162
|
+
if (typeof args.path !== 'string' || typeof args.content !== 'string')
|
|
163
|
+
throw new Error('path and content are required');
|
|
164
|
+
const data = args.encoding === 'base64' ? Buffer.from(args.content, 'base64') : Buffer.from(args.content, 'utf8');
|
|
165
|
+
const result = await writeSandboxFile(id, args.path, data, apiOptions);
|
|
166
|
+
return { bytes: result.bytes };
|
|
167
|
+
},
|
|
168
|
+
},
|
|
169
|
+
{
|
|
170
|
+
name: 'sandbox_read_file',
|
|
171
|
+
description: 'Read a file from a sandbox: UTF-8 text, or base64 for binary content; at most maxBytes (default 64 KiB) are returned.',
|
|
172
|
+
inputSchema: {
|
|
173
|
+
type: 'object',
|
|
174
|
+
properties: {
|
|
175
|
+
id: { type: 'string' },
|
|
176
|
+
path: { type: 'string' },
|
|
177
|
+
maxBytes: { type: 'integer', minimum: 1, maximum: MCP_SANDBOX_READ_BYTES },
|
|
178
|
+
},
|
|
179
|
+
required: ['id', 'path'],
|
|
180
|
+
additionalProperties: false,
|
|
181
|
+
},
|
|
182
|
+
handler: async (args, apiOptions) => {
|
|
183
|
+
const id = await resolveSandboxId(idOf(args), apiOptions);
|
|
184
|
+
if (typeof args.path !== 'string')
|
|
185
|
+
throw new Error('path is required');
|
|
186
|
+
const limit = typeof args.maxBytes === 'number' ? Math.min(args.maxBytes, MCP_SANDBOX_READ_BYTES) : MCP_SANDBOX_READ_BYTES;
|
|
187
|
+
const data = await readSandboxFile(id, args.path, apiOptions);
|
|
188
|
+
return { ...utf8OrBase64(data.subarray(0, limit)), bytes: data.length, truncated: data.length > limit };
|
|
189
|
+
},
|
|
190
|
+
},
|
|
191
|
+
{
|
|
192
|
+
name: 'sandbox_list',
|
|
193
|
+
description: 'List your live sandboxes (id, name, status, size, network, expiry).',
|
|
194
|
+
inputSchema: { type: 'object', properties: {}, additionalProperties: false },
|
|
195
|
+
handler: async (_args, apiOptions) => (await listSandboxes(apiOptions)).map((sandbox) => ({
|
|
196
|
+
id: sandbox.id, name: sandbox.name, status: sandbox.status, resources: sandbox.resources,
|
|
197
|
+
network: sandbox.network, expiresAt: sandbox.expiresAt, idleExpiresAt: sandbox.idleExpiresAt,
|
|
198
|
+
})),
|
|
199
|
+
},
|
|
200
|
+
{
|
|
201
|
+
name: 'sandbox_destroy',
|
|
202
|
+
description: 'Destroy a sandbox and everything in it. Idempotent.',
|
|
203
|
+
inputSchema: { type: 'object', properties: { id: { type: 'string' } }, required: ['id'], additionalProperties: false },
|
|
204
|
+
handler: async (args, apiOptions) => {
|
|
205
|
+
const sandbox = await destroySandbox(await resolveSandboxId(idOf(args), apiOptions), apiOptions);
|
|
206
|
+
return { id: sandbox.id, status: sandbox.status };
|
|
207
|
+
},
|
|
208
|
+
},
|
|
209
|
+
];
|
|
210
|
+
export const SANDBOX_TOOLS = TOOLS.map(withPlanHint);
|
|
211
|
+
//# sourceMappingURL=mcp-sandbox-tools.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mcp-sandbox-tools.js","sourceRoot":"","sources":["../../src/lib/mcp-sandbox-tools.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,OAAO,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAC;AACzD,OAAO,EACL,aAAa,EACb,cAAc,EACd,aAAa,EACb,aAAa,EACb,eAAe,EACf,gBAAgB,EAChB,gBAAgB,GAEjB,MAAM,kBAAkB,CAAC;AAE1B,gDAAgD;AAChD,MAAM,CAAC,MAAM,wBAAwB,GAAG,EAAE,GAAG,IAAI,CAAC;AAClD,MAAM,sBAAsB,GAAG,EAAE,GAAG,IAAI,CAAC;AASzC,MAAM,QAAQ,GAAG,EAAE,KAAK,EAAE,CAAC,EAAE,IAAI,EAAE,QAAQ,EAAE,OAAO,EAAE,2CAA2C,EAAE,EAAE,EAAE,IAAI,EAAE,SAAS,EAAE,OAAO,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC;AACxI,MAAM,GAAG,GAAG,EAAE,IAAI,EAAE,QAAQ,EAAE,oBAAoB,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,EAAE,WAAW,EAAE,wDAAwD,EAAE,CAAC;AAEhJ,yCAAyC;AACzC,MAAM,CAAC,MAAM,wBAAwB,GAA4B;IAC/D,IAAI,EAAE,QAAQ;IACd,UAAU,EAAE;QACV,IAAI,EAAE,EAAE,IAAI,EAAE,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ATEFUL_REPLICAS.md §3.5, §3.8, §7.2): the `role` column of
|
|
4
|
+
* `inquir apps replicas <app>` and the endpoints block under its table. The
|
|
5
|
+
* same fields `GET /v1/apps/:id/replicas` returns and `inquir mcp`'s replica
|
|
6
|
+
* tool passes through as they are; nothing here is a CLI-only notion.
|
|
7
|
+
*/
|
|
8
|
+
import type { AppReplicaCondition, AppReplicaRoleFields, AppReplicaRoles } from '@inquir/compute';
|
|
9
|
+
/** The `role` cell of one ordinal: its role, `(stale)` when it stopped being reported, `-` without one. */
|
|
10
|
+
export declare function replicaRoleCell(ordinal: AppReplicaRoleFields): string;
|
|
11
|
+
/**
|
|
12
|
+
* The endpoints block: one row per declared endpoint with its hostname and
|
|
13
|
+
* state, the public one marked. Empty without endpoints.
|
|
14
|
+
*/
|
|
15
|
+
export declare function formatRoleEndpoints(replicas: AppReplicaRoles & {
|
|
16
|
+
scale?: {
|
|
17
|
+
public?: string;
|
|
18
|
+
};
|
|
19
|
+
}): string[];
|
|
20
|
+
/** One warning line per application-level condition worth acting on (RoleConflict). */
|
|
21
|
+
export declare function roleConditionWarnings(conditions: readonly AppReplicaCondition[] | undefined): string[];
|
|
22
|
+
//# sourceMappingURL=replica-roles.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"replica-roles.d.ts","sourceRoot":"","sources":["../../src/lib/replica-roles.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,OAAO,KAAK,EAAE,mBAAmB,EAAE,oBAAoB,EAAE,eAAe,EAAmB,MAAM,iBAAiB,CAAC;AAGnH,2GAA2G;AAC3G,wBAAgB,eAAe,CAAC,OAAO,EAAE,oBAAoB,GAAG,MAAM,CAGrE;AASD;;;GAGG;AACH,wBAAgB,mBAAmB,CAAC,QAAQ,EAAE,eAAe,GAAG;IAAE,KAAK,CAAC,EAAE;QAAE,MAAM,CAAC,EAAE,MAAM,CAAA;KAAE,CAAA;CAAE,GAAG,MAAM,EAAE,CAWzG;AAED,uFAAuF;AACvF,wBAAgB,qBAAqB,CAAC,UAAU,EAAE,SAAS,mBAAmB,EAAE,GAAG,SAAS,GAAG,MAAM,EAAE,CAItG"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { dim, formatTable, green, red, yellow } from '../utils/output.js';
|
|
2
|
+
/** The `role` cell of one ordinal: its role, `(stale)` when it stopped being reported, `-` without one. */
|
|
3
|
+
export function replicaRoleCell(ordinal) {
|
|
4
|
+
if (!ordinal.role)
|
|
5
|
+
return '-';
|
|
6
|
+
return ordinal.roleStale ? `${ordinal.role} (stale)` : ordinal.role;
|
|
7
|
+
}
|
|
8
|
+
function endpointStatus(endpoint) {
|
|
9
|
+
if (endpoint.status === 'conflict')
|
|
10
|
+
return red(`conflict: ${(endpoint.conflict ?? []).join(', ')} claim it`);
|
|
11
|
+
if (endpoint.status === 'empty')
|
|
12
|
+
return yellow('no replica');
|
|
13
|
+
const members = endpoint.members.map((member) => member.ordinal).join(', ');
|
|
14
|
+
return green(endpoint.viaFallback ? `serving ${members} (via ${endpoint.viaFallback})` : `serving ${members}`);
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* The endpoints block: one row per declared endpoint with its hostname and
|
|
18
|
+
* state, the public one marked. Empty without endpoints.
|
|
19
|
+
*/
|
|
20
|
+
export function formatRoleEndpoints(replicas) {
|
|
21
|
+
const endpoints = replicas.endpoints ?? [];
|
|
22
|
+
if (endpoints.length === 0)
|
|
23
|
+
return [];
|
|
24
|
+
const publicEndpoint = replicas.scale?.public && replicas.scale.public !== 'default' ? replicas.scale.public : null;
|
|
25
|
+
const lines = ['', 'Endpoints', formatTable(endpoints.map((endpoint) => ({
|
|
26
|
+
endpoint: endpoint.name === publicEndpoint ? `${endpoint.name} (public)` : endpoint.name,
|
|
27
|
+
hostname: endpoint.hostname,
|
|
28
|
+
status: endpointStatus(endpoint),
|
|
29
|
+
published: endpoint.published ? 'yes' : dim('no (report)'),
|
|
30
|
+
})), ['endpoint', 'hostname', 'status', 'published'])];
|
|
31
|
+
return lines;
|
|
32
|
+
}
|
|
33
|
+
/** One warning line per application-level condition worth acting on (RoleConflict). */
|
|
34
|
+
export function roleConditionWarnings(conditions) {
|
|
35
|
+
return (conditions ?? [])
|
|
36
|
+
.filter((condition) => condition.status === 'True' && condition.type === 'RoleConflict')
|
|
37
|
+
.map((condition) => `${condition.type}: ${condition.message}`);
|
|
38
|
+
}
|
|
39
|
+
//# sourceMappingURL=replica-roles.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"replica-roles.js","sourceRoot":"","sources":["../../src/lib/replica-roles.ts"],"names":[],"mappings":"AAQA,OAAO,EAAE,GAAG,EAAE,WAAW,EAAE,KAAK,EAAE,GAAG,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAE1E,2GAA2G;AAC3G,MAAM,UAAU,eAAe,CAAC,OAA6B;IAC3D,IAAI,CAAC,OAAO,CAAC,IAAI;QAAE,OAAO,GAAG,CAAC;IAC9B,OAAO,OAAO,CAAC,SAAS,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,IAAI,UAAU,CAAC,CAAC,CAAC,OAAO,CAAC,IAAI,CAAC;AACtE,CAAC;AAED,SAAS,cAAc,CAAC,QAAyB;IAC/C,IAAI,QAAQ,CAAC,MAAM,KAAK,UAAU;QAAE,OAAO,GAAG,CAAC,aAAa,CAAC,QAAQ,CAAC,QAAQ,IAAI,EAAE,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;IAC7G,IAAI,QAAQ,CAAC,MAAM,KAAK,OAAO;QAAE,OAAO,MAAM,CAAC,YAAY,CAAC,CAAC;IAC7D,MAAM,OAAO,GAAG,QAAQ,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAC5E,OAAO,KAAK,CAAC,QAAQ,CAAC,WAAW,CA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,KAAK,MAAM,IAAI,SAAS,CAAC,IAAI,KAAK,cAAc,CAAC;SACvF,GAAG,CAAC,CAAC,SAAS,EAAE,EAAE,CAAC,GAAG,SAAS,CAAC,IAAI,KAAK,SAAS,CAAC,OAAO,EAAE,CAAC,CAAC;AACnE,CAAC"}
|
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The CLI and MCP client of /v1/sandboxes (docs/roadmap/SANDBOXES.md §5).
|
|
3
|
+
* Built on the SDK transport (auth headers, error mapping) without adding a
|
|
4
|
+
* `client.sandboxes` surface to the published SDK: that is P2, and this CLI
|
|
5
|
+
* must keep working against the SDK version it depends on.
|
|
6
|
+
*/
|
|
7
|
+
import { type ApiRequestOptions } from '../utils/api.js';
|
|
8
|
+
/** SandboxSpec (§5.1): the same object on every surface. */
|
|
9
|
+
export interface SandboxSpecInput {
|
|
10
|
+
name?: string;
|
|
11
|
+
image?: string;
|
|
12
|
+
region?: 'auto' | 'ru' | 'nl';
|
|
13
|
+
resources?: {
|
|
14
|
+
vcpu?: number;
|
|
15
|
+
memoryMb?: number;
|
|
16
|
+
diskGb?: number;
|
|
17
|
+
};
|
|
18
|
+
network?: {
|
|
19
|
+
mode?: 'none' | 'proxy' | 'open';
|
|
20
|
+
allow?: string[];
|
|
21
|
+
};
|
|
22
|
+
env?: Record<string, string>;
|
|
23
|
+
lifetime?: {
|
|
24
|
+
idle?: string | number;
|
|
25
|
+
max?: string | number;
|
|
26
|
+
};
|
|
27
|
+
project?: string;
|
|
28
|
+
}
|
|
29
|
+
export interface Sandbox {
|
|
30
|
+
id: string;
|
|
31
|
+
name: string | null;
|
|
32
|
+
status: 'PENDING' | 'STARTING' | 'RUNNING' | 'STOPPING' | 'DESTROYED' | 'FAILED';
|
|
33
|
+
image: string;
|
|
34
|
+
region: string;
|
|
35
|
+
resources: {
|
|
36
|
+
vcpu: number;
|
|
37
|
+
memoryMb: number;
|
|
38
|
+
diskGb: number;
|
|
39
|
+
};
|
|
40
|
+
network: {
|
|
41
|
+
mode: string;
|
|
42
|
+
allow: string[];
|
|
43
|
+
};
|
|
44
|
+
envKeys: string[];
|
|
45
|
+
lifetime: {
|
|
46
|
+
idleSeconds: number;
|
|
47
|
+
maxSeconds: number;
|
|
48
|
+
};
|
|
49
|
+
createdAt: string;
|
|
50
|
+
startedAt: string | null;
|
|
51
|
+
idleExpiresAt: string;
|
|
52
|
+
expiresAt: string;
|
|
53
|
+
endedAt: string | null;
|
|
54
|
+
endReason: string | null;
|
|
55
|
+
failureCode: string | null;
|
|
56
|
+
execCount: number;
|
|
57
|
+
}
|
|
58
|
+
export interface SandboxExecInput {
|
|
59
|
+
cmd: string | string[];
|
|
60
|
+
cwd?: string;
|
|
61
|
+
env?: Record<string, string>;
|
|
62
|
+
timeoutMs?: number;
|
|
63
|
+
stdin?: string;
|
|
64
|
+
}
|
|
65
|
+
export interface SandboxExecResult {
|
|
66
|
+
execId: string | null;
|
|
67
|
+
exitCode: number | null;
|
|
68
|
+
timedOut: boolean;
|
|
69
|
+
truncated: boolean;
|
|
70
|
+
durationMs: number;
|
|
71
|
+
/** Set when the exec ended without an exit status. */
|
|
72
|
+
errorCode?: string;
|
|
73
|
+
errorMessage?: string;
|
|
74
|
+
}
|
|
75
|
+
export declare function createSandbox(spec: SandboxSpecInput, options: ApiRequestOptions, settings?: {
|
|
76
|
+
wait?: boolean;
|
|
77
|
+
idempotencyKey?: string;
|
|
78
|
+
}): Promise<Sandbox>;
|
|
79
|
+
export declare function listSandboxes(options: ApiRequestOptions, filter?: {
|
|
80
|
+
all?: boolean;
|
|
81
|
+
}): Promise<Sandbox[]>;
|
|
82
|
+
export declare function getSandbox(id: string, options: ApiRequestOptions): Promise<Sandbox>;
|
|
83
|
+
export declare function destroySandbox(id: string, options: ApiRequestOptions): Promise<Sandbox>;
|
|
84
|
+
/** An id (`sbx_…`) as is; otherwise the live sandbox with that name. */
|
|
85
|
+
export declare function resolveSandboxId(reference: string, options: ApiRequestOptions): Promise<string>;
|
|
86
|
+
/**
|
|
87
|
+
* Run one exec and stream its NDJSON frames: `start`, `stdout`/`stderr`
|
|
88
|
+
* (`data`, UTF-8), then `exit` or `error`. Aborting the signal closes the
|
|
89
|
+
* stream, which cancels the exec on the server.
|
|
90
|
+
*/
|
|
91
|
+
export declare function execInSandbox(id: string, input: SandboxExecInput, options: ApiRequestOptions, handlers?: {
|
|
92
|
+
onStdout?: (text: string) => void;
|
|
93
|
+
onStderr?: (text: string) => void;
|
|
94
|
+
signal?: AbortSignal;
|
|
95
|
+
}): Promise<SandboxExecResult>;
|
|
96
|
+
export declare function writeSandboxFile(id: string, path: string, data: Uint8Array, options: ApiRequestOptions, format?: 'file' | 'tar'): Promise<{
|
|
97
|
+
path: string;
|
|
98
|
+
bytes: number;
|
|
99
|
+
}>;
|
|
100
|
+
export declare function readSandboxFile(id: string, path: string, options: ApiRequestOptions, format?: 'file' | 'tar'): Promise<Buffer>;
|
|
101
|
+
/** `90s`, `15m`, `1h`, `1h30m` → the same string after validation (the API parses it). */
|
|
102
|
+
export declare function parseDurationFlag(value: string, flag: string): string;
|
|
103
|
+
/** `512m`, `1g`, `1.5g`, `1024` (MiB) → MiB. */
|
|
104
|
+
export declare function parseSizeMb(value: string, flag: string): number;
|
|
105
|
+
/** S/M/L presets of the dashboard form and `--size` (§6.1, §6.2). */
|
|
106
|
+
export declare const SANDBOX_SIZES: Record<'s' | 'm' | 'l', {
|
|
107
|
+
vcpu: number;
|
|
108
|
+
memoryMb: number;
|
|
109
|
+
diskGb: number;
|
|
110
|
+
}>;
|
|
111
|
+
/** A one-use shell ticket (POST /v1/sandboxes/:id/shell-ticket): the WebSocket offers `protocol` as its subprotocol. */
|
|
112
|
+
export interface SandboxShellTicket {
|
|
113
|
+
ticket: string;
|
|
114
|
+
protocol: string;
|
|
115
|
+
expiresAt: string;
|
|
116
|
+
}
|
|
117
|
+
export declare function issueShellTicket(id: string, size: {
|
|
118
|
+
cols: number;
|
|
119
|
+
rows: number;
|
|
120
|
+
}, options: ApiRequestOptions): Promise<SandboxShellTicket>;
|
|
121
|
+
/** Frames the shell WebSocket sends (sandboxes.routes.ts). */
|
|
122
|
+
export type SandboxShellServerFrame = {
|
|
123
|
+
type: 'ready';
|
|
124
|
+
sandboxId: string;
|
|
125
|
+
shellId: string;
|
|
126
|
+
shell: string;
|
|
127
|
+
} | {
|
|
128
|
+
type: 'output';
|
|
129
|
+
dataBase64: string;
|
|
130
|
+
} | {
|
|
131
|
+
type: 'exit';
|
|
132
|
+
exitCode: number | null;
|
|
133
|
+
} | {
|
|
134
|
+
type: 'error';
|
|
135
|
+
error: {
|
|
136
|
+
code: string;
|
|
137
|
+
message: string;
|
|
138
|
+
};
|
|
139
|
+
};
|
|
140
|
+
/** The parts of a WebSocket the shell client uses (Node's global WebSocket; injectable for tests). */
|
|
141
|
+
export interface ShellSocket {
|
|
142
|
+
readonly readyState: number;
|
|
143
|
+
send(data: string): void;
|
|
144
|
+
close(code?: number, reason?: string): void;
|
|
145
|
+
addEventListener(type: 'open' | 'message' | 'close' | 'error', listener: (event: {
|
|
146
|
+
data?: unknown;
|
|
147
|
+
code?: number;
|
|
148
|
+
}) => void): void;
|
|
149
|
+
}
|
|
150
|
+
export type ShellSocketFactory = (url: string, init: {
|
|
151
|
+
protocols: string[];
|
|
152
|
+
headers: Record<string, string>;
|
|
153
|
+
}) => ShellSocket;
|
|
154
|
+
/**
|
|
155
|
+
* Open the shell WebSocket of a sandbox with a fresh ticket: the ticket rides
|
|
156
|
+
* in the negotiated subprotocol (never in the URL) and the credential in the
|
|
157
|
+
* same headers every API call carries.
|
|
158
|
+
*/
|
|
159
|
+
export declare function openShellSocket(id: string, size: {
|
|
160
|
+
cols: number;
|
|
161
|
+
rows: number;
|
|
162
|
+
}, options: ApiRequestOptions, factory?: ShellSocketFactory): Promise<ShellSocket>;
|
|
163
|
+
/** Parse one server frame; null for anything else. */
|
|
164
|
+
export declare function parseShellFrame(data: unknown): SandboxShellServerFrame | null;
|
|
165
|
+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