pipely-ai 1.3.5 → 1.4.0
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/index.js +47 -45
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -449,10 +449,17 @@ function printDockerHelp(os) {
|
|
|
449
449
|
|
|
450
450
|
// ── Local Mode ──────────────────────────────────────
|
|
451
451
|
|
|
452
|
-
const PIPELY_DIR = join(process.env.HOME || process.env.USERPROFILE || ".", ".pipely");
|
|
453
452
|
const BUNDLE_REPO = "Pedro-Furtado/pipely-ai";
|
|
454
453
|
const BUNDLE_NAME = "pipely-local.tar.gz";
|
|
455
454
|
|
|
455
|
+
function getLocalDir() {
|
|
456
|
+
return process.cwd();
|
|
457
|
+
}
|
|
458
|
+
|
|
459
|
+
function getBundleDir() {
|
|
460
|
+
return join(getLocalDir(), ".pipely");
|
|
461
|
+
}
|
|
462
|
+
|
|
456
463
|
async function getLatestReleaseUrl() {
|
|
457
464
|
return new Promise((resolve) => {
|
|
458
465
|
const url = `https://api.github.com/repos/${BUNDLE_REPO}/releases/latest`;
|
|
@@ -500,37 +507,42 @@ function extractTarGz(file, dest) {
|
|
|
500
507
|
}
|
|
501
508
|
|
|
502
509
|
function getLocalEnvPath() {
|
|
503
|
-
return join(
|
|
510
|
+
return join(getLocalDir(), ".env");
|
|
504
511
|
}
|
|
505
512
|
|
|
506
513
|
function isLocalInstalled() {
|
|
507
|
-
|
|
514
|
+
const bd = getBundleDir();
|
|
515
|
+
return existsSync(join(bd, "package.json")) && existsSync(join(bd, "server"));
|
|
508
516
|
}
|
|
509
517
|
|
|
510
518
|
function generateLocalEnv() {
|
|
511
519
|
const jwtSecret = generateKey(64);
|
|
512
520
|
const setupKey = randomUUID();
|
|
521
|
+
const dir = getLocalDir();
|
|
513
522
|
|
|
514
|
-
const dbPath = join(
|
|
523
|
+
const dbPath = join(dir, "data", "pipely.db").replace(/\\/g, "/");
|
|
524
|
+
const frontendPath = join(getBundleDir(), "frontend").replace(/\\/g, "/");
|
|
515
525
|
const env = `# Pipely AI — Local Mode
|
|
516
526
|
DATABASE_URL=file:${dbPath}
|
|
517
527
|
JWT_SECRET=${jwtSecret}
|
|
518
528
|
OWNER_SETUP_KEY=${setupKey}
|
|
519
|
-
FRONTEND_URL=http://localhost:
|
|
529
|
+
FRONTEND_URL=http://localhost:3333
|
|
520
530
|
BACKEND_URL=http://localhost:3333
|
|
531
|
+
SERVE_FRONTEND=${frontendPath}
|
|
521
532
|
POLL_INTERVAL_MS=60000
|
|
522
533
|
PORT=3333
|
|
523
|
-
VITE_API_URL=http://localhost:3333
|
|
524
534
|
`;
|
|
525
535
|
return { env, setupKey };
|
|
526
536
|
}
|
|
527
537
|
|
|
528
538
|
async function installLocal() {
|
|
529
539
|
const os = detectOS();
|
|
540
|
+
const dir = getLocalDir();
|
|
541
|
+
const bundleDir = getBundleDir();
|
|
530
542
|
|
|
531
543
|
// Check if already installed
|
|
532
544
|
if (isLocalInstalled()) {
|
|
533
|
-
console.log(` ${c.green}✓${c.reset} Pipely AI ja instalado em ${c.dim}${
|
|
545
|
+
console.log(` ${c.green}✓${c.reset} Pipely AI ja instalado em ${c.dim}${dir}${c.reset}\n`);
|
|
534
546
|
console.log(` Iniciando...\n`);
|
|
535
547
|
return runLocal();
|
|
536
548
|
}
|
|
@@ -549,8 +561,8 @@ async function installLocal() {
|
|
|
549
561
|
}
|
|
550
562
|
console.log(`${c.green}✓${c.reset}`);
|
|
551
563
|
|
|
552
|
-
const tmpFile = join(
|
|
553
|
-
mkdirSync(
|
|
564
|
+
const tmpFile = join(dir, BUNDLE_NAME);
|
|
565
|
+
mkdirSync(bundleDir, { recursive: true });
|
|
554
566
|
|
|
555
567
|
process.stdout.write(` Baixando bundle... `);
|
|
556
568
|
try {
|
|
@@ -565,7 +577,7 @@ async function installLocal() {
|
|
|
565
577
|
// Extract
|
|
566
578
|
process.stdout.write(` Extraindo... `);
|
|
567
579
|
try {
|
|
568
|
-
extractTarGz(tmpFile,
|
|
580
|
+
extractTarGz(tmpFile, bundleDir);
|
|
569
581
|
console.log(`${c.green}✓${c.reset}`);
|
|
570
582
|
} catch (err) {
|
|
571
583
|
console.log(`${c.red}✗${c.reset}`);
|
|
@@ -580,7 +592,7 @@ async function installLocal() {
|
|
|
580
592
|
console.log(`\n ${c.magenta}── Instalando dependencias ────────────────${c.reset}\n`);
|
|
581
593
|
try {
|
|
582
594
|
execSync("npm install --production --no-fund --no-audit", {
|
|
583
|
-
cwd:
|
|
595
|
+
cwd: bundleDir,
|
|
584
596
|
stdio: "inherit",
|
|
585
597
|
});
|
|
586
598
|
console.log(`\n ${c.green}✓${c.reset} Dependencias instaladas`);
|
|
@@ -596,15 +608,16 @@ async function installLocal() {
|
|
|
596
608
|
console.log(` ${c.green}✓${c.reset} .env gerado`);
|
|
597
609
|
|
|
598
610
|
// Create data directory
|
|
599
|
-
mkdirSync(join(
|
|
611
|
+
mkdirSync(join(dir, "data"), { recursive: true });
|
|
600
612
|
|
|
601
613
|
// Setup database
|
|
614
|
+
const dbPath = join(dir, "data", "pipely.db").replace(/\\/g, "/");
|
|
602
615
|
process.stdout.write(` Criando banco de dados... `);
|
|
603
616
|
try {
|
|
604
617
|
execSync("npx prisma db push", {
|
|
605
|
-
cwd: join(
|
|
618
|
+
cwd: join(bundleDir, "server"),
|
|
606
619
|
stdio: "pipe",
|
|
607
|
-
env: { ...process.env, DATABASE_URL: `file:${
|
|
620
|
+
env: { ...process.env, DATABASE_URL: `file:${dbPath}` },
|
|
608
621
|
});
|
|
609
622
|
console.log(`${c.green}✓${c.reset}`);
|
|
610
623
|
} catch (err) {
|
|
@@ -622,8 +635,8 @@ async function installLocal() {
|
|
|
622
635
|
console.log("");
|
|
623
636
|
console.log(` ${c.bold}Setup Key:${c.reset} ${c.yellow}${setupKey}${c.reset}`);
|
|
624
637
|
console.log("");
|
|
625
|
-
console.log(` ${c.bold}Diretorio:${c.reset} ${c.dim}${
|
|
626
|
-
console.log(` ${c.bold}Banco de dados:${c.reset} ${c.dim}${join(
|
|
638
|
+
console.log(` ${c.bold}Diretorio:${c.reset} ${c.dim}${dir}${c.reset}`);
|
|
639
|
+
console.log(` ${c.bold}Banco de dados:${c.reset} ${c.dim}${join(dir, "data/pipely.db")}${c.reset}`);
|
|
627
640
|
console.log("");
|
|
628
641
|
|
|
629
642
|
return runLocal();
|
|
@@ -635,6 +648,8 @@ async function runLocal() {
|
|
|
635
648
|
process.exit(1);
|
|
636
649
|
}
|
|
637
650
|
|
|
651
|
+
const bundleDir = getBundleDir();
|
|
652
|
+
|
|
638
653
|
console.log(` ${c.magenta}── Iniciando Pipely AI ────────────────────${c.reset}\n`);
|
|
639
654
|
|
|
640
655
|
const envPath = getLocalEnvPath();
|
|
@@ -647,40 +662,27 @@ async function runLocal() {
|
|
|
647
662
|
|
|
648
663
|
const childEnv = { ...process.env, ...envVars };
|
|
649
664
|
|
|
650
|
-
// Start server
|
|
651
|
-
const server = fork(join(
|
|
652
|
-
cwd: join(
|
|
665
|
+
// Start server (serves frontend via SERVE_FRONTEND env)
|
|
666
|
+
const server = fork(join(bundleDir, "server/dist/index.js"), [], {
|
|
667
|
+
cwd: join(bundleDir, "server"),
|
|
653
668
|
env: { ...childEnv, PORT: "3333" },
|
|
654
669
|
stdio: "inherit",
|
|
655
670
|
});
|
|
656
671
|
|
|
657
672
|
// Start agent
|
|
658
|
-
const agent = fork(join(
|
|
659
|
-
cwd: join(
|
|
673
|
+
const agent = fork(join(bundleDir, "agent/dist/index.js"), [], {
|
|
674
|
+
cwd: join(bundleDir, "agent"),
|
|
660
675
|
env: { ...childEnv, PORT: "3335" },
|
|
661
676
|
stdio: "inherit",
|
|
662
677
|
});
|
|
663
678
|
|
|
664
|
-
//
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
app.get(/^\/(?!api|health).*/, (_req, res) => {
|
|
672
|
-
res.sendFile(join(frontendDir, "index.html"));
|
|
673
|
-
});
|
|
674
|
-
const fPort = envVars.FRONTEND_PORT || 3000;
|
|
675
|
-
app.listen(fPort, () => {
|
|
676
|
-
console.log(` ${c.cyan}Frontend:${c.reset} http://localhost:${fPort}`);
|
|
677
|
-
console.log(` ${c.cyan}Backend:${c.reset} http://localhost:3333`);
|
|
678
|
-
console.log(` ${c.cyan}Agent:${c.reset} http://localhost:3335`);
|
|
679
|
-
console.log("");
|
|
680
|
-
console.log(` Pressione ${c.bold}Ctrl+C${c.reset} para parar.\n`);
|
|
681
|
-
});
|
|
682
|
-
}
|
|
683
|
-
}
|
|
679
|
+
// Wait for server to start then print endpoints
|
|
680
|
+
await sleep(2000);
|
|
681
|
+
console.log("");
|
|
682
|
+
console.log(` ${c.cyan}App:${c.reset} http://localhost:3333`);
|
|
683
|
+
console.log(` ${c.cyan}Agent:${c.reset} http://localhost:3335`);
|
|
684
|
+
console.log("");
|
|
685
|
+
console.log(` Pressione ${c.bold}Ctrl+C${c.reset} para parar.\n`);
|
|
684
686
|
|
|
685
687
|
function shutdown() {
|
|
686
688
|
console.log(`\n Parando...\n`);
|
|
@@ -1138,10 +1140,10 @@ async function install() {
|
|
|
1138
1140
|
|
|
1139
1141
|
function cmdLocalKeys() {
|
|
1140
1142
|
if (!isLocalInstalled()) {
|
|
1141
|
-
console.log(`\n ${c.red}✗ Pipely AI nao instalado
|
|
1143
|
+
console.log(`\n ${c.red}✗ Pipely AI nao instalado nesta pasta${c.reset}\n`);
|
|
1142
1144
|
process.exit(1);
|
|
1143
1145
|
}
|
|
1144
|
-
const env = readEnvFile(
|
|
1146
|
+
const env = readEnvFile(getLocalDir());
|
|
1145
1147
|
console.log("");
|
|
1146
1148
|
console.log(` ${c.bold}PIPELY AI — Chaves (Local)${c.reset}\n`);
|
|
1147
1149
|
if (env.OWNER_SETUP_KEY) {
|
|
@@ -1150,7 +1152,7 @@ function cmdLocalKeys() {
|
|
|
1150
1152
|
if (env.JWT_SECRET) {
|
|
1151
1153
|
console.log(` JWT Secret: ${c.yellow}${env.JWT_SECRET.slice(0, 16)}...${c.reset}`);
|
|
1152
1154
|
}
|
|
1153
|
-
console.log(`\n Diretorio: ${c.dim}${
|
|
1155
|
+
console.log(`\n Diretorio: ${c.dim}${getLocalDir()}${c.reset}`);
|
|
1154
1156
|
console.log("");
|
|
1155
1157
|
}
|
|
1156
1158
|
|
|
@@ -1204,7 +1206,7 @@ switch (command) {
|
|
|
1204
1206
|
case "update":
|
|
1205
1207
|
if (local) {
|
|
1206
1208
|
// Delete and re-download bundle
|
|
1207
|
-
try { rmSync(
|
|
1209
|
+
try { rmSync(getBundleDir(), { recursive: true }); } catch {}
|
|
1208
1210
|
console.log(`\n ${c.dim}Reinstalando...${c.reset}\n`);
|
|
1209
1211
|
installLocal().catch((err) => {
|
|
1210
1212
|
console.error(`\n ${c.red}Erro: ${err.message}${c.reset}\n`);
|