Skip to content

Commit 1c4031a

Browse files
committed
Enhance KBNet setup and functionality
- Updated README.md to include links for online trial, self-host pack, demo video, and project article. - Modified extractItem function in mark.tsx to return itemConfig.text for IDs shorter than 5 characters. - Changed summary generation logic in summary-content.tsx to use completedAt instead of requestedAt. - Adjusted auth.ts to disable signup based on SELF_HOST variable. - Simplified toast notifications in wsHandler.ts. - Removed mindsdb-js-sdk dependency from package.json. - Refactored MindsDB query handling in server API to use local runMindsDBQuery function. - Updated generateMapSummary function to handle query results correctly. - Replaced MindsDB connection logic with fetch-based implementation in minds.ts. - Cleaned up seed scripts and added configuration management for MindsDB. - Enhanced Makefile for clearer setup instructions and added seeding process. - Created comprehensive self-host setup guide in self-host/README.md. - Updated docker-compose.yml to use official Docker images for platform and server. - Added seeding scripts and configuration for MindsDB in self-host/seed directory.
1 parent bfaa901 commit 1c4031a

File tree

29 files changed

+558
-199
lines changed

29 files changed

+558
-199
lines changed

README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,14 @@
99

1010
KBNet is an interactive learning platform that creates dynamic, AI-powered knowledge maps for users to explore topics in an engaging and intuitive way. The project uses MindsDB for AI capabilities and follows a modern web architecture.
1111

12+
## Try KbNet
13+
14+
- **Online Trial**: Experience KbNet at [https://kbnet.diybuilds.tech/](https://kbnet.diybuilds.tech/)
15+
- **Self-Host Pack**: Download the latest self-host pack from our [GitHub releases](https://github.com/PriyanshuPz/kbnet/releases) and read setup instructions in the [`self-host/README.md`](./self-host/README.md) file.
16+
17+
- **Demo Video**: Watch KbNet in action on [YouTube](https://youtu.be/AZJZm--uAKg)
18+
- **Project Article**: Learn about the development and vision behind KbNet in our [detailed article](https://dev.to/priyanshuverma/mindsdb-made-it-easy-i-made-it-hard-building-an-ai-powered-knowledge-map-d0g)
19+
1220
## Core Features
1321

1422
### 1. Knowledge Map Exploration

apps/platform/src/components/map/mark.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,10 @@ function extractItem(content: string) {
5454

5555
if (match) {
5656
const [_, itemConfig] = match;
57+
const id = content.split(":")[1];
58+
if (id.length < 5) {
59+
return itemConfig.text;
60+
}
5761
return `${itemConfig.text}(${itemConfig.url}${content.split(":")[1]})`;
5862
}
5963

apps/platform/src/components/summary/summary-content.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ export function MapSummaryContent({ mapId, initialData }: SummaryContentProps) {
4242
function canGenerateSummary() {
4343
if (!isEnabled || SELF_HOST) return false; // Can't generate if disabled or self-hosted
4444
if (!summaryData) return true; // No summary data means we can generate
45-
const lastGenerated = summaryData.requestedAt;
45+
const lastGenerated = summaryData.completedAt;
4646
if (!lastGenerated) return true; // No previous generation means we can generate
4747
const now = new Date();
4848
const hoursSinceLast =

apps/platform/src/lib/auth.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { customSession, username } from "better-auth/plugins";
55
import { bearer } from "better-auth/plugins";
66
import { anonymous } from "better-auth/plugins";
77
import { getUserById } from "./data";
8+
import { SELF_HOST } from "./utils";
89

910
const restrictedUsernames = [
1011
"admin",
@@ -42,7 +43,6 @@ const restrictedUsernames = [
4243
"adminpanel",
4344
];
4445

45-
const ENABLE_SIGNUP = process.env.ENABLE_SIGNUP === "true";
4646
export const auth = betterAuth({
4747
database: prismaAdapter(prisma, {
4848
provider: "postgresql",
@@ -58,7 +58,7 @@ export const auth = betterAuth({
5858
username: profile.login.replaceAll("-", "_"),
5959
displayName: profile.name || profile.login,
6060
}),
61-
disableSignUp: !ENABLE_SIGNUP,
61+
disableSignUp: SELF_HOST,
6262
},
6363
},
6464
plugins: [

apps/platform/src/lib/wsHandler.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ export async function wsHandler(
6363
state.setState("idle");
6464
state.setError(null);
6565
playFeedback("level_up");
66-
toast.info(message, {
66+
toast(message, {
6767
style: {
6868
maxWidth: "400px",
6969
whiteSpace: "normal",

apps/server/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
"@kbnet/db": "*",
1414
"@kbnet/shared": "*",
1515
"@paralleldrive/cuid2": "^2.2.2",
16-
"mindsdb-js-sdk": "^2.3.2",
1716
"better-auth": "^1.2.9",
1817
"ai": "^4.3.16",
1918
"dotenv": "^16.5.0",

apps/server/src/api/index.ts

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ import { Hono } from "hono";
44
import { generateMapSummary } from "../controllers/summary";
55
import { authClient } from "../lib/auth-client";
66
import { userSettings } from "../controllers/user";
7-
import { runMindsDBQuery } from "@kbnet/shared/mindsdb";
87
import { MindsDBConfig } from "@kbnet/shared";
8+
import { runMindsDBQuery } from "../lib/minds";
99

1010
const router = new Hono<{
1111
Variables: {
@@ -45,7 +45,7 @@ router.post("/maps/trigger/summary", async (c) => {
4545
}
4646

4747
// limit it to one summary generation one time in 24 hours
48-
const lastGenerated = map.latestSummary?.requestedAt;
48+
const lastGenerated = map.latestSummary?.completedAt;
4949
if (lastGenerated) {
5050
const now = new Date();
5151
const hoursSinceLast =
@@ -127,6 +127,22 @@ router.post("/assistant", async (c) => {
127127
return c.json({ error: "Invalid messages format" }, 400);
128128
}
129129

130+
try {
131+
const q = await runMindsDBQuery(`SELECT 1 as ok;`);
132+
if (q[0].ok !== 1) {
133+
return c.json(
134+
{ error: "Sorry, We don't have MindsDB up at the moment." },
135+
403
136+
);
137+
}
138+
} catch (error) {
139+
console.error("MindsDB connection error:", error);
140+
return c.json(
141+
{ error: "Sorry, We don't have MindsDB up at the moment." },
142+
403
143+
);
144+
}
145+
130146
const node = await prisma.node.findUnique({
131147
where: { id: currentNodeId },
132148
include: {
@@ -157,19 +173,14 @@ router.post("/assistant", async (c) => {
157173
${messages.map((msg, index) => `Message ${index + 1} from ${msg.role}: ${msg.content[0].text}`).join("\n")}
158174
`;
159175

160-
// FROM ${MindsDBConfig.MAIN_NODE_GEN_MODEL}
161176
const query = await runMindsDBQuery(`
162-
SELECT answer
163-
FROM gen_main_node_model
164-
WHERE question = '${prompt.replace(/'/g, "''")}';
165-
`);
166-
167-
if (query.type != "table") {
168-
return c.json({ error: "Failed to get response from MindsDB" }, 500);
169-
}
177+
SELECT answer
178+
FROM ${MindsDBConfig.MAIN_NODE_GEN_MODEL}
179+
WHERE question = '${prompt.replace(/'/g, "''")}';
180+
`);
170181

171182
const answer =
172-
query.rows[0]?.answer ||
183+
query[0]?.answer ||
173184
"I'm sorry, I don't have an answer for that at the moment.";
174185

175186
return c.json({ text: answer });

apps/server/src/controllers/summary.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
import { MindsDBConfig } from "@kbnet/shared";
2-
import { connectMindsDB, runMindsDBQuery } from "@kbnet/shared/mindsdb";
32
import { prisma } from "@kbnet/db";
3+
import { runMindsDBQuery } from "../lib/minds";
44

55
export async function generateMapSummary(mapId: string) {
66
try {
7-
await connectMindsDB();
8-
97
const map = await prisma.map.findUnique({
108
where: { id: mapId },
119
include: { latestSummary: true },
@@ -22,11 +20,11 @@ export async function generateMapSummary(mapId: string) {
2220
LIMIT 1;
2321
`);
2422

25-
if (query.rows.length === 0) {
23+
if (query.length === 0) {
2624
throw new Error("No summary generated by MindsDB");
2725
}
2826

29-
const summaryRecord = query.rows[0];
27+
const summaryRecord = query[0];
3028
const summaryText = summaryRecord?.answer;
3129

3230
if (!summaryText) {

apps/server/src/index.ts

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ import { authClient, tokenToSession } from "./lib/auth-client";
77
import { createServer } from "http";
88
import { MessageType, pack } from "@kbnet/shared";
99
import { serve } from "@hono/node-server";
10-
import { connectMindsDB, runMindsDBQuery } from "@kbnet/shared/mindsdb";
1110
import { prisma } from "@kbnet/db";
11+
import { runMindsDBQuery } from "./lib/minds";
1212

1313
config();
1414

@@ -25,15 +25,14 @@ app.get("/", async (c) => {
2525
let isMindsDB = false;
2626
let isDB = false;
2727
try {
28-
const cell = await runMindsDBQuery(`SELECT 1`);
29-
console.log("MindsDB cell result:", cell.type);
30-
if (cell.type == "table") {
28+
const cell = await runMindsDBQuery(`SELECT 1 as ok`);
29+
30+
if (cell[0].ok === 1) {
3131
isMindsDB = true;
3232
} else {
33-
isMindsDB = false;
33+
console.error("MindsDB query did not return expected result.");
3434
}
3535
} catch (error) {
36-
isMindsDB = false;
3736
console.error("Failed to connect to MindsDB");
3837
}
3938

apps/server/src/lib/ai.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ export async function generateMapStartPoint(
4040

4141
const { object } = await generateObject({
4242
model: google("gemini-2.0-flash"),
43-
system: MAIN_NODE_GEN_MODEL_PROMPT(query, kbdata.rows),
43+
system: MAIN_NODE_GEN_MODEL_PROMPT(query, kbdata),
4444
schema: z.object({
4545
mainNode: z.object({
4646
title: z

0 commit comments

Comments
 (0)