sparkecoder 0.1.7 → 0.1.8
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/cli.js +107 -23
- package/dist/cli.js.map +1 -1
- package/dist/index.js +102 -22
- package/dist/index.js.map +1 -1
- package/dist/server/index.d.ts +1 -0
- package/dist/server/index.js +102 -22
- package/dist/server/index.js.map +1 -1
- package/package.json +4 -1
package/dist/cli.js
CHANGED
|
@@ -4478,6 +4478,33 @@ async function findWebPort(preferredPort) {
|
|
|
4478
4478
|
}
|
|
4479
4479
|
return { port: preferredPort, alreadyRunning: false };
|
|
4480
4480
|
}
|
|
4481
|
+
function hasProductionBuild(webDir) {
|
|
4482
|
+
const buildIdPath = join3(webDir, ".next", "BUILD_ID");
|
|
4483
|
+
return existsSync7(buildIdPath);
|
|
4484
|
+
}
|
|
4485
|
+
function runCommand(command, args, cwd, env) {
|
|
4486
|
+
return new Promise((resolve8) => {
|
|
4487
|
+
const child = spawn(command, args, {
|
|
4488
|
+
cwd,
|
|
4489
|
+
stdio: ["ignore", "pipe", "pipe"],
|
|
4490
|
+
env,
|
|
4491
|
+
shell: true
|
|
4492
|
+
});
|
|
4493
|
+
let output = "";
|
|
4494
|
+
child.stdout?.on("data", (data) => {
|
|
4495
|
+
output += data.toString();
|
|
4496
|
+
});
|
|
4497
|
+
child.stderr?.on("data", (data) => {
|
|
4498
|
+
output += data.toString();
|
|
4499
|
+
});
|
|
4500
|
+
child.on("close", (code) => {
|
|
4501
|
+
resolve8({ success: code === 0, output });
|
|
4502
|
+
});
|
|
4503
|
+
child.on("error", (err) => {
|
|
4504
|
+
resolve8({ success: false, output: err.message });
|
|
4505
|
+
});
|
|
4506
|
+
});
|
|
4507
|
+
}
|
|
4481
4508
|
async function startWebUI(apiPort, webPort = DEFAULT_WEB_PORT, quiet = false) {
|
|
4482
4509
|
const webDir = getWebDirectory();
|
|
4483
4510
|
if (!webDir) {
|
|
@@ -4489,39 +4516,90 @@ async function startWebUI(apiPort, webPort = DEFAULT_WEB_PORT, quiet = false) {
|
|
|
4489
4516
|
if (!quiet) console.log(` \u2713 Web UI already running at http://localhost:${actualPort}`);
|
|
4490
4517
|
return { process: null, port: actualPort };
|
|
4491
4518
|
}
|
|
4492
|
-
const
|
|
4493
|
-
const
|
|
4494
|
-
const
|
|
4519
|
+
const usePnpm = existsSync7(join3(webDir, "pnpm-lock.yaml"));
|
|
4520
|
+
const useNpm = !usePnpm && existsSync7(join3(webDir, "package-lock.json"));
|
|
4521
|
+
const pkgManager = usePnpm ? "pnpm" : useNpm ? "npm" : "npx";
|
|
4522
|
+
const { NODE_OPTIONS, TSX_TSCONFIG_PATH, ...cleanEnv } = process.env;
|
|
4523
|
+
const webEnv = {
|
|
4524
|
+
...cleanEnv,
|
|
4525
|
+
NEXT_PUBLIC_API_URL: `http://127.0.0.1:${apiPort}`
|
|
4526
|
+
};
|
|
4527
|
+
const isProduction = process.env.NODE_ENV === "production";
|
|
4528
|
+
let command;
|
|
4529
|
+
let args;
|
|
4530
|
+
if (isProduction) {
|
|
4531
|
+
if (!hasProductionBuild(webDir)) {
|
|
4532
|
+
if (!quiet) console.log(" \u{1F4E6} Building Web UI for production...");
|
|
4533
|
+
const buildArgs = pkgManager === "npx" ? ["next", "build"] : ["run", "build"];
|
|
4534
|
+
const buildResult = await runCommand(pkgManager, buildArgs, webDir, webEnv);
|
|
4535
|
+
if (!buildResult.success) {
|
|
4536
|
+
if (!quiet) console.error(" \u274C Web UI build failed");
|
|
4537
|
+
return { process: null, port: actualPort };
|
|
4538
|
+
}
|
|
4539
|
+
if (!quiet) console.log(" \u2713 Web UI build complete");
|
|
4540
|
+
}
|
|
4541
|
+
command = pkgManager;
|
|
4542
|
+
args = pkgManager === "npx" ? ["next", "start", "-p", String(actualPort)] : ["run", "start", "-p", String(actualPort)];
|
|
4543
|
+
} else {
|
|
4544
|
+
command = pkgManager;
|
|
4545
|
+
args = pkgManager === "npx" ? ["next", "dev", "-p", String(actualPort)] : ["run", "dev", "-p", String(actualPort)];
|
|
4546
|
+
}
|
|
4495
4547
|
const child = spawn(command, args, {
|
|
4496
4548
|
cwd: webDir,
|
|
4497
4549
|
stdio: ["ignore", "pipe", "pipe"],
|
|
4498
|
-
env:
|
|
4499
|
-
|
|
4500
|
-
|
|
4501
|
-
},
|
|
4502
|
-
detached: false
|
|
4550
|
+
env: webEnv,
|
|
4551
|
+
detached: false,
|
|
4552
|
+
shell: true
|
|
4503
4553
|
});
|
|
4554
|
+
const startupTimeout = 3e4;
|
|
4504
4555
|
let started = false;
|
|
4505
|
-
|
|
4506
|
-
|
|
4507
|
-
|
|
4508
|
-
|
|
4509
|
-
if (!
|
|
4510
|
-
|
|
4511
|
-
|
|
4512
|
-
|
|
4556
|
+
let exited = false;
|
|
4557
|
+
let exitCode = null;
|
|
4558
|
+
const startedPromise = new Promise((resolve8) => {
|
|
4559
|
+
const timeout = setTimeout(() => {
|
|
4560
|
+
if (!started && !exited) {
|
|
4561
|
+
resolve8(false);
|
|
4562
|
+
}
|
|
4563
|
+
}, startupTimeout);
|
|
4564
|
+
child.stdout?.on("data", (data) => {
|
|
4565
|
+
const output = data.toString();
|
|
4566
|
+
if (!started && (output.includes("Ready") || output.includes("started") || output.includes("localhost"))) {
|
|
4567
|
+
started = true;
|
|
4568
|
+
clearTimeout(timeout);
|
|
4569
|
+
resolve8(true);
|
|
4570
|
+
}
|
|
4571
|
+
});
|
|
4513
4572
|
child.stderr?.on("data", (data) => {
|
|
4514
4573
|
const output = data.toString();
|
|
4515
4574
|
if (output.toLowerCase().includes("error")) {
|
|
4516
|
-
console.error(` Web UI error: ${output.trim()}`);
|
|
4575
|
+
if (!quiet) console.error(` Web UI error: ${output.trim().slice(0, 200)}`);
|
|
4517
4576
|
}
|
|
4518
4577
|
});
|
|
4519
|
-
|
|
4520
|
-
|
|
4521
|
-
|
|
4578
|
+
child.on("error", (err) => {
|
|
4579
|
+
if (!quiet) console.error(` \u274C Web UI spawn error: ${err.message}`);
|
|
4580
|
+
clearTimeout(timeout);
|
|
4581
|
+
resolve8(false);
|
|
4582
|
+
});
|
|
4583
|
+
child.on("exit", (code) => {
|
|
4584
|
+
exited = true;
|
|
4585
|
+
exitCode = code;
|
|
4586
|
+
if (!started) {
|
|
4587
|
+
clearTimeout(timeout);
|
|
4588
|
+
resolve8(false);
|
|
4589
|
+
}
|
|
4590
|
+
webUIProcess = null;
|
|
4591
|
+
});
|
|
4522
4592
|
});
|
|
4523
4593
|
webUIProcess = child;
|
|
4524
|
-
|
|
4594
|
+
const didStart = await startedPromise;
|
|
4595
|
+
if (!didStart) {
|
|
4596
|
+
if (exited && exitCode !== 0) {
|
|
4597
|
+
if (!quiet) console.error(` \u274C Web UI failed to start (exit code: ${exitCode})`);
|
|
4598
|
+
} else if (!exited) {
|
|
4599
|
+
if (!quiet) console.log(` \u26A0 Web UI startup timed out, continuing anyway...`);
|
|
4600
|
+
}
|
|
4601
|
+
}
|
|
4602
|
+
return { process: child, port: actualPort, started: didStart };
|
|
4525
4603
|
}
|
|
4526
4604
|
function stopWebUI() {
|
|
4527
4605
|
if (webUIProcess) {
|
|
@@ -4615,11 +4693,13 @@ async function startServer(options = {}) {
|
|
|
4615
4693
|
hostname: host
|
|
4616
4694
|
});
|
|
4617
4695
|
let webPort;
|
|
4696
|
+
let webStarted;
|
|
4618
4697
|
if (options.webUI !== false) {
|
|
4619
4698
|
const result = await startWebUI(port, options.webPort || DEFAULT_WEB_PORT, options.quiet);
|
|
4620
4699
|
webPort = result.port;
|
|
4700
|
+
webStarted = result.started;
|
|
4621
4701
|
}
|
|
4622
|
-
return { app, port, host, webPort };
|
|
4702
|
+
return { app, port, host, webPort, webStarted };
|
|
4623
4703
|
}
|
|
4624
4704
|
function stopServer() {
|
|
4625
4705
|
stopWebUI();
|
|
@@ -5285,7 +5365,11 @@ async function runChat(options) {
|
|
|
5285
5365
|
});
|
|
5286
5366
|
serverStartedByUs = true;
|
|
5287
5367
|
const webUrl = `http://localhost:${serverResult.webPort || options.webPort || "6969"}`;
|
|
5288
|
-
|
|
5368
|
+
if (serverResult.webStarted === false) {
|
|
5369
|
+
spinner.warn(`Web UI failed to start at ${chalk.cyan(webUrl)}`);
|
|
5370
|
+
} else {
|
|
5371
|
+
spinner.succeed(`Web UI: ${chalk.cyan(webUrl)}`);
|
|
5372
|
+
}
|
|
5289
5373
|
const cleanup = () => {
|
|
5290
5374
|
if (serverStartedByUs) {
|
|
5291
5375
|
stopServer();
|