@computesdk/workbench 23.0.0 → 24.0.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/README.md +11 -88
- package/dist/bin/workbench.js +56 -713
- package/dist/bin/workbench.js.map +1 -1
- package/dist/helpers.d.ts +0 -4
- package/dist/helpers.js +2 -2
- package/dist/helpers.js.map +1 -1
- package/dist/index.js +56 -713
- package/dist/index.js.map +1 -1
- package/package.json +23 -24
package/dist/bin/workbench.js
CHANGED
|
@@ -39,8 +39,6 @@ function createState() {
|
|
|
39
39
|
currentSandbox: null,
|
|
40
40
|
sandboxCreatedAt: null,
|
|
41
41
|
availableProviders: [],
|
|
42
|
-
useDirectMode: false,
|
|
43
|
-
// Default to gateway mode
|
|
44
42
|
verbose: false,
|
|
45
43
|
// Enabled automatically for local provider
|
|
46
44
|
compute: null
|
|
@@ -119,29 +117,16 @@ __export(output_exports, {
|
|
|
119
117
|
showInfo: () => showInfo,
|
|
120
118
|
showWelcome: () => showWelcome
|
|
121
119
|
});
|
|
122
|
-
function showWelcome(availableProviders, currentProvider
|
|
120
|
+
function showWelcome(availableProviders, currentProvider) {
|
|
123
121
|
console.log(c.bold(c.cyan("\n\u2554\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2557")));
|
|
124
122
|
console.log(c.bold(c.cyan("\u2551 ComputeSDK Workbench \u2551")));
|
|
125
123
|
console.log(c.bold(c.cyan("\u255A\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u255D\n")));
|
|
126
124
|
console.log(c.dim("Prompt shows connection status: > (disconnected) or provider:sandbox> (connected)\n"));
|
|
127
|
-
if (localDaemonRunning) {
|
|
128
|
-
console.log(c.green("Local daemon detected - auto-connecting...\n"));
|
|
129
|
-
}
|
|
130
125
|
if (availableProviders.length > 0) {
|
|
131
|
-
|
|
132
|
-
console.log(`Providers available: ${backendProviders.join(", ")}`);
|
|
126
|
+
console.log(`Providers available: ${availableProviders.join(", ")}`);
|
|
133
127
|
if (currentProvider) {
|
|
134
|
-
|
|
135
|
-
console.log(`Current provider: ${c.green("local")} (local daemon)
|
|
136
|
-
`);
|
|
137
|
-
} else if (useDirectMode) {
|
|
138
|
-
console.log(`Current provider: ${c.green(currentProvider)} (direct mode)
|
|
128
|
+
console.log(`Current provider: ${c.green(currentProvider)}
|
|
139
129
|
`);
|
|
140
|
-
} else {
|
|
141
|
-
const backendProvider = currentProvider === "gateway" ? backendProviders[0] || "auto" : currentProvider;
|
|
142
|
-
console.log(`Current provider: ${c.green(backendProvider)} (via gateway)
|
|
143
|
-
`);
|
|
144
|
-
}
|
|
145
130
|
} else {
|
|
146
131
|
console.log(`
|
|
147
132
|
${c.dim('Tip: Use "provider <name>" to select a provider')}
|
|
@@ -167,8 +152,6 @@ function showInfo(state) {
|
|
|
167
152
|
console.log(` Sandbox ID: ${c.cyan(state.currentSandbox.sandboxId)}`);
|
|
168
153
|
}
|
|
169
154
|
console.log(` Provider: ${c.green(state.currentProvider || "unknown")}`);
|
|
170
|
-
const modeLabel = state.useDirectMode ? "direct \u{1F517}" : "gateway \u{1F310}";
|
|
171
|
-
console.log(` Mode: ${c.blue(modeLabel)}`);
|
|
172
155
|
console.log(` Created: ${state.sandboxCreatedAt?.toLocaleString() || "unknown"}`);
|
|
173
156
|
console.log(` Uptime: ${formatUptime(state)}`);
|
|
174
157
|
console.log("");
|
|
@@ -192,33 +175,14 @@ function showHelp() {
|
|
|
192
175
|
${c.bold("ComputeSDK Workbench Commands")}
|
|
193
176
|
|
|
194
177
|
${c.bold("Provider Management:")}
|
|
195
|
-
${c.cyan("provider <name>")} Switch to provider
|
|
178
|
+
${c.cyan("provider <name>")} Switch to provider
|
|
196
179
|
${c.dim("Example: provider e2b")}
|
|
197
|
-
${c.cyan("provider direct <name>")} Connect directly to provider
|
|
198
|
-
${c.dim("Example: provider direct e2b")}
|
|
199
180
|
${c.cyan("providers")} List all providers with status
|
|
200
|
-
${c.cyan("mode <gateway|direct>")} Toggle default mode for next sandbox
|
|
201
|
-
|
|
202
|
-
${c.bold("Provider Modes:")}
|
|
203
|
-
${c.bold("Gateway (default)")}: Routes through ComputeSDK API, zero-config
|
|
204
|
-
\u2022 Requires: COMPUTESDK_API_KEY + provider credentials
|
|
205
|
-
\u2022 Usage: ${c.cyan("provider e2b")}
|
|
206
|
-
|
|
207
|
-
${c.bold("Direct")}: Connects directly to provider, requires packages
|
|
208
|
-
\u2022 Requires: Provider package installed + credentials
|
|
209
|
-
\u2022 Usage: ${c.cyan("provider direct e2b")}
|
|
210
181
|
|
|
211
182
|
${c.bold("Sandbox Management:")}
|
|
212
183
|
${c.cyan("restart")} Restart current sandbox
|
|
213
184
|
${c.cyan("destroy")} Destroy current sandbox
|
|
214
185
|
${c.cyan("info")} Show sandbox info (provider, uptime)
|
|
215
|
-
${c.cyan("connect <url> [token]")} Connect to sandbox via URL
|
|
216
|
-
|
|
217
|
-
${c.bold("Local Daemon:")}
|
|
218
|
-
${c.cyan("provider local")} Connect to local daemon's main sandbox
|
|
219
|
-
${c.cyan("provider local list")} List local sandboxes
|
|
220
|
-
${c.cyan("provider local <subdomain>")} Connect to specific local sandbox
|
|
221
|
-
${c.dim("Example: provider local separate-snail-qkktux")}
|
|
222
186
|
|
|
223
187
|
${c.bold("Environment:")}
|
|
224
188
|
${c.cyan("env")} Show environment/credentials status
|
|
@@ -253,53 +217,14 @@ ${c.bold("Running Commands:")}
|
|
|
253
217
|
${c.cyan('filesystem.exists("/path")')}
|
|
254
218
|
${c.cyan('filesystem.remove("/file")')}
|
|
255
219
|
|
|
256
|
-
${c.dim("Named Sandboxes (gateway mode only):")}
|
|
257
|
-
${c.cyan("create()")} ${c.dim("// Create & switch to new sandbox")}
|
|
258
|
-
${c.cyan('create({ namespace: "h" })')} ${c.dim("// Create with namespace & switch")}
|
|
259
|
-
${c.cyan('findOrCreate({ name: "my-app" })')} ${c.dim("// Find or create & switch")}
|
|
260
|
-
${c.cyan('find({ name: "my-app" })')} ${c.dim("// Find existing & switch")}
|
|
261
|
-
|
|
262
|
-
${c.dim("Note: Prompts before switching if you already have an active sandbox")}
|
|
263
|
-
|
|
264
|
-
${c.dim("Child Sandboxes (gateway mode only):")}
|
|
265
|
-
${c.cyan("child.create()")} ${c.dim("// Create child sandbox")}
|
|
266
|
-
${c.cyan("child.list()")} ${c.dim("// List all children")}
|
|
267
|
-
${c.cyan('child.retrieve("sandbox-id")')} ${c.dim("// Get child info")}
|
|
268
|
-
${c.cyan('child.destroy("sandbox-id")')} ${c.dim("// Delete child")}
|
|
269
|
-
|
|
270
220
|
${c.dim("Sandbox Methods:")}
|
|
271
221
|
${c.cyan("getUrl({ port: 3000 })")} ${c.dim("// Get public URL")}
|
|
272
|
-
${c.cyan(
|
|
222
|
+
${c.cyan('runCommand("echo hi")')} ${c.dim("// Execute command")}
|
|
273
223
|
${c.cyan("sandboxInfo()")} ${c.dim("// Get sandbox details")}
|
|
274
224
|
${c.cyan("ready()")} ${c.dim("// Get readiness status")}
|
|
275
225
|
${c.cyan("getInstance()")} ${c.dim("// Get native instance")}
|
|
276
|
-
|
|
277
|
-
${c.dim("Terminal (PTY & Exec):")}
|
|
278
|
-
${c.cyan("terminal.create({ pty: true })")} ${c.dim("// Create PTY terminal")}
|
|
279
|
-
${c.cyan("terminal.create({ pty: false })")} ${c.dim("// Create exec terminal")}
|
|
280
|
-
${c.cyan("terminal.list()")} ${c.dim("// List all terminals")}
|
|
281
|
-
${c.cyan("terminal.retrieve(id)")} ${c.dim("// Get terminal by ID")}
|
|
282
|
-
${c.cyan("terminal.destroy(id)")} ${c.dim("// Close terminal by ID")}
|
|
283
|
-
|
|
284
|
-
${c.dim("PTY Terminal:")}
|
|
285
|
-
${c.cyan("term = terminal.create({ pty: true })")}
|
|
286
|
-
${c.cyan('term.on("output", (data) => console.log(data))')}
|
|
287
|
-
${c.cyan('term.write("echo hello\\n")')}
|
|
288
|
-
${c.cyan("term.destroy()")}
|
|
289
|
-
|
|
290
|
-
${c.dim("Exec Terminal:")}
|
|
291
|
-
${c.cyan("exec = terminal.create({ pty: false })")}
|
|
292
|
-
${c.cyan('cmd = exec.command.run("ls -la")')}
|
|
293
|
-
${c.cyan("cmd.stdout")} ${c.dim("// view output")}
|
|
294
|
-
|
|
226
|
+
|
|
295
227
|
${c.dim('Note: No need to use "await" - promises are auto-awaited!')}
|
|
296
|
-
|
|
297
|
-
${c.dim("Compute CLI:")}
|
|
298
|
-
${c.cyan("compute.isSetup()")} ${c.dim("// Check if daemon is running")}
|
|
299
|
-
${c.cyan("compute.setup()")} ${c.dim("// Install + start daemon")}
|
|
300
|
-
${c.cyan("compute.install()")} ${c.dim("// Install compute CLI")}
|
|
301
|
-
${c.cyan("compute.start()")} ${c.dim("// Start daemon")}
|
|
302
|
-
${c.cyan("compute.health()")} ${c.dim("// Check daemon health")}
|
|
303
228
|
|
|
304
229
|
${c.bold("Shell Commands:")}
|
|
305
230
|
Use ${c.cyan("$")} prefix to run any shell command directly:
|
|
@@ -494,14 +419,11 @@ function showEnv() {
|
|
|
494
419
|
console.log(c.dim("Tip: Set credentials in your .env file"));
|
|
495
420
|
console.log("");
|
|
496
421
|
}
|
|
497
|
-
function autoDetectProvider(
|
|
422
|
+
function autoDetectProvider() {
|
|
498
423
|
const explicit = process.env.COMPUTESDK_PROVIDER?.toLowerCase();
|
|
499
424
|
if (explicit && isValidProvider(explicit) && isProviderReady(explicit)) {
|
|
500
425
|
return explicit;
|
|
501
426
|
}
|
|
502
|
-
if (forceGatewayMode) {
|
|
503
|
-
return isProviderReady("gateway") ? "gateway" : null;
|
|
504
|
-
}
|
|
505
427
|
for (const provider of PROVIDER_NAMES) {
|
|
506
428
|
if (isProviderReady(provider)) {
|
|
507
429
|
return provider;
|
|
@@ -538,8 +460,6 @@ Available: ${PROVIDER_NAMES.join(", ")}`;
|
|
|
538
460
|
async function loadProvider(providerName) {
|
|
539
461
|
try {
|
|
540
462
|
switch (providerName) {
|
|
541
|
-
case "gateway":
|
|
542
|
-
return await import("computesdk");
|
|
543
463
|
case "e2b":
|
|
544
464
|
return await import("@computesdk/e2b");
|
|
545
465
|
case "railway":
|
|
@@ -582,20 +502,12 @@ async function loadProvider(providerName) {
|
|
|
582
502
|
throw new Error(`Unknown provider: ${providerName}`);
|
|
583
503
|
}
|
|
584
504
|
} catch (error) {
|
|
585
|
-
if (providerName === "gateway") {
|
|
586
|
-
throw new Error(`Failed to load gateway provider from computesdk package.`);
|
|
587
|
-
}
|
|
588
505
|
throw new Error(
|
|
589
506
|
`Failed to load provider ${providerName}. Make sure to install it: npm install @computesdk/${providerName}`
|
|
590
507
|
);
|
|
591
508
|
}
|
|
592
509
|
}
|
|
593
510
|
function getProviderConfig(providerName) {
|
|
594
|
-
if (providerName === "gateway") {
|
|
595
|
-
const config2 = {};
|
|
596
|
-
if (process.env.COMPUTESDK_API_KEY) config2.apiKey = process.env.COMPUTESDK_API_KEY;
|
|
597
|
-
return config2;
|
|
598
|
-
}
|
|
599
511
|
return getProviderConfigFromEnv(providerName);
|
|
600
512
|
}
|
|
601
513
|
var SHARED_PROVIDER_NAMES, SHARED_PROVIDER_AUTH, PROVIDER_ENV_MAP, PROVIDER_NAMES, PROVIDER_AUTH;
|
|
@@ -684,14 +596,8 @@ var init_providers = __esm({
|
|
|
684
596
|
"secure-exec": {},
|
|
685
597
|
upstash: { apiKey: "UPSTASH_BOX_API_KEY" }
|
|
686
598
|
};
|
|
687
|
-
PROVIDER_NAMES =
|
|
688
|
-
|
|
689
|
-
...SHARED_PROVIDER_NAMES
|
|
690
|
-
];
|
|
691
|
-
PROVIDER_AUTH = {
|
|
692
|
-
gateway: [["COMPUTESDK_API_KEY"]],
|
|
693
|
-
...SHARED_PROVIDER_AUTH
|
|
694
|
-
};
|
|
599
|
+
PROVIDER_NAMES = SHARED_PROVIDER_NAMES;
|
|
600
|
+
PROVIDER_AUTH = SHARED_PROVIDER_AUTH;
|
|
695
601
|
}
|
|
696
602
|
});
|
|
697
603
|
|
|
@@ -700,24 +606,17 @@ var commands_exports = {};
|
|
|
700
606
|
__export(commands_exports, {
|
|
701
607
|
cleanupOnExit: () => cleanupOnExit,
|
|
702
608
|
confirmSandboxSwitch: () => confirmSandboxSwitch,
|
|
703
|
-
connectToLocal: () => connectToLocal,
|
|
704
|
-
connectToSandbox: () => connectToSandbox,
|
|
705
609
|
createSandbox: () => createSandbox,
|
|
706
610
|
defineProviderCommand: () => defineProviderCommand,
|
|
707
611
|
destroySandbox: () => destroySandbox,
|
|
708
612
|
ensureSandbox: () => ensureSandbox,
|
|
709
613
|
getComputeInstance: () => getComputeInstance,
|
|
710
|
-
isLocalDaemonRunning: () => isLocalDaemonRunning,
|
|
711
|
-
listLocalSandboxes: () => listLocalSandboxes,
|
|
712
614
|
restartSandbox: () => restartSandbox,
|
|
713
615
|
runCommand: () => runCommand,
|
|
714
|
-
showMode: () => showMode,
|
|
715
616
|
showVerbose: () => showVerbose,
|
|
716
617
|
switchProvider: () => switchProvider,
|
|
717
|
-
toggleMode: () => toggleMode,
|
|
718
618
|
toggleVerbose: () => toggleVerbose
|
|
719
619
|
});
|
|
720
|
-
import { createCompute } from "@computesdk/provider";
|
|
721
620
|
import { escapeArgs } from "@computesdk/cmd";
|
|
722
621
|
async function confirm(question, defaultYes = false, _state) {
|
|
723
622
|
const promptSuffix = defaultYes ? "(Y/n)" : "(y/N)";
|
|
@@ -782,12 +681,10 @@ async function getComputeInstance(state) {
|
|
|
782
681
|
if (state.compute) {
|
|
783
682
|
return state.compute;
|
|
784
683
|
}
|
|
785
|
-
const providerName = state.currentProvider || autoDetectProvider(
|
|
786
|
-
const useDirect = state.useDirectMode;
|
|
684
|
+
const providerName = state.currentProvider || autoDetectProvider();
|
|
787
685
|
if (!providerName) {
|
|
788
686
|
throw new Error("No provider configured.");
|
|
789
687
|
}
|
|
790
|
-
let compute2;
|
|
791
688
|
const exportName = providerName.replace(/-([a-z])/g, (_, c2) => c2.toUpperCase());
|
|
792
689
|
const providerModule = await loadProvider(providerName);
|
|
793
690
|
const providerFactory = providerModule[exportName] ?? providerModule[providerName];
|
|
@@ -796,46 +693,25 @@ async function getComputeInstance(state) {
|
|
|
796
693
|
}
|
|
797
694
|
const config2 = getProviderConfig(providerName);
|
|
798
695
|
const providerInstance = providerFactory(config2);
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
} else {
|
|
804
|
-
const { compute: directCompute } = await import("computesdk");
|
|
805
|
-
compute2 = directCompute({
|
|
806
|
-
provider: providerInstance
|
|
807
|
-
});
|
|
808
|
-
}
|
|
696
|
+
const { compute: directCompute } = await import("computesdk");
|
|
697
|
+
const compute2 = directCompute({
|
|
698
|
+
provider: providerInstance
|
|
699
|
+
});
|
|
809
700
|
state.compute = compute2;
|
|
810
701
|
return compute2;
|
|
811
702
|
}
|
|
812
703
|
async function createSandbox(state) {
|
|
813
|
-
const providerName = state.currentProvider || autoDetectProvider(
|
|
814
|
-
const useDirect = state.useDirectMode;
|
|
704
|
+
const providerName = state.currentProvider || autoDetectProvider();
|
|
815
705
|
if (!providerName) {
|
|
816
706
|
logError('No provider configured. Run "env" to see setup instructions.');
|
|
817
707
|
throw new Error("No provider available");
|
|
818
708
|
}
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
actualProviderName = providerName;
|
|
824
|
-
if (!isProviderReady(providerName)) {
|
|
825
|
-
logError(`Provider ${providerName} is not fully configured for direct mode.`);
|
|
826
|
-
console.log(getProviderSetupHelp(providerName));
|
|
827
|
-
throw new Error("Provider not ready");
|
|
828
|
-
}
|
|
829
|
-
} else {
|
|
830
|
-
modeLabel = `${providerName} (via gateway)`;
|
|
831
|
-
actualProviderName = "gateway";
|
|
832
|
-
if (!isProviderReady("gateway")) {
|
|
833
|
-
logError("Gateway mode requires COMPUTESDK_API_KEY");
|
|
834
|
-
console.log(getProviderSetupHelp("gateway"));
|
|
835
|
-
throw new Error("Gateway not ready");
|
|
836
|
-
}
|
|
709
|
+
if (!isProviderReady(providerName)) {
|
|
710
|
+
logError(`Provider ${providerName} is not fully configured.`);
|
|
711
|
+
console.log(getProviderSetupHelp(providerName));
|
|
712
|
+
throw new Error("Provider not ready");
|
|
837
713
|
}
|
|
838
|
-
const spinner = new Spinner(`Creating sandbox with ${
|
|
714
|
+
const spinner = new Spinner(`Creating sandbox with ${providerName}...`).start();
|
|
839
715
|
const startTime = Date.now();
|
|
840
716
|
try {
|
|
841
717
|
const compute2 = await getComputeInstance(state);
|
|
@@ -935,122 +811,48 @@ function isStaleConnectionError(error) {
|
|
|
935
811
|
];
|
|
936
812
|
return stalePhrases.some((phrase) => message.includes(phrase));
|
|
937
813
|
}
|
|
938
|
-
async function switchProvider(state,
|
|
939
|
-
if (
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
return;
|
|
943
|
-
}
|
|
944
|
-
await connectToLocal(state, providerName);
|
|
814
|
+
async function switchProvider(state, name) {
|
|
815
|
+
if (!isValidProvider(name)) {
|
|
816
|
+
logError(`Unknown provider: ${name}`);
|
|
817
|
+
console.log(`Available providers: ${PROVIDER_NAMES.join(", ")}`);
|
|
945
818
|
return;
|
|
946
819
|
}
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
if (!providerName) {
|
|
951
|
-
logError("Usage: provider direct <name>");
|
|
952
|
-
console.log("Example: provider direct e2b");
|
|
953
|
-
return;
|
|
954
|
-
}
|
|
955
|
-
useDirect = true;
|
|
956
|
-
actualProvider = providerName;
|
|
957
|
-
} else if (mode === "gateway") {
|
|
958
|
-
if (!providerName) {
|
|
959
|
-
logError("Usage: provider gateway <name>");
|
|
960
|
-
console.log("Example: provider gateway e2b");
|
|
961
|
-
return;
|
|
962
|
-
}
|
|
963
|
-
useDirect = false;
|
|
964
|
-
actualProvider = providerName;
|
|
965
|
-
}
|
|
966
|
-
if (actualProvider === "gateway") {
|
|
967
|
-
actualProvider = autoDetectProvider(false) || "e2b";
|
|
968
|
-
}
|
|
969
|
-
if (!isValidProvider(actualProvider)) {
|
|
970
|
-
logError(`Unknown provider: ${actualProvider}`);
|
|
971
|
-
console.log(`Available providers: ${PROVIDER_NAMES.filter((p) => p !== "gateway").join(", ")}, local`);
|
|
972
|
-
return;
|
|
973
|
-
}
|
|
974
|
-
if (!useDirect && !isProviderReady("gateway")) {
|
|
975
|
-
logError("Gateway mode requires COMPUTESDK_API_KEY");
|
|
976
|
-
console.log(getProviderSetupHelp("gateway"));
|
|
977
|
-
return;
|
|
978
|
-
}
|
|
979
|
-
if (useDirect && !isProviderReady(actualProvider)) {
|
|
980
|
-
logError(`Provider ${actualProvider} is not fully configured for direct mode.`);
|
|
981
|
-
console.log(getProviderSetupHelp(actualProvider));
|
|
820
|
+
if (!isProviderReady(name)) {
|
|
821
|
+
logError(`Provider ${name} is not fully configured.`);
|
|
822
|
+
console.log(getProviderSetupHelp(name));
|
|
982
823
|
return;
|
|
983
824
|
}
|
|
984
825
|
if (hasSandbox(state)) {
|
|
985
826
|
const shouldDestroy = await confirm("Destroy current sandbox?", false, state);
|
|
986
827
|
if (shouldDestroy) {
|
|
987
828
|
await destroySandbox(state);
|
|
988
|
-
state.currentProvider =
|
|
989
|
-
state.useDirectMode = useDirect;
|
|
829
|
+
state.currentProvider = name;
|
|
990
830
|
state.compute = null;
|
|
991
|
-
|
|
992
|
-
logSuccess(`Switched to ${modeStr}`);
|
|
831
|
+
logSuccess(`Switched to ${name}`);
|
|
993
832
|
} else {
|
|
994
833
|
logWarning("Keeping current sandbox. Provider remains unchanged.");
|
|
995
834
|
}
|
|
996
835
|
} else {
|
|
997
|
-
state.currentProvider =
|
|
998
|
-
state.useDirectMode = useDirect;
|
|
836
|
+
state.currentProvider = name;
|
|
999
837
|
state.compute = null;
|
|
1000
|
-
|
|
1001
|
-
logSuccess(`Switched to ${modeStr}`);
|
|
838
|
+
logSuccess(`Switched to ${name}`);
|
|
1002
839
|
}
|
|
1003
840
|
}
|
|
1004
841
|
function defineProviderCommand(state) {
|
|
1005
|
-
return async function provider(
|
|
1006
|
-
if (!
|
|
842
|
+
return async function provider(name) {
|
|
843
|
+
if (!name) {
|
|
1007
844
|
if (state.currentProvider) {
|
|
1008
|
-
const modeStr = state.useDirectMode ? "direct" : state.currentProvider === "local" ? "local daemon" : "via gateway";
|
|
1009
845
|
console.log(`
|
|
1010
|
-
Current provider: ${c.green(state.currentProvider)}
|
|
846
|
+
Current provider: ${c.green(state.currentProvider)}
|
|
1011
847
|
`);
|
|
1012
848
|
} else {
|
|
1013
849
|
console.log(c.yellow("\nNo provider selected\n"));
|
|
1014
850
|
}
|
|
1015
851
|
return;
|
|
1016
852
|
}
|
|
1017
|
-
await switchProvider(state,
|
|
853
|
+
await switchProvider(state, name);
|
|
1018
854
|
};
|
|
1019
855
|
}
|
|
1020
|
-
async function toggleMode(state, mode) {
|
|
1021
|
-
const newMode = mode || (state.useDirectMode ? "gateway" : "direct");
|
|
1022
|
-
if (newMode === "direct") {
|
|
1023
|
-
state.useDirectMode = true;
|
|
1024
|
-
logSuccess("Switched to direct mode \u{1F517}");
|
|
1025
|
-
console.log(c.dim("Next sandbox will use direct provider packages\n"));
|
|
1026
|
-
if (hasSandbox(state) && !state.useDirectMode) {
|
|
1027
|
-
console.log(c.yellow("Current sandbox is in gateway mode."));
|
|
1028
|
-
console.log(c.dim('Run "restart" to switch to direct mode\n'));
|
|
1029
|
-
}
|
|
1030
|
-
} else {
|
|
1031
|
-
state.useDirectMode = false;
|
|
1032
|
-
logSuccess("Switched to gateway mode \u{1F310}");
|
|
1033
|
-
console.log(c.dim("Next sandbox will use gateway (requires COMPUTESDK_API_KEY)\n"));
|
|
1034
|
-
if (hasSandbox(state) && state.useDirectMode) {
|
|
1035
|
-
console.log(c.yellow("Current sandbox is in direct mode."));
|
|
1036
|
-
console.log(c.dim('Run "restart" to switch to gateway mode\n'));
|
|
1037
|
-
}
|
|
1038
|
-
}
|
|
1039
|
-
}
|
|
1040
|
-
function showMode(state) {
|
|
1041
|
-
const mode = state.useDirectMode ? "direct" : "gateway";
|
|
1042
|
-
const icon = mode === "gateway" ? "\u{1F310}" : "\u{1F517}";
|
|
1043
|
-
console.log(`
|
|
1044
|
-
Current mode: ${c.green(mode)} ${icon}`);
|
|
1045
|
-
if (mode === "gateway") {
|
|
1046
|
-
console.log(c.dim("Routes through ComputeSDK API (requires COMPUTESDK_API_KEY)"));
|
|
1047
|
-
} else {
|
|
1048
|
-
console.log(c.dim("Direct connection to providers (requires provider packages)"));
|
|
1049
|
-
}
|
|
1050
|
-
console.log(`
|
|
1051
|
-
Switch with: ${c.cyan("provider e2b")} (gateway) or ${c.cyan("provider direct e2b")} (direct)
|
|
1052
|
-
`);
|
|
1053
|
-
}
|
|
1054
856
|
function toggleVerbose(state) {
|
|
1055
857
|
state.verbose = !state.verbose;
|
|
1056
858
|
if (state.verbose) {
|
|
@@ -1077,182 +879,6 @@ Verbose mode: ${status}`);
|
|
|
1077
879
|
Toggle with: ${c.cyan("verbose")}
|
|
1078
880
|
`);
|
|
1079
881
|
}
|
|
1080
|
-
async function connectToSandbox(state, sandboxUrl, token) {
|
|
1081
|
-
if (!sandboxUrl) {
|
|
1082
|
-
logError("Usage: connect <sandbox_url> [token]");
|
|
1083
|
-
console.log("Example: connect https://sandbox-123.localhost:8080");
|
|
1084
|
-
console.log("Example: connect https://sandbox-123.localhost:8080 your_access_token");
|
|
1085
|
-
return;
|
|
1086
|
-
}
|
|
1087
|
-
const cleanUrl = sandboxUrl.replace(/\/$/, "");
|
|
1088
|
-
if (hasSandbox(state)) {
|
|
1089
|
-
const shouldDisconnect = await confirm("Disconnect from current sandbox?", false, state);
|
|
1090
|
-
if (!shouldDisconnect) {
|
|
1091
|
-
logWarning("Keeping current sandbox. Connection cancelled.");
|
|
1092
|
-
return;
|
|
1093
|
-
}
|
|
1094
|
-
clearSandbox(state);
|
|
1095
|
-
}
|
|
1096
|
-
const spinner = new Spinner(`Connecting to ${cleanUrl}...`).start();
|
|
1097
|
-
const startTime = Date.now();
|
|
1098
|
-
try {
|
|
1099
|
-
const { Sandbox } = await import("computesdk");
|
|
1100
|
-
let WebSocket;
|
|
1101
|
-
try {
|
|
1102
|
-
const wsModule = await import("ws");
|
|
1103
|
-
WebSocket = wsModule.default;
|
|
1104
|
-
} catch {
|
|
1105
|
-
logError('Failed to import "ws" module. Please install it: pnpm add ws');
|
|
1106
|
-
throw new Error('Missing "ws" dependency');
|
|
1107
|
-
}
|
|
1108
|
-
const sandbox = new Sandbox({
|
|
1109
|
-
sandboxUrl: cleanUrl,
|
|
1110
|
-
sandboxId: "",
|
|
1111
|
-
// Will be populated when we get info
|
|
1112
|
-
provider: "connected",
|
|
1113
|
-
// Mark as directly connected
|
|
1114
|
-
token,
|
|
1115
|
-
// Optional access token
|
|
1116
|
-
WebSocket
|
|
1117
|
-
});
|
|
1118
|
-
const info = await sandbox.getInfo();
|
|
1119
|
-
const duration = Date.now() - startTime;
|
|
1120
|
-
setSandbox(state, sandbox, "connected");
|
|
1121
|
-
spinner.succeed(`Connected to sandbox ${c.dim(`(${formatDuration(duration)})`)}`);
|
|
1122
|
-
console.log(c.dim(`Provider: ${info.provider || "unknown"}`));
|
|
1123
|
-
console.log(c.dim(`Sandbox ID: ${info.id || "unknown"}`));
|
|
1124
|
-
} catch (error) {
|
|
1125
|
-
const duration = Date.now() - startTime;
|
|
1126
|
-
spinner.fail(`Failed to connect ${c.dim(`(${formatDuration(duration)})`)}`);
|
|
1127
|
-
if (error instanceof Error) {
|
|
1128
|
-
logError(`Error: ${error.message}`);
|
|
1129
|
-
if (error.stack) {
|
|
1130
|
-
console.log(c.dim(error.stack));
|
|
1131
|
-
}
|
|
1132
|
-
}
|
|
1133
|
-
throw error;
|
|
1134
|
-
}
|
|
1135
|
-
}
|
|
1136
|
-
async function readLocalConfig() {
|
|
1137
|
-
const os2 = await import("os");
|
|
1138
|
-
const fs2 = await import("fs/promises");
|
|
1139
|
-
const path4 = await import("path");
|
|
1140
|
-
const configPath = path4.join(os2.homedir(), ".compute", "config.json");
|
|
1141
|
-
try {
|
|
1142
|
-
const content = await fs2.readFile(configPath, "utf-8");
|
|
1143
|
-
return JSON.parse(content);
|
|
1144
|
-
} catch {
|
|
1145
|
-
return null;
|
|
1146
|
-
}
|
|
1147
|
-
}
|
|
1148
|
-
async function isLocalDaemonRunning() {
|
|
1149
|
-
const os2 = await import("os");
|
|
1150
|
-
const fs2 = await import("fs/promises");
|
|
1151
|
-
const path4 = await import("path");
|
|
1152
|
-
const pidPath = path4.join(os2.homedir(), ".compute", "compute.pid");
|
|
1153
|
-
try {
|
|
1154
|
-
const pidContent = await fs2.readFile(pidPath, "utf-8");
|
|
1155
|
-
const pid = parseInt(pidContent.trim(), 10);
|
|
1156
|
-
process.kill(pid, 0);
|
|
1157
|
-
return true;
|
|
1158
|
-
} catch {
|
|
1159
|
-
return false;
|
|
1160
|
-
}
|
|
1161
|
-
}
|
|
1162
|
-
async function listLocalSandboxes() {
|
|
1163
|
-
const config2 = await readLocalConfig();
|
|
1164
|
-
if (!config2) {
|
|
1165
|
-
logError("No local daemon config found at ~/.compute/config.json");
|
|
1166
|
-
console.log(c.dim('Run "compute start" to start the local daemon'));
|
|
1167
|
-
return;
|
|
1168
|
-
}
|
|
1169
|
-
const isRunning = await isLocalDaemonRunning();
|
|
1170
|
-
console.log("");
|
|
1171
|
-
console.log(c.bold("Local Daemon Status:"), isRunning ? c.green("Running") : c.red("Stopped"));
|
|
1172
|
-
console.log("");
|
|
1173
|
-
if (!config2.sandboxes || config2.sandboxes.length === 0) {
|
|
1174
|
-
console.log(c.dim("No sandboxes found"));
|
|
1175
|
-
return;
|
|
1176
|
-
}
|
|
1177
|
-
console.log(c.bold("Sandboxes:"));
|
|
1178
|
-
for (const sandbox of config2.sandboxes) {
|
|
1179
|
-
const isMain = sandbox.subdomain === config2.main_subdomain;
|
|
1180
|
-
const mainLabel = isMain ? c.green(" (main)") : "";
|
|
1181
|
-
console.log(` ${c.cyan(sandbox.subdomain)}${mainLabel}`);
|
|
1182
|
-
console.log(c.dim(` https://${sandbox.subdomain}.sandbox.computesdk.com`));
|
|
1183
|
-
}
|
|
1184
|
-
console.log("");
|
|
1185
|
-
console.log(c.dim(`Connect with: local ${config2.main_subdomain}`));
|
|
1186
|
-
console.log("");
|
|
1187
|
-
}
|
|
1188
|
-
async function connectToLocal(state, subdomain) {
|
|
1189
|
-
const config2 = await readLocalConfig();
|
|
1190
|
-
if (!config2) {
|
|
1191
|
-
logError("No local daemon config found at ~/.compute/config.json");
|
|
1192
|
-
console.log(c.dim('Run "compute start" to start the local daemon'));
|
|
1193
|
-
return;
|
|
1194
|
-
}
|
|
1195
|
-
const isRunning = await isLocalDaemonRunning();
|
|
1196
|
-
if (!isRunning) {
|
|
1197
|
-
logError("Local daemon is not running");
|
|
1198
|
-
console.log(c.dim('Run "compute start" to start the local daemon'));
|
|
1199
|
-
return;
|
|
1200
|
-
}
|
|
1201
|
-
const targetSubdomain = subdomain || config2.main_subdomain;
|
|
1202
|
-
const sandbox = config2.sandboxes.find((s) => s.subdomain === targetSubdomain);
|
|
1203
|
-
if (!sandbox) {
|
|
1204
|
-
logError(`Sandbox "${targetSubdomain}" not found`);
|
|
1205
|
-
console.log(c.dim('Run "local list" to see available sandboxes'));
|
|
1206
|
-
return;
|
|
1207
|
-
}
|
|
1208
|
-
const sandboxUrl = `https://${targetSubdomain}.sandbox.computesdk.com`;
|
|
1209
|
-
const token = config2.access_token;
|
|
1210
|
-
if (hasSandbox(state)) {
|
|
1211
|
-
const shouldDisconnect = await confirm("Disconnect from current sandbox?", false, state);
|
|
1212
|
-
if (!shouldDisconnect) {
|
|
1213
|
-
logWarning("Keeping current sandbox. Connection cancelled.");
|
|
1214
|
-
return;
|
|
1215
|
-
}
|
|
1216
|
-
clearSandbox(state);
|
|
1217
|
-
}
|
|
1218
|
-
const spinner = new Spinner(`Connecting to local sandbox ${targetSubdomain}...`).start();
|
|
1219
|
-
const startTime = Date.now();
|
|
1220
|
-
try {
|
|
1221
|
-
const { Sandbox } = await import("computesdk");
|
|
1222
|
-
let WebSocket;
|
|
1223
|
-
try {
|
|
1224
|
-
const wsModule = await import("ws");
|
|
1225
|
-
WebSocket = wsModule.default;
|
|
1226
|
-
} catch {
|
|
1227
|
-
spinner.fail('Failed to import "ws" module');
|
|
1228
|
-
logError("Please install ws: pnpm add ws");
|
|
1229
|
-
throw new Error('Missing "ws" dependency');
|
|
1230
|
-
}
|
|
1231
|
-
const sandboxInstance = new Sandbox({
|
|
1232
|
-
sandboxUrl,
|
|
1233
|
-
sandboxId: targetSubdomain,
|
|
1234
|
-
provider: "local",
|
|
1235
|
-
token,
|
|
1236
|
-
WebSocket
|
|
1237
|
-
});
|
|
1238
|
-
const info = await sandboxInstance.getInfo();
|
|
1239
|
-
const duration = Date.now() - startTime;
|
|
1240
|
-
setSandbox(state, sandboxInstance, "local");
|
|
1241
|
-
state.verbose = true;
|
|
1242
|
-
process.env.COMPUTESDK_DEBUG = "1";
|
|
1243
|
-
spinner.succeed(`Connected to local sandbox ${c.dim(`(${formatDuration(duration)})`)}`);
|
|
1244
|
-
console.log(c.dim(`Sandbox: ${targetSubdomain}`));
|
|
1245
|
-
console.log(c.dim(`URL: ${sandboxUrl}`));
|
|
1246
|
-
console.log(c.dim(`Verbose mode: enabled (for debugging)`));
|
|
1247
|
-
} catch (error) {
|
|
1248
|
-
const duration = Date.now() - startTime;
|
|
1249
|
-
spinner.fail(`Failed to connect ${c.dim(`(${formatDuration(duration)})`)}`);
|
|
1250
|
-
if (error instanceof Error) {
|
|
1251
|
-
logError(`Error: ${error.message}`);
|
|
1252
|
-
}
|
|
1253
|
-
throw error;
|
|
1254
|
-
}
|
|
1255
|
-
}
|
|
1256
882
|
async function cleanupOnExit(state, replServer) {
|
|
1257
883
|
if (!hasSandbox(state)) {
|
|
1258
884
|
return;
|
|
@@ -1261,10 +887,6 @@ async function cleanupOnExit(state, replServer) {
|
|
|
1261
887
|
replServer.pause();
|
|
1262
888
|
}
|
|
1263
889
|
console.log("");
|
|
1264
|
-
if (state.currentProvider === "connected") {
|
|
1265
|
-
logWarning("Disconnecting from external sandbox (not destroying).");
|
|
1266
|
-
return;
|
|
1267
|
-
}
|
|
1268
890
|
const shouldDestroy = await confirm("Destroy active sandbox?", false, state);
|
|
1269
891
|
if (shouldDestroy) {
|
|
1270
892
|
await destroySandbox(state);
|
|
@@ -1307,6 +929,18 @@ function isCommand(value) {
|
|
|
1307
929
|
// src/cli/repl.ts
|
|
1308
930
|
import * as path2 from "path";
|
|
1309
931
|
import * as os from "os";
|
|
932
|
+
function getSandboxMetadata(sandbox) {
|
|
933
|
+
const instance = sandbox.getInstance?.();
|
|
934
|
+
if (typeof instance !== "object" || instance === null || !("config" in instance)) {
|
|
935
|
+
return {};
|
|
936
|
+
}
|
|
937
|
+
const config2 = instance.config;
|
|
938
|
+
if (typeof config2 !== "object" || config2 === null || !("metadata" in config2)) {
|
|
939
|
+
return {};
|
|
940
|
+
}
|
|
941
|
+
const metadata = config2.metadata;
|
|
942
|
+
return typeof metadata === "object" && metadata !== null ? metadata : {};
|
|
943
|
+
}
|
|
1310
944
|
function createREPL(state) {
|
|
1311
945
|
const replServer = repl.start({
|
|
1312
946
|
prompt: "> ",
|
|
@@ -1404,22 +1038,12 @@ function injectCmdContext(replServer) {
|
|
|
1404
1038
|
function injectWorkbenchCommands(replServer, state) {
|
|
1405
1039
|
replServer.context.provider = defineProviderCommand(state);
|
|
1406
1040
|
replServer.context.providers = () => showProviders();
|
|
1407
|
-
replServer.context.mode = async (modeName) => {
|
|
1408
|
-
if (!modeName) {
|
|
1409
|
-
showMode(state);
|
|
1410
|
-
} else {
|
|
1411
|
-
await toggleMode(state, modeName);
|
|
1412
|
-
}
|
|
1413
|
-
};
|
|
1414
1041
|
replServer.context.restart = async () => {
|
|
1415
1042
|
await restartSandbox(state);
|
|
1416
1043
|
};
|
|
1417
1044
|
replServer.context.destroy = async () => {
|
|
1418
1045
|
await destroySandbox(state);
|
|
1419
1046
|
};
|
|
1420
|
-
replServer.context.connect = async (url, token) => {
|
|
1421
|
-
await connectToSandbox(state, url, token);
|
|
1422
|
-
};
|
|
1423
1047
|
replServer.context.info = () => showInfo(state);
|
|
1424
1048
|
replServer.context.verbose = () => {
|
|
1425
1049
|
toggleVerbose(state);
|
|
@@ -1456,13 +1080,6 @@ function injectWorkbenchCommands(replServer, state) {
|
|
|
1456
1080
|
}
|
|
1457
1081
|
return sandboxReady.ready();
|
|
1458
1082
|
};
|
|
1459
|
-
replServer.context.runCode = async (code, runtime) => {
|
|
1460
|
-
const sandbox = state.currentSandbox;
|
|
1461
|
-
if (!sandbox) {
|
|
1462
|
-
throw new Error("No active sandbox. Run a command to auto-create one.");
|
|
1463
|
-
}
|
|
1464
|
-
return sandbox.runCode(code, runtime);
|
|
1465
|
-
};
|
|
1466
1083
|
replServer.context.runCommand = async (command, options) => {
|
|
1467
1084
|
const sandbox = state.currentSandbox;
|
|
1468
1085
|
if (!sandbox) {
|
|
@@ -1481,7 +1098,7 @@ function injectWorkbenchCommands(replServer, state) {
|
|
|
1481
1098
|
return {
|
|
1482
1099
|
sandboxId: sandbox2.sandboxId,
|
|
1483
1100
|
provider: sandbox2.provider,
|
|
1484
|
-
metadata: sandbox2
|
|
1101
|
+
metadata: getSandboxMetadata(sandbox2)
|
|
1485
1102
|
};
|
|
1486
1103
|
}
|
|
1487
1104
|
const compute2 = await getComputeInstance2(state);
|
|
@@ -1491,70 +1108,7 @@ function injectWorkbenchCommands(replServer, state) {
|
|
|
1491
1108
|
return {
|
|
1492
1109
|
sandboxId: sandbox.sandboxId,
|
|
1493
1110
|
provider: sandbox.provider,
|
|
1494
|
-
metadata: sandbox
|
|
1495
|
-
};
|
|
1496
|
-
};
|
|
1497
|
-
replServer.context.findOrCreate = async (options) => {
|
|
1498
|
-
if (state.useDirectMode) {
|
|
1499
|
-
throw new Error('Named sandboxes (findOrCreate) are only available in gateway mode. Use "mode gateway" to switch.');
|
|
1500
|
-
}
|
|
1501
|
-
const { getComputeInstance: getComputeInstance2, confirmSandboxSwitch: confirmSandboxSwitch2 } = await Promise.resolve().then(() => (init_commands(), commands_exports));
|
|
1502
|
-
const { setSandbox: setSandbox2 } = await Promise.resolve().then(() => (init_state(), state_exports));
|
|
1503
|
-
const { logSuccess: logSuccess2 } = await Promise.resolve().then(() => (init_output(), output_exports));
|
|
1504
|
-
const shouldSwitch = await confirmSandboxSwitch2(state);
|
|
1505
|
-
if (!shouldSwitch) {
|
|
1506
|
-
const compute3 = await getComputeInstance2(state);
|
|
1507
|
-
const sandbox2 = await compute3.sandbox.findOrCreate(options);
|
|
1508
|
-
return {
|
|
1509
|
-
sandboxId: sandbox2.sandboxId,
|
|
1510
|
-
provider: sandbox2.provider,
|
|
1511
|
-
name: options.name,
|
|
1512
|
-
namespace: options.namespace || "default",
|
|
1513
|
-
metadata: sandbox2.getInstance().config.metadata || {}
|
|
1514
|
-
};
|
|
1515
|
-
}
|
|
1516
|
-
const compute2 = await getComputeInstance2(state);
|
|
1517
|
-
const sandbox = await compute2.sandbox.findOrCreate(options);
|
|
1518
|
-
setSandbox2(state, sandbox, sandbox.provider);
|
|
1519
|
-
logSuccess2(`Switched to sandbox ${sandbox.sandboxId}`);
|
|
1520
|
-
return {
|
|
1521
|
-
sandboxId: sandbox.sandboxId,
|
|
1522
|
-
provider: sandbox.provider,
|
|
1523
|
-
name: options.name,
|
|
1524
|
-
namespace: options.namespace || "default",
|
|
1525
|
-
metadata: sandbox.getInstance().config.metadata || {}
|
|
1526
|
-
};
|
|
1527
|
-
};
|
|
1528
|
-
replServer.context.find = async (options) => {
|
|
1529
|
-
if (state.useDirectMode) {
|
|
1530
|
-
throw new Error('Named sandboxes (find) are only available in gateway mode. Use "mode gateway" to switch.');
|
|
1531
|
-
}
|
|
1532
|
-
const { getComputeInstance: getComputeInstance2, confirmSandboxSwitch: confirmSandboxSwitch2 } = await Promise.resolve().then(() => (init_commands(), commands_exports));
|
|
1533
|
-
const { setSandbox: setSandbox2 } = await Promise.resolve().then(() => (init_state(), state_exports));
|
|
1534
|
-
const { logSuccess: logSuccess2 } = await Promise.resolve().then(() => (init_output(), output_exports));
|
|
1535
|
-
const compute2 = await getComputeInstance2(state);
|
|
1536
|
-
const sandbox = await compute2.sandbox.find(options);
|
|
1537
|
-
if (!sandbox) {
|
|
1538
|
-
return null;
|
|
1539
|
-
}
|
|
1540
|
-
const shouldSwitch = await confirmSandboxSwitch2(state);
|
|
1541
|
-
if (!shouldSwitch) {
|
|
1542
|
-
return {
|
|
1543
|
-
sandboxId: sandbox.sandboxId,
|
|
1544
|
-
provider: sandbox.provider,
|
|
1545
|
-
name: options.name,
|
|
1546
|
-
namespace: options.namespace || "default",
|
|
1547
|
-
metadata: sandbox.getInstance().config.metadata || {}
|
|
1548
|
-
};
|
|
1549
|
-
}
|
|
1550
|
-
setSandbox2(state, sandbox, sandbox.provider);
|
|
1551
|
-
logSuccess2(`Switched to sandbox ${sandbox.sandboxId}`);
|
|
1552
|
-
return {
|
|
1553
|
-
sandboxId: sandbox.sandboxId,
|
|
1554
|
-
provider: sandbox.provider,
|
|
1555
|
-
name: options.name,
|
|
1556
|
-
namespace: options.namespace || "default",
|
|
1557
|
-
metadata: sandbox.getInstance().config.metadata || {}
|
|
1111
|
+
metadata: getSandboxMetadata(sandbox)
|
|
1558
1112
|
};
|
|
1559
1113
|
};
|
|
1560
1114
|
replServer.context.filesystem = {
|
|
@@ -1613,160 +1167,6 @@ function injectWorkbenchCommands(replServer, state) {
|
|
|
1613
1167
|
};
|
|
1614
1168
|
}
|
|
1615
1169
|
};
|
|
1616
|
-
replServer.context.child = {
|
|
1617
|
-
get create() {
|
|
1618
|
-
return async () => {
|
|
1619
|
-
if (state.useDirectMode) {
|
|
1620
|
-
throw new Error('Child sandboxes are only available in gateway mode. Use "mode gateway" to switch.');
|
|
1621
|
-
}
|
|
1622
|
-
const sandbox = state.currentSandbox;
|
|
1623
|
-
if (!sandbox) {
|
|
1624
|
-
throw new Error("No active sandbox. Run a command to auto-create one.");
|
|
1625
|
-
}
|
|
1626
|
-
const instance = sandbox.getInstance();
|
|
1627
|
-
return instance.child.create();
|
|
1628
|
-
};
|
|
1629
|
-
},
|
|
1630
|
-
get list() {
|
|
1631
|
-
return async () => {
|
|
1632
|
-
if (state.useDirectMode) {
|
|
1633
|
-
throw new Error('Child sandboxes are only available in gateway mode. Use "mode gateway" to switch.');
|
|
1634
|
-
}
|
|
1635
|
-
const sandbox = state.currentSandbox;
|
|
1636
|
-
if (!sandbox) {
|
|
1637
|
-
throw new Error("No active sandbox. Run a command to auto-create one.");
|
|
1638
|
-
}
|
|
1639
|
-
const instance = sandbox.getInstance();
|
|
1640
|
-
return instance.child.list();
|
|
1641
|
-
};
|
|
1642
|
-
},
|
|
1643
|
-
get retrieve() {
|
|
1644
|
-
return async (subdomain) => {
|
|
1645
|
-
if (state.useDirectMode) {
|
|
1646
|
-
throw new Error('Child sandboxes are only available in gateway mode. Use "mode gateway" to switch.');
|
|
1647
|
-
}
|
|
1648
|
-
const sandbox = state.currentSandbox;
|
|
1649
|
-
if (!sandbox) {
|
|
1650
|
-
throw new Error("No active sandbox. Run a command to auto-create one.");
|
|
1651
|
-
}
|
|
1652
|
-
const instance = sandbox.getInstance();
|
|
1653
|
-
return instance.child.retrieve(subdomain);
|
|
1654
|
-
};
|
|
1655
|
-
},
|
|
1656
|
-
get destroy() {
|
|
1657
|
-
return async (subdomain, options) => {
|
|
1658
|
-
if (state.useDirectMode) {
|
|
1659
|
-
throw new Error('Child sandboxes are only available in gateway mode. Use "mode gateway" to switch.');
|
|
1660
|
-
}
|
|
1661
|
-
const sandbox = state.currentSandbox;
|
|
1662
|
-
if (!sandbox) {
|
|
1663
|
-
throw new Error("No active sandbox. Run a command to auto-create one.");
|
|
1664
|
-
}
|
|
1665
|
-
const instance = sandbox.getInstance();
|
|
1666
|
-
return instance.child.destroy(subdomain, options);
|
|
1667
|
-
};
|
|
1668
|
-
}
|
|
1669
|
-
};
|
|
1670
|
-
replServer.context.server = {
|
|
1671
|
-
get start() {
|
|
1672
|
-
return async (options) => {
|
|
1673
|
-
const sandbox = state.currentSandbox;
|
|
1674
|
-
if (!sandbox) {
|
|
1675
|
-
throw new Error("No active sandbox. Run a command to auto-create one.");
|
|
1676
|
-
}
|
|
1677
|
-
return sandbox.server.start(options);
|
|
1678
|
-
};
|
|
1679
|
-
},
|
|
1680
|
-
get list() {
|
|
1681
|
-
return async () => {
|
|
1682
|
-
const sandbox = state.currentSandbox;
|
|
1683
|
-
if (!sandbox) {
|
|
1684
|
-
throw new Error("No active sandbox. Run a command to auto-create one.");
|
|
1685
|
-
}
|
|
1686
|
-
return sandbox.server.list();
|
|
1687
|
-
};
|
|
1688
|
-
},
|
|
1689
|
-
get retrieve() {
|
|
1690
|
-
return async (slug) => {
|
|
1691
|
-
const sandbox = state.currentSandbox;
|
|
1692
|
-
if (!sandbox) {
|
|
1693
|
-
throw new Error("No active sandbox. Run a command to auto-create one.");
|
|
1694
|
-
}
|
|
1695
|
-
return sandbox.server.retrieve(slug);
|
|
1696
|
-
};
|
|
1697
|
-
},
|
|
1698
|
-
get stop() {
|
|
1699
|
-
return async (slug) => {
|
|
1700
|
-
const sandbox = state.currentSandbox;
|
|
1701
|
-
if (!sandbox) {
|
|
1702
|
-
throw new Error("No active sandbox. Run a command to auto-create one.");
|
|
1703
|
-
}
|
|
1704
|
-
return sandbox.server.stop(slug);
|
|
1705
|
-
};
|
|
1706
|
-
},
|
|
1707
|
-
get restart() {
|
|
1708
|
-
return async (slug) => {
|
|
1709
|
-
const sandbox = state.currentSandbox;
|
|
1710
|
-
if (!sandbox) {
|
|
1711
|
-
throw new Error("No active sandbox. Run a command to auto-create one.");
|
|
1712
|
-
}
|
|
1713
|
-
return sandbox.server.restart(slug);
|
|
1714
|
-
};
|
|
1715
|
-
}
|
|
1716
|
-
};
|
|
1717
|
-
replServer.context.terminal = {
|
|
1718
|
-
get create() {
|
|
1719
|
-
return async (options) => {
|
|
1720
|
-
const sandbox = state.currentSandbox;
|
|
1721
|
-
if (!sandbox) {
|
|
1722
|
-
throw new Error("No active sandbox. Run a command to auto-create one.");
|
|
1723
|
-
}
|
|
1724
|
-
const term = await sandbox.terminal.create(options);
|
|
1725
|
-
if (state.verbose) {
|
|
1726
|
-
if (term._ws) {
|
|
1727
|
-
term._ws.config.debug = true;
|
|
1728
|
-
}
|
|
1729
|
-
term.on("output", (data) => {
|
|
1730
|
-
console.log("[terminal:output]", JSON.stringify(data));
|
|
1731
|
-
});
|
|
1732
|
-
term.on("error", (error) => {
|
|
1733
|
-
console.log("[terminal:error]", error);
|
|
1734
|
-
});
|
|
1735
|
-
term.on("destroyed", () => {
|
|
1736
|
-
console.log("[terminal:destroyed]");
|
|
1737
|
-
});
|
|
1738
|
-
}
|
|
1739
|
-
return term;
|
|
1740
|
-
};
|
|
1741
|
-
},
|
|
1742
|
-
get list() {
|
|
1743
|
-
return async () => {
|
|
1744
|
-
const sandbox = state.currentSandbox;
|
|
1745
|
-
if (!sandbox) {
|
|
1746
|
-
throw new Error("No active sandbox. Run a command to auto-create one.");
|
|
1747
|
-
}
|
|
1748
|
-
return sandbox.terminal.list();
|
|
1749
|
-
};
|
|
1750
|
-
},
|
|
1751
|
-
get retrieve() {
|
|
1752
|
-
return async (id) => {
|
|
1753
|
-
const sandbox = state.currentSandbox;
|
|
1754
|
-
if (!sandbox) {
|
|
1755
|
-
throw new Error("No active sandbox. Run a command to auto-create one.");
|
|
1756
|
-
}
|
|
1757
|
-
return sandbox.terminal.retrieve(id);
|
|
1758
|
-
};
|
|
1759
|
-
},
|
|
1760
|
-
get destroy() {
|
|
1761
|
-
return async (id) => {
|
|
1762
|
-
const sandbox = state.currentSandbox;
|
|
1763
|
-
if (!sandbox) {
|
|
1764
|
-
throw new Error("No active sandbox. Run a command to auto-create one.");
|
|
1765
|
-
}
|
|
1766
|
-
return sandbox.terminal.destroy(id);
|
|
1767
|
-
};
|
|
1768
|
-
}
|
|
1769
|
-
};
|
|
1770
1170
|
replServer.context.getInstance = () => {
|
|
1771
1171
|
const sandbox = state.currentSandbox;
|
|
1772
1172
|
if (!sandbox) {
|
|
@@ -1777,36 +1177,13 @@ function injectWorkbenchCommands(replServer, state) {
|
|
|
1777
1177
|
}
|
|
1778
1178
|
function setupSmartEvaluator(replServer, state) {
|
|
1779
1179
|
const originalEval = replServer.eval;
|
|
1780
|
-
const workbenchCommands = /* @__PURE__ */ new Set(["help", "providers", "info", "env", "restart", "destroy", "
|
|
1180
|
+
const workbenchCommands = /* @__PURE__ */ new Set(["help", "providers", "info", "env", "restart", "destroy", "verbose", "sandboxInfo"]);
|
|
1781
1181
|
replServer.eval = function(cmd2, context, filename, callback) {
|
|
1782
1182
|
const trimmedCmd = cmd2.trim();
|
|
1783
|
-
const
|
|
1784
|
-
if (providerLocalMatch) {
|
|
1785
|
-
const arg = providerLocalMatch[1];
|
|
1786
|
-
const providerCmd = arg ? `await provider('local', '${arg}')` : `await provider('local')`;
|
|
1787
|
-
originalEval.call(this, providerCmd, context, filename, callback);
|
|
1788
|
-
return;
|
|
1789
|
-
}
|
|
1790
|
-
const providerMatch = trimmedCmd.match(/^provider(?:\s+(direct|gateway))?\s+([\w-]+)$/);
|
|
1183
|
+
const providerMatch = trimmedCmd.match(/^provider\s+([\w-]+)$/);
|
|
1791
1184
|
if (providerMatch) {
|
|
1792
|
-
const
|
|
1793
|
-
|
|
1794
|
-
const providerCmd = mode ? `await provider('${mode}', '${providerName}')` : `await provider('${providerName}')`;
|
|
1795
|
-
originalEval.call(this, providerCmd, context, filename, callback);
|
|
1796
|
-
return;
|
|
1797
|
-
}
|
|
1798
|
-
const providerOnlyMatch = trimmedCmd.match(/^provider\s+(direct|gateway)$/);
|
|
1799
|
-
if (providerOnlyMatch) {
|
|
1800
|
-
const mode = providerOnlyMatch[1];
|
|
1801
|
-
const providerCmd = `await provider('${mode}')`;
|
|
1802
|
-
originalEval.call(this, providerCmd, context, filename, callback);
|
|
1803
|
-
return;
|
|
1804
|
-
}
|
|
1805
|
-
const modeMatch = trimmedCmd.match(/^mode\s+(gateway|direct)$/);
|
|
1806
|
-
if (modeMatch) {
|
|
1807
|
-
const modeName = modeMatch[1];
|
|
1808
|
-
const modeCmd = `await mode('${modeName}')`;
|
|
1809
|
-
originalEval.call(this, modeCmd, context, filename, callback);
|
|
1185
|
+
const providerName = providerMatch[1];
|
|
1186
|
+
originalEval.call(this, `await provider('${providerName}')`, context, filename, callback);
|
|
1810
1187
|
return;
|
|
1811
1188
|
}
|
|
1812
1189
|
const dollarMatch = trimmedCmd.match(/^\$(.+)$/);
|
|
@@ -1859,14 +1236,10 @@ function setupSmartEvaluator(replServer, state) {
|
|
|
1859
1236
|
function setupAutocomplete(replServer, state) {
|
|
1860
1237
|
const originalCompleter = replServer.completer;
|
|
1861
1238
|
const workbenchCommands = {
|
|
1862
|
-
"provider": [...PROVIDER_NAMES
|
|
1863
|
-
// Include 'local' as a provider option
|
|
1864
|
-
"mode": ["gateway", "direct"],
|
|
1239
|
+
"provider": [...PROVIDER_NAMES],
|
|
1865
1240
|
"providers": [],
|
|
1866
1241
|
"restart": [],
|
|
1867
1242
|
"destroy": [],
|
|
1868
|
-
"connect": [],
|
|
1869
|
-
// Connect takes a URL argument
|
|
1870
1243
|
"info": [],
|
|
1871
1244
|
"env": [],
|
|
1872
1245
|
"help": [],
|
|
@@ -1875,7 +1248,6 @@ function setupAutocomplete(replServer, state) {
|
|
|
1875
1248
|
".exit": [],
|
|
1876
1249
|
// Sandbox methods
|
|
1877
1250
|
"getUrl": [],
|
|
1878
|
-
"runCode": [],
|
|
1879
1251
|
"sandboxInfo": [],
|
|
1880
1252
|
"getInstance": []
|
|
1881
1253
|
// Filesystem is an object, so it gets dot notation autocomplete automatically
|
|
@@ -1965,39 +1337,10 @@ init_providers();
|
|
|
1965
1337
|
init_commands();
|
|
1966
1338
|
async function startWorkbench() {
|
|
1967
1339
|
const state = createState();
|
|
1968
|
-
const localDaemonRunning = await isLocalDaemonRunning();
|
|
1969
1340
|
state.availableProviders = getAvailableProviders();
|
|
1970
|
-
|
|
1971
|
-
|
|
1972
|
-
}
|
|
1973
|
-
const detectedProvider = autoDetectProvider();
|
|
1974
|
-
if (localDaemonRunning) {
|
|
1975
|
-
state.currentProvider = "local";
|
|
1976
|
-
state.useDirectMode = false;
|
|
1977
|
-
state.verbose = true;
|
|
1978
|
-
process.env.COMPUTESDK_DEBUG = "1";
|
|
1979
|
-
} else {
|
|
1980
|
-
const hasGateway = state.availableProviders.includes("gateway");
|
|
1981
|
-
const backendProviders = state.availableProviders.filter((p) => p !== "gateway" && p !== "local");
|
|
1982
|
-
if (hasGateway && backendProviders.length > 0) {
|
|
1983
|
-
state.currentProvider = backendProviders[0] || "e2b";
|
|
1984
|
-
state.useDirectMode = false;
|
|
1985
|
-
} else if (backendProviders.length > 0) {
|
|
1986
|
-
state.currentProvider = backendProviders[0];
|
|
1987
|
-
state.useDirectMode = true;
|
|
1988
|
-
} else {
|
|
1989
|
-
state.currentProvider = detectedProvider;
|
|
1990
|
-
state.useDirectMode = false;
|
|
1991
|
-
}
|
|
1992
|
-
}
|
|
1993
|
-
showWelcome(state.availableProviders, state.currentProvider, state.useDirectMode, localDaemonRunning);
|
|
1341
|
+
state.currentProvider = state.availableProviders[0] ?? null;
|
|
1342
|
+
showWelcome(state.availableProviders, state.currentProvider);
|
|
1994
1343
|
const replServer = createREPL(state);
|
|
1995
|
-
if (localDaemonRunning) {
|
|
1996
|
-
try {
|
|
1997
|
-
await connectToLocal(state);
|
|
1998
|
-
} catch {
|
|
1999
|
-
}
|
|
2000
|
-
}
|
|
2001
1344
|
replServer.on("exit", async () => {
|
|
2002
1345
|
await cleanupOnExit(state, replServer);
|
|
2003
1346
|
process.exit(0);
|