gnosys 4.4.1 → 4.4.6
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 +126 -16
- package/dist/cli.js.map +1 -1
- package/dist/lib/setup.d.ts +2 -2
- package/dist/lib/setup.d.ts.map +1 -1
- package/dist/lib/setup.js +30 -48
- package/dist/lib/setup.js.map +1 -1
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -3499,18 +3499,114 @@ const webCmd = program
|
|
|
3499
3499
|
.description("Web Knowledge Base — generate searchable knowledge from websites");
|
|
3500
3500
|
webCmd
|
|
3501
3501
|
.command("init")
|
|
3502
|
-
.description("
|
|
3502
|
+
.description("Interactive setup for web knowledge base")
|
|
3503
3503
|
.option("--source <type>", "Source type: sitemap, directory, urls", "sitemap")
|
|
3504
3504
|
.option("--output <dir>", "Output directory for knowledge files", "./knowledge")
|
|
3505
3505
|
.option("--no-config", "Skip gnosys.json modification")
|
|
3506
|
+
.option("--non-interactive", "Skip prompts, use defaults")
|
|
3506
3507
|
.option("--json", "Output as JSON")
|
|
3507
3508
|
.action(async (opts) => {
|
|
3508
3509
|
try {
|
|
3509
3510
|
const { mkdirSync } = await import("fs");
|
|
3510
|
-
const { loadConfig, updateConfig } = await import("./lib/config.js");
|
|
3511
|
+
const { loadConfig, updateConfig, resolveTaskModel } = await import("./lib/config.js");
|
|
3512
|
+
const { createInterface } = await import("readline/promises");
|
|
3511
3513
|
const storePath = await getWebStorePath();
|
|
3514
|
+
const DIM = "\x1b[2m";
|
|
3515
|
+
const BOLD = "\x1b[1m";
|
|
3516
|
+
const CYAN = "\x1b[36m";
|
|
3517
|
+
const GREEN = "\x1b[32m";
|
|
3518
|
+
const RESET = "\x1b[0m";
|
|
3519
|
+
const CHECK = `${GREEN}\u2713${RESET}`;
|
|
3520
|
+
let sitemapUrl = "";
|
|
3521
|
+
let outputDir = opts.output;
|
|
3522
|
+
let llmEnrich = true;
|
|
3523
|
+
let envVarName = "ANTHROPIC_API_KEY";
|
|
3524
|
+
// Detect current agent config for provider info
|
|
3525
|
+
let agentProvider = "anthropic";
|
|
3526
|
+
let agentModel = "";
|
|
3527
|
+
try {
|
|
3528
|
+
const cfg = await loadConfig(storePath);
|
|
3529
|
+
agentProvider = cfg.llm.defaultProvider;
|
|
3530
|
+
const taskModel = resolveTaskModel(cfg, "structuring");
|
|
3531
|
+
agentModel = taskModel.model;
|
|
3532
|
+
}
|
|
3533
|
+
catch { /* no config yet */ }
|
|
3534
|
+
// Map provider to env var name
|
|
3535
|
+
const providerEnvVars = {
|
|
3536
|
+
anthropic: "ANTHROPIC_API_KEY",
|
|
3537
|
+
openai: "OPENAI_API_KEY",
|
|
3538
|
+
groq: "GROQ_API_KEY",
|
|
3539
|
+
xai: "XAI_API_KEY",
|
|
3540
|
+
mistral: "MISTRAL_API_KEY",
|
|
3541
|
+
ollama: "",
|
|
3542
|
+
lmstudio: "",
|
|
3543
|
+
custom: "GNOSYS_LLM_API_KEY",
|
|
3544
|
+
};
|
|
3545
|
+
if (!opts.nonInteractive && !opts.json && process.stdout.isTTY) {
|
|
3546
|
+
const rl = createInterface({ input: process.stdin, output: process.stdout });
|
|
3547
|
+
try {
|
|
3548
|
+
console.log();
|
|
3549
|
+
console.log(`${BOLD}Web Knowledge Base Setup${RESET}`);
|
|
3550
|
+
console.log();
|
|
3551
|
+
console.log(`${DIM}This sets up a /knowledge/ directory in your project.`);
|
|
3552
|
+
console.log(`Gnosys crawls your site, converts pages to markdown, and`);
|
|
3553
|
+
console.log(`builds a search index. Everything deploys with your app.`);
|
|
3554
|
+
console.log();
|
|
3555
|
+
console.log(`No API keys are stored in your project. The LLM key is`);
|
|
3556
|
+
console.log(`read from an environment variable at build time.${RESET}`);
|
|
3557
|
+
console.log();
|
|
3558
|
+
// Step 1: Sitemap URL
|
|
3559
|
+
console.log(`${BOLD}Step 1/3${RESET} ${DIM}\u2014${RESET} Content source`);
|
|
3560
|
+
console.log();
|
|
3561
|
+
console.log(`${DIM} \u2022 Deployed site: https://yoursite.com/sitemap.xml`);
|
|
3562
|
+
console.log(` \u2022 Local dev: http://localhost:3000/sitemap.xml`);
|
|
3563
|
+
console.log(` \u2022 Not ready yet: press Enter (add later in gnosys.json)${RESET}`);
|
|
3564
|
+
console.log();
|
|
3565
|
+
const urlAnswer = await rl.question("Sitemap URL: ");
|
|
3566
|
+
sitemapUrl = urlAnswer.trim();
|
|
3567
|
+
console.log();
|
|
3568
|
+
// Step 2: LLM enrichment
|
|
3569
|
+
console.log(`${BOLD}Step 2/3${RESET} ${DIM}\u2014${RESET} LLM enrichment`);
|
|
3570
|
+
console.log();
|
|
3571
|
+
console.log(`${DIM}LLM enrichment generates better tags, keyword clouds, and`);
|
|
3572
|
+
console.log(`frontmatter for each page. Without it, Gnosys uses TF-IDF`);
|
|
3573
|
+
console.log(`keyword extraction (free, no API key needed, decent quality).${RESET}`);
|
|
3574
|
+
console.log();
|
|
3575
|
+
if (agentModel && providerEnvVars[agentProvider]) {
|
|
3576
|
+
console.log(`${DIM}Your agent setup uses ${agentProvider}/${agentModel} for structuring.${RESET}`);
|
|
3577
|
+
}
|
|
3578
|
+
console.log();
|
|
3579
|
+
const enrichAnswer = await rl.question("Enable LLM enrichment? [Y/n] ");
|
|
3580
|
+
llmEnrich = !enrichAnswer.trim().toLowerCase().startsWith("n");
|
|
3581
|
+
console.log();
|
|
3582
|
+
// Step 3: CI/CD env var
|
|
3583
|
+
if (llmEnrich) {
|
|
3584
|
+
console.log(`${BOLD}Step 3/3${RESET} ${DIM}\u2014${RESET} CI/CD environment variable`);
|
|
3585
|
+
console.log();
|
|
3586
|
+
console.log(`${DIM}In CI/CD (GitHub Actions, Vercel, Netlify), the LLM API key`);
|
|
3587
|
+
console.log(`is read from an environment variable. No keys are stored in`);
|
|
3588
|
+
console.log(`your project or committed to git.${RESET}`);
|
|
3589
|
+
console.log();
|
|
3590
|
+
const defaultEnv = providerEnvVars[agentProvider] || "ANTHROPIC_API_KEY";
|
|
3591
|
+
const envAnswer = await rl.question(`Env var name for API key (${defaultEnv}): `);
|
|
3592
|
+
envVarName = envAnswer.trim() || defaultEnv;
|
|
3593
|
+
}
|
|
3594
|
+
else {
|
|
3595
|
+
console.log(`${DIM}Step 3/3 \u2014 Skipped (no LLM = no API key needed)${RESET}`);
|
|
3596
|
+
envVarName = "";
|
|
3597
|
+
}
|
|
3598
|
+
console.log();
|
|
3599
|
+
// Output dir
|
|
3600
|
+
const dirAnswer = await rl.question(`Output directory (${opts.output}): `);
|
|
3601
|
+
outputDir = dirAnswer.trim() || opts.output;
|
|
3602
|
+
rl.close();
|
|
3603
|
+
}
|
|
3604
|
+
catch {
|
|
3605
|
+
rl.close();
|
|
3606
|
+
}
|
|
3607
|
+
}
|
|
3512
3608
|
// Create output directory
|
|
3513
|
-
mkdirSync(
|
|
3609
|
+
mkdirSync(outputDir, { recursive: true });
|
|
3514
3610
|
// Update gnosys.json with web config
|
|
3515
3611
|
if (opts.config) {
|
|
3516
3612
|
try {
|
|
@@ -3519,37 +3615,51 @@ webCmd
|
|
|
3519
3615
|
await updateConfig(storePath, {
|
|
3520
3616
|
web: {
|
|
3521
3617
|
source: opts.source,
|
|
3522
|
-
|
|
3618
|
+
...(sitemapUrl ? { sitemapUrl } : {}),
|
|
3619
|
+
outputDir,
|
|
3523
3620
|
exclude: ["/api", "/admin", "/_next"],
|
|
3524
3621
|
categories: {
|
|
3525
3622
|
"/blog/*": "blog",
|
|
3526
3623
|
"/services/*": "services",
|
|
3527
3624
|
"/products/*": "products",
|
|
3528
3625
|
"/about*": "company",
|
|
3529
|
-
"/careers*": "careers",
|
|
3530
|
-
"/industries/*": "industries",
|
|
3531
3626
|
},
|
|
3532
|
-
llmEnrich
|
|
3627
|
+
llmEnrich,
|
|
3533
3628
|
prune: false,
|
|
3534
3629
|
},
|
|
3535
3630
|
});
|
|
3536
3631
|
}
|
|
3537
3632
|
}
|
|
3538
3633
|
catch {
|
|
3539
|
-
// No gnosys.json yet —
|
|
3634
|
+
// No gnosys.json yet — run gnosys init first
|
|
3540
3635
|
}
|
|
3541
3636
|
}
|
|
3542
3637
|
if (opts.json) {
|
|
3543
|
-
console.log(JSON.stringify({ ok: true, outputDir
|
|
3638
|
+
console.log(JSON.stringify({ ok: true, outputDir, source: opts.source, sitemapUrl: sitemapUrl || null, llmEnrich, envVarName: envVarName || null }));
|
|
3544
3639
|
}
|
|
3545
3640
|
else {
|
|
3546
|
-
console.log(
|
|
3547
|
-
console.log(
|
|
3548
|
-
|
|
3549
|
-
|
|
3550
|
-
|
|
3551
|
-
console.log(
|
|
3552
|
-
|
|
3641
|
+
console.log(`${CHECK} Created ${outputDir}/`);
|
|
3642
|
+
console.log(`${CHECK} Updated gnosys.json with web config`);
|
|
3643
|
+
if (sitemapUrl) {
|
|
3644
|
+
console.log(`${CHECK} Sitemap: ${sitemapUrl}`);
|
|
3645
|
+
}
|
|
3646
|
+
console.log(`${CHECK} LLM enrichment: ${llmEnrich ? "enabled" : "disabled (TF-IDF mode)"}`);
|
|
3647
|
+
if (envVarName) {
|
|
3648
|
+
console.log(`${CHECK} CI/CD env var: ${envVarName}`);
|
|
3649
|
+
}
|
|
3650
|
+
console.log();
|
|
3651
|
+
console.log(`${BOLD}Next steps:${RESET}`);
|
|
3652
|
+
if (!sitemapUrl) {
|
|
3653
|
+
console.log(` 1. Add your sitemap URL to gnosys.json → web.sitemapUrl`);
|
|
3654
|
+
}
|
|
3655
|
+
if (envVarName) {
|
|
3656
|
+
console.log(` ${sitemapUrl ? "1" : "2"}. Set ${CYAN}${envVarName}${RESET} in your hosting provider (Vercel, Netlify, GitHub Actions)`);
|
|
3657
|
+
console.log(` ${DIM}Never commit API keys to your repo${RESET}`);
|
|
3658
|
+
}
|
|
3659
|
+
console.log(` ${!sitemapUrl && envVarName ? "3" : envVarName || !sitemapUrl ? "2" : "1"}. Run: ${CYAN}gnosys web build${RESET}`);
|
|
3660
|
+
console.log(` ${!sitemapUrl && envVarName ? "4" : envVarName || !sitemapUrl ? "3" : "2"}. Add to package.json: ${CYAN}"postbuild": "npx gnosys web build"${RESET}`);
|
|
3661
|
+
console.log();
|
|
3662
|
+
console.log(`${DIM}Every deploy will re-crawl and rebuild the search index automatically.${RESET}`);
|
|
3553
3663
|
}
|
|
3554
3664
|
}
|
|
3555
3665
|
catch (err) {
|